blob: 8b33593dad2c8d086e454180e4d21b4834486d2a [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;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080066import android.telephony.Annotation.ThermalMitigationResult;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran4deb8872020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080078import android.telephony.DataThrottlingRequest;
Hui Wang641e81c2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Daniel Bright59e67312020-11-13 11:49:37 -080090import android.telephony.RadioInterfaceCapabilities;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070091import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080092import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080093import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080094import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080095import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070096import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070097import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080098import android.telephony.TelephonyScanManager;
Jack Nudelmanb0b87642020-11-12 15:04:39 -080099import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800100import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000101import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700102import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700103import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800104import android.telephony.data.ApnSetting;
105import android.telephony.emergency.EmergencyNumber;
Hui Wang641e81c2020-10-12 12:14:23 -0700106import android.telephony.gba.GbaAuthRequest;
107import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700108import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800109import android.telephony.ims.ProvisioningManager;
Hui Wang761a6682020-10-31 05:12:53 +0000110import android.telephony.ims.RcsClientConfiguration;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700111import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800113import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700114import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700116import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang761a6682020-10-31 05:12:53 +0000117import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700118import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800119import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800120import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800122import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700123import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800124import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700125import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800127import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800128
Andrew Lee312e8172014-10-23 17:01:36 -0700129import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800130import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700133import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700134import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800135import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700136import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700137import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800138import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang641e81c2020-10-12 12:14:23 -0700140import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800141import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800142import com.android.internal.telephony.IBooleanConsumer;
Hall Liu27d24262020-09-18 19:04:59 -0700143import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700144import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800145import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700146import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800147import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700149import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700150import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700152import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800153import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700154import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700155import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700156import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700157import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700158import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700159import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700160import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700161import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800162import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800163import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800164import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700165import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800166import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700167import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800168import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700169import com.android.internal.telephony.imsphone.ImsPhone;
170import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800171import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700172import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800174import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800176import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700177import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800180import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000181import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800182import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700183import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liu27d24262020-09-18 19:04:59 -0700184import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800185import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700186import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700187import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800188import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700189import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700190import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800191import com.android.services.telephony.TelecomAccountRegistry;
192import com.android.services.telephony.TelephonyConnectionService;
Peter Wang44b186e2020-01-13 23:33:09 -0800193import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800194
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700195import java.io.FileDescriptor;
196import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700197import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800198import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800199import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800200import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800201import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100202import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700204import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800205import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800206import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800207import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
209/**
210 * Implementation of the ITelephony interface.
211 */
Santos Cordon117fee72014-05-16 17:56:12 -0700212public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213 private static final String LOG_TAG = "PhoneInterfaceManager";
214 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
215 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800216 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217
218 // Message codes used with mMainThreadHandler
219 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700220 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
221 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700222 private static final int CMD_OPEN_CHANNEL = 9;
223 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
224 private static final int CMD_CLOSE_CHANNEL = 11;
225 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800226 private static final int CMD_NV_READ_ITEM = 13;
227 private static final int EVENT_NV_READ_ITEM_DONE = 14;
228 private static final int CMD_NV_WRITE_ITEM = 15;
229 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
230 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
231 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700232 private static final int CMD_RESET_MODEM_CONFIG = 19;
233 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800234 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
235 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
236 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
237 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800238 private static final int CMD_SEND_ENVELOPE = 25;
239 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000240 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
241 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700242 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
243 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
244 private static final int CMD_EXCHANGE_SIM_IO = 31;
245 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800246 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
247 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700248 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
249 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700250 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
251 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700252 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
253 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
254 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
255 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700256 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
257 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
258 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
259 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700260 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800261 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
262 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000263 private static final int CMD_SWITCH_SLOTS = 50;
264 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700265 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
266 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
267 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
268 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
269 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
270 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
271 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
272 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700273 private static final int CMD_GET_ALL_CELL_INFO = 60;
274 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
275 private static final int CMD_GET_CELL_LOCATION = 62;
276 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700277 private static final int CMD_MODEM_REBOOT = 64;
278 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700279 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
280 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800281 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
282 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700283 private static final int CMD_GET_MODEM_STATUS = 70;
284 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700285 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
286 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700287 private static final int CMD_ERASE_MODEM_CONFIG = 74;
288 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800289 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
290 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
291 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
292 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800293 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
294 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800295 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800296 private static final int CMD_GET_CALL_FORWARDING = 83;
297 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
298 private static final int CMD_SET_CALL_FORWARDING = 85;
299 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
300 private static final int CMD_GET_CALL_WAITING = 87;
301 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
302 private static final int CMD_SET_CALL_WAITING = 89;
303 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindran37444802020-08-11 10:40:43 -0700304 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
305 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
306 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
307 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chinbaab1432020-10-28 13:46:24 -0700308 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
309 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chin679c08a2020-11-18 13:39:35 -0800310 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
311 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800312 private static final int CMD_SET_DATA_THROTTLING = 99;
313 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liu109698e2020-11-24 14:50:34 -0800314 private static final int CMD_SET_SIM_POWER = 101;
315 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700316
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800317 // Parameters of select command.
318 private static final int SELECT_COMMAND = 0xA4;
319 private static final int SELECT_P1 = 0x04;
320 private static final int SELECT_P2 = 0;
321 private static final int SELECT_P3 = 0x10;
322
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700323 /** The singleton instance. */
324 private static PhoneInterfaceManager sInstance;
325
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800327 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800328 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700329 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800330 private AppOpsManager mAppOps;
331 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800332 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800333 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700334 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700335
Peter Wangdafb9ac2020-01-15 14:13:38 -0800336 /** User Activity */
337 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800338 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
339
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700340 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
341
Derek Tan97ebb422014-09-05 16:55:38 -0700342 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
343 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800344 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800345 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700346
Michelecea4cf22018-12-21 15:00:11 -0800347 // String to store multi SIM allowed
348 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
349
Derek Tan740e1672017-06-27 14:56:27 -0700350 // The AID of ISD-R.
351 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
352
yinxub1bed742017-04-17 11:45:04 -0700353 private NetworkScanRequestTracker mNetworkScanRequestTracker;
354
David Kelly5e06a7f2018-03-12 14:10:59 +0000355 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
356 private static final int MANUFACTURER_CODE_LENGTH = 8;
357
Jack Nudelmanb0b87642020-11-12 15:04:39 -0800358 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
359
Derek Tan89e89d42014-07-08 17:00:10 -0700360 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700361 * Experiment flag to enable erase modem config on reset network, default value is false
362 */
363 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
364 "reset_network_erase_modem_config_enabled";
365
366 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700367 * A request object to use for transmitting data to an ICC.
368 */
369 private static final class IccAPDUArgument {
370 public int channel, cla, command, p1, p2, p3;
371 public String data;
372
373 public IccAPDUArgument(int channel, int cla, int command,
374 int p1, int p2, int p3, String data) {
375 this.channel = channel;
376 this.cla = cla;
377 this.command = command;
378 this.p1 = p1;
379 this.p2 = p2;
380 this.p3 = p3;
381 this.data = data;
382 }
383 }
384
385 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700386 * A request object to use for transmitting data to an ICC.
387 */
388 private static final class ManualNetworkSelectionArgument {
389 public OperatorInfo operatorInfo;
390 public boolean persistSelection;
391
392 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
393 this.operatorInfo = operatorInfo;
394 this.persistSelection = persistSelection;
395 }
396 }
397
398 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700399 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
400 * request after sending. The main thread will notify the request when it is complete.
401 */
402 private static final class MainThreadRequest {
403 /** The argument to use for the request */
404 public Object argument;
405 /** The result of the request that is run on the main thread */
406 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800407 // The subscriber id that this request applies to. Defaults to
408 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
409 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410
Nathan Harold92bed182018-10-12 18:16:49 -0700411 // In cases where subId is unavailable, the caller needs to specify the phone.
412 public Phone phone;
413
vagdeviaf9a5b92018-08-15 16:01:53 -0700414 public WorkSource workSource;
415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 public MainThreadRequest(Object argument) {
417 this.argument = argument;
418 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800419
Nathan Harold92bed182018-10-12 18:16:49 -0700420 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
421 this.argument = argument;
422 if (phone != null) {
423 this.phone = phone;
424 }
425 this.workSource = workSource;
426 }
427
vagdeviaf9a5b92018-08-15 16:01:53 -0700428 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800429 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800430 if (subId != null) {
431 this.subId = subId;
432 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700433 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700435 }
436
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800437 private static final class IncomingThirdPartyCallArgs {
438 public final ComponentName component;
439 public final String callId;
440 public final String callerDisplayName;
441
442 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
443 String callerDisplayName) {
444 this.component = component;
445 this.callId = callId;
446 this.callerDisplayName = callerDisplayName;
447 }
448 }
449
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700450 /**
451 * A handler that processes messages on the main thread in the phone process. Since many
452 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
453 * inbound binder threads to the main thread in the phone process. The Binder thread
454 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
455 * on, which will be notified when the operation completes and will contain the result of the
456 * request.
457 *
458 * <p>If a MainThreadRequest object is provided in the msg.obj field,
459 * note that request.result must be set to something non-null for the calling thread to
460 * unblock.
461 */
462 private final class MainThreadHandler extends Handler {
463 @Override
464 public void handleMessage(Message msg) {
465 MainThreadRequest request;
466 Message onCompleted;
467 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800468 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700469 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800470 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471
472 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700473 case CMD_HANDLE_USSD_REQUEST: {
474 request = (MainThreadRequest) msg.obj;
475 final Phone phone = getPhoneFromRequest(request);
476 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
477 String ussdRequest = ussdObject.first;
478 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700479
Pengquan Menga1bb6272018-09-06 09:59:22 -0700480 if (!isUssdApiAllowed(request.subId)) {
481 // Carrier does not support use of this API, return failure.
482 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
483 UssdResponse response = new UssdResponse(ussdRequest, null);
484 Bundle returnData = new Bundle();
485 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
486 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700487
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 request.result = true;
489 notifyRequester(request);
490 return;
491 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700492
Pengquan Menga1bb6272018-09-06 09:59:22 -0700493 try {
494 request.result = phone != null
495 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
496 } catch (CallStateException cse) {
497 request.result = false;
498 }
499 // Wake up the requesting thread
500 notifyRequester(request);
501 break;
pkanwar32d516d2016-10-14 19:37:38 -0700502 }
503
Yorke Lee716f67e2015-06-17 15:39:16 -0700504 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700505 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700506 final Phone phone = getPhoneFromRequest(request);
507 request.result = phone != null ?
508 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
509 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700510 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700511 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700512 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700513 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700514
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700515 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700517 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800518 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700519 if (uiccCard == null) {
520 loge("iccTransmitApduLogicalChannel: No UICC");
521 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700523 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
525 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700526 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 iccArgument.channel, iccArgument.cla, iccArgument.command,
528 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700529 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700531 break;
532
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700533 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700534 ar = (AsyncResult) msg.obj;
535 request = (MainThreadRequest) ar.userObj;
536 if (ar.exception == null && ar.result != null) {
537 request.result = ar.result;
538 } else {
539 request.result = new IccIoResult(0x6F, 0, (byte[])null);
540 if (ar.result == null) {
541 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800542 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700543 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800544 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 } else {
546 loge("iccTransmitApduLogicalChannel: Unknown exception");
547 }
548 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700549 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700550 break;
551
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
553 request = (MainThreadRequest) msg.obj;
554 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800555 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 if (uiccCard == null) {
557 loge("iccTransmitApduBasicChannel: No UICC");
558 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 } else {
561 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
562 request);
563 uiccCard.iccTransmitApduBasicChannel(
564 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
565 iccArgument.p3, iccArgument.data, onCompleted);
566 }
567 break;
568
569 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
570 ar = (AsyncResult) msg.obj;
571 request = (MainThreadRequest) ar.userObj;
572 if (ar.exception == null && ar.result != null) {
573 request.result = ar.result;
574 } else {
575 request.result = new IccIoResult(0x6F, 0, (byte[])null);
576 if (ar.result == null) {
577 loge("iccTransmitApduBasicChannel: Empty response");
578 } else if (ar.exception instanceof CommandException) {
579 loge("iccTransmitApduBasicChannel: CommandException: " +
580 ar.exception);
581 } else {
582 loge("iccTransmitApduBasicChannel: Unknown exception");
583 }
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
588 case CMD_EXCHANGE_SIM_IO:
589 request = (MainThreadRequest) msg.obj;
590 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800591 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700592 if (uiccCard == null) {
593 loge("iccExchangeSimIO: No UICC");
594 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 } else {
597 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
598 request);
599 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
600 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
601 iccArgument.data, onCompleted);
602 }
603 break;
604
605 case EVENT_EXCHANGE_SIM_IO_DONE:
606 ar = (AsyncResult) msg.obj;
607 request = (MainThreadRequest) ar.userObj;
608 if (ar.exception == null && ar.result != null) {
609 request.result = ar.result;
610 } else {
611 request.result = new IccIoResult(0x6f, 0, (byte[])null);
612 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700613 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700614 break;
615
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 case CMD_SEND_ENVELOPE:
617 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800618 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 if (uiccCard == null) {
620 loge("sendEnvelopeWithStatus: No UICC");
621 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
624 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
625 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
626 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 break;
628
629 case EVENT_SEND_ENVELOPE_DONE:
630 ar = (AsyncResult) msg.obj;
631 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700632 if (ar.exception == null && ar.result != null) {
633 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800634 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700635 request.result = new IccIoResult(0x6F, 0, (byte[])null);
636 if (ar.result == null) {
637 loge("sendEnvelopeWithStatus: Empty response");
638 } else if (ar.exception instanceof CommandException) {
639 loge("sendEnvelopeWithStatus: CommandException: " +
640 ar.exception);
641 } else {
642 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
643 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700645 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800646 break;
647
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 case CMD_OPEN_CHANNEL:
649 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800650 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800651 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700652 if (uiccCard == null) {
653 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800654 request.result = new IccOpenLogicalChannelResponse(-1,
655 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700657 } else {
658 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800659 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
660 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700661 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700662 break;
663
664 case EVENT_OPEN_CHANNEL_DONE:
665 ar = (AsyncResult) msg.obj;
666 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700667 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700668 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700669 int[] result = (int[]) ar.result;
670 int channelId = result[0];
671 byte[] selectResponse = null;
672 if (result.length > 1) {
673 selectResponse = new byte[result.length - 1];
674 for (int i = 1; i < result.length; ++i) {
675 selectResponse[i - 1] = (byte) result[i];
676 }
677 }
678 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700679 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700681 if (ar.result == null) {
682 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700684 if (ar.exception != null) {
685 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
686 }
687
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700688 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700689 if (ar.exception instanceof CommandException) {
690 CommandException.Error error =
691 ((CommandException) (ar.exception)).getCommandError();
692 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700693 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700694 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700695 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700696 }
697 }
698 openChannelResp = new IccOpenLogicalChannelResponse(
699 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700701 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700702 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700703 break;
704
705 case CMD_CLOSE_CHANNEL:
706 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800707 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700708 if (uiccCard == null) {
709 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900710 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700712 } else {
713 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
714 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
715 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
718 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800719 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
720 break;
721
722 case CMD_NV_READ_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800725 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
726 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800727 break;
728
729 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700730 ar = (AsyncResult) msg.obj;
731 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800732 if (ar.exception == null && ar.result != null) {
733 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700734 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800735 request.result = "";
736 if (ar.result == null) {
737 loge("nvReadItem: Empty response");
738 } else if (ar.exception instanceof CommandException) {
739 loge("nvReadItem: CommandException: " +
740 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800742 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700743 }
744 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700745 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700746 break;
747
Jake Hambye994d462014-02-03 13:10:13 -0800748 case CMD_NV_WRITE_ITEM:
749 request = (MainThreadRequest) msg.obj;
750 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
751 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800752 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700753 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800754 break;
755
756 case EVENT_NV_WRITE_ITEM_DONE:
757 handleNullReturnEvent(msg, "nvWriteItem");
758 break;
759
760 case CMD_NV_WRITE_CDMA_PRL:
761 request = (MainThreadRequest) msg.obj;
762 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800764 break;
765
766 case EVENT_NV_WRITE_CDMA_PRL_DONE:
767 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
768 break;
769
chen xu6dac5ab2018-10-26 17:39:23 -0700770 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800771 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700772 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
chen xu6dac5ab2018-10-26 17:39:23 -0700776 case EVENT_RESET_MODEM_CONFIG_DONE:
777 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800778 break;
779
Sooraj Sasindran37444802020-08-11 10:40:43 -0700780 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
783 request);
784 Phone phone = getPhoneFromRequest(request);
785 if (phone != null) {
786 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
787 } else {
788 loge("isNRDualConnectivityEnabled: No phone object");
789 request.result = false;
790 notifyRequester(request);
791 }
792 break;
793 }
794
795 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
796 ar = (AsyncResult) msg.obj;
797 request = (MainThreadRequest) ar.userObj;
798 if (ar.exception == null && ar.result != null) {
799 request.result = ar.result;
800 } else {
801 // request.result must be set to something non-null
802 // for the calling thread to unblock
803 if (request.result != null) {
804 request.result = ar.result;
805 } else {
806 request.result = false;
807 }
808 if (ar.result == null) {
809 loge("isNRDualConnectivityEnabled: Empty response");
810 } else if (ar.exception instanceof CommandException) {
811 loge("isNRDualConnectivityEnabled: CommandException: "
812 + ar.exception);
813 } else {
814 loge("isNRDualConnectivityEnabled: Unknown exception");
815 }
816 }
817 notifyRequester(request);
818 break;
819
820 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
823 Phone phone = getPhoneFromRequest(request);
824 if (phone != null) {
825 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
826 request.workSource);
827 } else {
828 loge("enableNrDualConnectivity: No phone object");
829 request.result =
830 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
831 notifyRequester(request);
832 }
833 break;
834 }
835
836 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
837 ar = (AsyncResult) msg.obj;
838 request = (MainThreadRequest) ar.userObj;
839 if (ar.exception == null) {
840 request.result =
841 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
842 } else {
843 request.result =
844 TelephonyManager
845 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
846 if (ar.exception instanceof CommandException) {
847 CommandException.Error error =
848 ((CommandException) (ar.exception)).getCommandError();
849 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
850 request.result =
851 TelephonyManager
852 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
853 }
854 loge("enableNrDualConnectivity" + ": CommandException: "
855 + ar.exception);
856 } else {
857 loge("enableNrDualConnectivity" + ": Unknown exception");
858 }
859 }
860 notifyRequester(request);
861 break;
862 }
863
Jake Hamby7c27be32014-03-03 13:25:59 -0800864 case CMD_GET_PREFERRED_NETWORK_TYPE:
865 request = (MainThreadRequest) msg.obj;
866 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700867 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800868 break;
869
870 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
871 ar = (AsyncResult) msg.obj;
872 request = (MainThreadRequest) ar.userObj;
873 if (ar.exception == null && ar.result != null) {
874 request.result = ar.result; // Integer
875 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530876 // request.result must be set to something non-null
877 // for the calling thread to unblock
878 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 if (ar.result == null) {
880 loge("getPreferredNetworkType: Empty response");
881 } else if (ar.exception instanceof CommandException) {
882 loge("getPreferredNetworkType: CommandException: " +
883 ar.exception);
884 } else {
885 loge("getPreferredNetworkType: Unknown exception");
886 }
887 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700888 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800889 break;
890
891 case CMD_SET_PREFERRED_NETWORK_TYPE:
892 request = (MainThreadRequest) msg.obj;
893 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
894 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700895 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 break;
897
898 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
899 handleNullReturnEvent(msg, "setPreferredNetworkType");
900 break;
901
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000902 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
903 request = (MainThreadRequest)msg.obj;
904 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800905 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000906 break;
907
908 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
909 ar = (AsyncResult)msg.obj;
910 request = (MainThreadRequest)ar.userObj;
911 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700912 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 break;
914
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800915 case CMD_SET_VOICEMAIL_NUMBER:
916 request = (MainThreadRequest) msg.obj;
917 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
918 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800919 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
920 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800921 break;
922
923 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
924 handleNullReturnEvent(msg, "setVoicemailNumber");
925 break;
926
Stuart Scott54788802015-03-30 13:18:01 -0700927 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
928 request = (MainThreadRequest) msg.obj;
929 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
930 request);
931 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
932 break;
933
934 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
935 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
936 break;
937
Shishir Agrawal302c8692015-06-19 13:49:39 -0700938 case CMD_PERFORM_NETWORK_SCAN:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
941 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
942 break;
943
Hall Liu27d24262020-09-18 19:04:59 -0700944 case CMD_GET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -0800945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -0700947 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
948 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
949 request.argument;
950 int callForwardingReason = args.first;
951 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -0800952 break;
Hall Liu27d24262020-09-18 19:04:59 -0700953 }
954 case EVENT_GET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -0800955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -0700957 TelephonyManager.CallForwardingInfoCallback callback =
958 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
959 request.argument).second;
Shuo Qian4a594052020-01-23 11:59:30 -0800960 if (ar.exception == null && ar.result != null) {
Hall Liu27d24262020-09-18 19:04:59 -0700961 CallForwardingInfo callForwardingInfo = null;
Shuo Qian4a594052020-01-23 11:59:30 -0800962 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
963 for (CallForwardInfo callForwardInfo : callForwardInfos) {
964 // Service Class is a bit mask per 3gpp 27.007. Search for
965 // any service for voice call.
966 if ((callForwardInfo.serviceClass
967 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liu27d24262020-09-18 19:04:59 -0700968 callForwardingInfo = new CallForwardingInfo(true,
969 callForwardInfo.reason,
970 callForwardInfo.number,
971 callForwardInfo.timeSeconds);
Shuo Qian4a594052020-01-23 11:59:30 -0800972 break;
973 }
974 }
975 // Didn't find a call forward info for voice call.
976 if (callForwardingInfo == null) {
Hall Liu27d24262020-09-18 19:04:59 -0700977 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
978 0 /* reason */, null /* number */, 0 /* timeout */);
Shuo Qian4a594052020-01-23 11:59:30 -0800979 }
Hall Liu27d24262020-09-18 19:04:59 -0700980 callback.onCallForwardingInfoAvailable(callForwardingInfo);
Shuo Qian4a594052020-01-23 11:59:30 -0800981 } else {
982 if (ar.result == null) {
983 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
984 }
985 if (ar.exception != null) {
986 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
987 }
Hall Liu940c4ca2020-09-29 17:10:18 -0700988 int errorCode = TelephonyManager
989 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
Shuo Qian4a594052020-01-23 11:59:30 -0800990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700994 errorCode = TelephonyManager
995 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
Shuo Qian4a594052020-01-23 11:59:30 -0800996 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -0700997 errorCode = TelephonyManager
998 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
Shuo Qian4a594052020-01-23 11:59:30 -0800999 }
1000 }
Hall Liu27d24262020-09-18 19:04:59 -07001001 callback.onError(errorCode);
Shuo Qian4a594052020-01-23 11:59:30 -08001002 }
Shuo Qian4a594052020-01-23 11:59:30 -08001003 break;
Hall Liu27d24262020-09-18 19:04:59 -07001004 }
Shuo Qian4a594052020-01-23 11:59:30 -08001005
Hall Liu27d24262020-09-18 19:04:59 -07001006 case CMD_SET_CALL_FORWARDING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001009 request = (MainThreadRequest) msg.obj;
Shuo Qian4a594052020-01-23 11:59:30 -08001010 CallForwardingInfo callForwardingInfoToSet =
Hall Liu27d24262020-09-18 19:04:59 -07001011 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1012 request.argument).first;
1013 request.phone.setCallForwardingOption(
1014 callForwardingInfoToSet.isEnabled()
1015 ? CommandsInterface.CF_ACTION_ENABLE
1016 : CommandsInterface.CF_ACTION_DISABLE,
Shuo Qian4a594052020-01-23 11:59:30 -08001017 callForwardingInfoToSet.getReason(),
1018 callForwardingInfoToSet.getNumber(),
1019 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1020 break;
Hall Liu27d24262020-09-18 19:04:59 -07001021 }
Shuo Qian4a594052020-01-23 11:59:30 -08001022
Hall Liu27d24262020-09-18 19:04:59 -07001023 case EVENT_SET_CALL_FORWARDING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001026 Consumer<Integer> callback =
1027 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1028 request.argument).second;
1029 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001030 loge("setCallForwarding exception: " + ar.exception);
Hall Liu940c4ca2020-09-29 17:10:18 -07001031 int errorCode = TelephonyManager.CallForwardingInfoCallback
1032 .RESULT_ERROR_UNKNOWN;
Hall Liu27d24262020-09-18 19:04:59 -07001033 if (ar.exception instanceof CommandException) {
1034 CommandException.Error error =
1035 ((CommandException) (ar.exception)).getCommandError();
1036 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager.CallForwardingInfoCallback
1038 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liu27d24262020-09-18 19:04:59 -07001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liu940c4ca2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager.CallForwardingInfoCallback
1041 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liu27d24262020-09-18 19:04:59 -07001042 }
1043 }
1044 callback.accept(errorCode);
1045 } else {
Hall Liu940c4ca2020-09-29 17:10:18 -07001046 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
Shuo Qian4a594052020-01-23 11:59:30 -08001047 }
Shuo Qian4a594052020-01-23 11:59:30 -08001048 break;
Hall Liu27d24262020-09-18 19:04:59 -07001049 }
Shuo Qian4a594052020-01-23 11:59:30 -08001050
Hall Liu27d24262020-09-18 19:04:59 -07001051 case CMD_GET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1054 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1055 break;
Hall Liu27d24262020-09-18 19:04:59 -07001056 }
Shuo Qian4a594052020-01-23 11:59:30 -08001057
Hall Liu27d24262020-09-18 19:04:59 -07001058 case EVENT_GET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001061 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
Shuo Qian4a594052020-01-23 11:59:30 -08001062 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1063 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001064 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -08001065 // Service Class is a bit mask per 3gpp 27.007.
1066 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001067 if (callForwardResults.length > 1
1068 && ((callForwardResults[1]
Hall Liu27d24262020-09-18 19:04:59 -07001069 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001070 callForwardingStatus = callForwardResults[0] == 0
Hall Liu27d24262020-09-18 19:04:59 -07001071 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1072 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001073 } else {
Hall Liu27d24262020-09-18 19:04:59 -07001074 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
Shuo Qian4a594052020-01-23 11:59:30 -08001075 }
1076 } else {
1077 if (ar.result == null) {
1078 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1079 }
1080 if (ar.exception != null) {
1081 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1082 }
1083 if (ar.exception instanceof CommandException) {
1084 CommandException.Error error =
1085 ((CommandException) (ar.exception)).getCommandError();
1086 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1087 callForwardingStatus =
1088 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1089 }
1090 }
1091 }
Hall Liu27d24262020-09-18 19:04:59 -07001092 callback.accept(callForwardingStatus);
Shuo Qian4a594052020-01-23 11:59:30 -08001093 break;
Hall Liu27d24262020-09-18 19:04:59 -07001094 }
Shuo Qian4a594052020-01-23 11:59:30 -08001095
Hall Liu27d24262020-09-18 19:04:59 -07001096 case CMD_SET_CALL_WAITING: {
Shuo Qian4a594052020-01-23 11:59:30 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liu27d24262020-09-18 19:04:59 -07001099 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1100 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
Shuo Qian4a594052020-01-23 11:59:30 -08001101 break;
Hall Liu27d24262020-09-18 19:04:59 -07001102 }
Shuo Qian4a594052020-01-23 11:59:30 -08001103
Hall Liu27d24262020-09-18 19:04:59 -07001104 case EVENT_SET_CALL_WAITING_DONE: {
Shuo Qian4a594052020-01-23 11:59:30 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liu27d24262020-09-18 19:04:59 -07001107 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1108 Consumer<Integer> callback =
1109 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1110 if (ar.exception != null) {
Shuo Qian4a594052020-01-23 11:59:30 -08001111 loge("setCallWaiting exception: " + ar.exception);
Hall Liu27d24262020-09-18 19:04:59 -07001112 if (ar.exception instanceof CommandException) {
1113 CommandException.Error error =
1114 ((CommandException) (ar.exception)).getCommandError();
1115 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1116 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1117 } else {
1118 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1119 }
1120 } else {
1121 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1122 }
1123 } else {
1124 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1125 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
Shuo Qian4a594052020-01-23 11:59:30 -08001126 }
Shuo Qian4a594052020-01-23 11:59:30 -08001127 break;
Hall Liu27d24262020-09-18 19:04:59 -07001128 }
Shuo Qian4a594052020-01-23 11:59:30 -08001129
Shishir Agrawal302c8692015-06-19 13:49:39 -07001130 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1131 ar = (AsyncResult) msg.obj;
1132 request = (MainThreadRequest) ar.userObj;
1133 CellNetworkScanResult cellScanResult;
1134 if (ar.exception == null && ar.result != null) {
1135 cellScanResult = new CellNetworkScanResult(
1136 CellNetworkScanResult.STATUS_SUCCESS,
1137 (List<OperatorInfo>) ar.result);
1138 } else {
1139 if (ar.result == null) {
1140 loge("getCellNetworkScanResults: Empty response");
1141 }
1142 if (ar.exception != null) {
1143 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1144 }
1145 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1146 if (ar.exception instanceof CommandException) {
1147 CommandException.Error error =
1148 ((CommandException) (ar.exception)).getCommandError();
1149 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1150 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1151 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1152 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1153 }
1154 }
1155 cellScanResult = new CellNetworkScanResult(errorCode, null);
1156 }
1157 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001159 break;
1160
1161 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1162 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001163 ManualNetworkSelectionArgument selArg =
1164 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001165 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1166 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001167 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1168 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001169 break;
1170
1171 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001172 ar = (AsyncResult) msg.obj;
1173 request = (MainThreadRequest) ar.userObj;
1174 if (ar.exception == null) {
1175 request.result = true;
1176 } else {
1177 request.result = false;
1178 loge("setNetworkSelectionModeManual " + ar.exception);
1179 }
1180 notifyRequester(request);
1181 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 break;
1183
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001184 case CMD_GET_MODEM_ACTIVITY_INFO:
1185 request = (MainThreadRequest) msg.obj;
1186 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001187 if (defaultPhone != null) {
1188 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001189 } else {
1190 ResultReceiver result = (ResultReceiver) request.argument;
1191 Bundle bundle = new Bundle();
1192 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
Hall Liu49656c02020-10-09 19:00:11 -07001193 new ModemActivityInfo(0, 0, 0,
1194 new int[ModemActivityInfo.getNumTxPowerLevels()], 0));
Shuo Qian8f4750a2020-02-20 17:12:10 -08001195 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001196 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001197 break;
1198
Hall Liud0f208c2020-10-14 16:54:44 -07001199 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: {
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001200 ar = (AsyncResult) msg.obj;
1201 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001202 ResultReceiver result = (ResultReceiver) request.argument;
1203
Hall Liud0f208c2020-10-14 16:54:44 -07001204 ModemActivityInfo ret = null;
1205 int error = 0;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001206 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001207 // Update the last modem activity info and the result of the request.
1208 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1209 if (isModemActivityInfoValid(info)) {
Hall Liu49656c02020-10-09 19:00:11 -07001210 int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()];
Shuo Qian8f4750a2020-02-20 17:12:10 -08001211 int[] txTimeMs = info.getTransmitTimeMillis();
1212 int[] lastModemTxTimeMs = mLastModemActivityInfo
1213 .getTransmitTimeMillis();
1214 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1215 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1216 }
Hall Liu49656c02020-10-09 19:00:11 -07001217 mLastModemActivityInfo.setTimestamp(info.getTimestampMillis());
Shuo Qian8f4750a2020-02-20 17:12:10 -08001218 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1219 + mLastModemActivityInfo.getSleepTimeMillis());
1220 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1221 + mLastModemActivityInfo.getIdleTimeMillis());
1222 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1223 mLastModemActivityInfo.setReceiveTimeMillis(
1224 info.getReceiveTimeMillis()
1225 + mLastModemActivityInfo.getReceiveTimeMillis());
1226 }
Hall Liu49656c02020-10-09 19:00:11 -07001227 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(),
Shuo Qian8f4750a2020-02-20 17:12:10 -08001228 mLastModemActivityInfo.getSleepTimeMillis(),
1229 mLastModemActivityInfo.getIdleTimeMillis(),
1230 mLastModemActivityInfo.getTransmitTimeMillis(),
1231 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001232 } else {
1233 if (ar.result == null) {
1234 loge("queryModemActivityInfo: Empty response");
Hall Liud0f208c2020-10-14 16:54:44 -07001235 error = TelephonyManager.ModemActivityInfoException
1236 .ERROR_INVALID_INFO_RECEIVED;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001237 } else if (ar.exception instanceof CommandException) {
1238 loge("queryModemActivityInfo: CommandException: " +
1239 ar.exception);
Hall Liud0f208c2020-10-14 16:54:44 -07001240 error = TelephonyManager.ModemActivityInfoException
1241 .ERROR_MODEM_RESPONSE_ERROR;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001242 } else {
1243 loge("queryModemActivityInfo: Unknown exception");
Hall Liud0f208c2020-10-14 16:54:44 -07001244 error = TelephonyManager.ModemActivityInfoException
1245 .ERROR_UNKNOWN;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 }
1247 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001248 Bundle bundle = new Bundle();
Hall Liud0f208c2020-10-14 16:54:44 -07001249 if (ret != null) {
1250 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1251 } else {
1252 bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error);
1253 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001254 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001255 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001256 break;
Hall Liud0f208c2020-10-14 16:54:44 -07001257 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001258
Meng Wang1a7c35a2016-05-05 20:56:15 -07001259 case CMD_SET_ALLOWED_CARRIERS:
1260 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001261 CarrierRestrictionRules argument =
1262 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001264 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001265 break;
1266
1267 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1268 ar = (AsyncResult) msg.obj;
1269 request = (MainThreadRequest) ar.userObj;
1270 if (ar.exception == null && ar.result != null) {
1271 request.result = ar.result;
1272 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001273 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1274 if (ar.exception instanceof CommandException) {
1275 loge("setAllowedCarriers: CommandException: " + ar.exception);
1276 CommandException.Error error =
1277 ((CommandException) (ar.exception)).getCommandError();
1278 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1279 request.result =
1280 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1281 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001282 } else {
1283 loge("setAllowedCarriers: Unknown exception");
1284 }
1285 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001286 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001287 break;
1288
1289 case CMD_GET_ALLOWED_CARRIERS:
1290 request = (MainThreadRequest) msg.obj;
1291 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001292 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001293 break;
1294
1295 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1296 ar = (AsyncResult) msg.obj;
1297 request = (MainThreadRequest) ar.userObj;
1298 if (ar.exception == null && ar.result != null) {
1299 request.result = ar.result;
1300 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001301 request.result = new IllegalStateException(
1302 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001303 if (ar.result == null) {
1304 loge("getAllowedCarriers: Empty response");
1305 } else if (ar.exception instanceof CommandException) {
1306 loge("getAllowedCarriers: CommandException: " +
1307 ar.exception);
1308 } else {
1309 loge("getAllowedCarriers: Unknown exception");
1310 }
1311 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001312 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001313 break;
1314
Nathan Haroldb3014052017-01-25 15:57:32 -08001315 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1316 ar = (AsyncResult) msg.obj;
1317 request = (MainThreadRequest) ar.userObj;
1318 if (ar.exception == null && ar.result != null) {
1319 request.result = ar.result;
1320 } else {
1321 request.result = new IllegalArgumentException(
1322 "Failed to retrieve Forbidden Plmns");
1323 if (ar.result == null) {
1324 loge("getForbiddenPlmns: Empty response");
1325 } else {
1326 loge("getForbiddenPlmns: Unknown exception");
1327 }
1328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001329 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001330 break;
1331
1332 case CMD_GET_FORBIDDEN_PLMNS:
1333 request = (MainThreadRequest) msg.obj;
1334 uiccCard = getUiccCardFromRequest(request);
1335 if (uiccCard == null) {
1336 loge("getForbiddenPlmns() UiccCard is null");
1337 request.result = new IllegalArgumentException(
1338 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001339 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001340 break;
1341 }
1342 Integer appType = (Integer) request.argument;
1343 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1344 if (uiccApp == null) {
1345 loge("getForbiddenPlmns() no app with specified type -- "
1346 + appType);
1347 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001348 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001349 break;
1350 } else {
1351 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1352 + " specified type -- " + appType);
1353 }
1354 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1355 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1356 onCompleted);
1357 break;
1358
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001359 case CMD_SWITCH_SLOTS:
1360 request = (MainThreadRequest) msg.obj;
1361 int[] physicalSlots = (int[]) request.argument;
1362 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1363 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1364 break;
1365
1366 case EVENT_SWITCH_SLOTS_DONE:
1367 ar = (AsyncResult) msg.obj;
1368 request = (MainThreadRequest) ar.userObj;
1369 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001370 notifyRequester(request);
1371 break;
1372 case CMD_GET_NETWORK_SELECTION_MODE:
1373 request = (MainThreadRequest) msg.obj;
1374 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1375 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1376 break;
1377
1378 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1379 ar = (AsyncResult) msg.obj;
1380 request = (MainThreadRequest) ar.userObj;
1381 if (ar.exception != null) {
1382 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1383 } else {
1384 int mode = ((int[]) ar.result)[0];
1385 if (mode == 0) {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1387 } else {
1388 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1389 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001390 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001391 notifyRequester(request);
1392 break;
1393 case CMD_GET_CDMA_ROAMING_MODE:
1394 request = (MainThreadRequest) msg.obj;
1395 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1396 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1397 break;
1398 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1399 ar = (AsyncResult) msg.obj;
1400 request = (MainThreadRequest) ar.userObj;
1401 if (ar.exception != null) {
1402 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1403 } else {
1404 request.result = ((int[]) ar.result)[0];
1405 }
1406 notifyRequester(request);
1407 break;
1408 case CMD_SET_CDMA_ROAMING_MODE:
1409 request = (MainThreadRequest) msg.obj;
1410 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1411 int mode = (int) request.argument;
1412 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1413 break;
1414 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1415 ar = (AsyncResult) msg.obj;
1416 request = (MainThreadRequest) ar.userObj;
1417 request.result = ar.exception == null;
1418 notifyRequester(request);
1419 break;
Sarah Chinbaab1432020-10-28 13:46:24 -07001420 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1421 request = (MainThreadRequest) msg.obj;
1422 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1423 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1424 break;
1425 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1426 ar = (AsyncResult) msg.obj;
1427 request = (MainThreadRequest) ar.userObj;
1428 if (ar.exception != null) {
1429 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1430 } else {
1431 request.result = ((int[]) ar.result)[0];
1432 }
1433 notifyRequester(request);
1434 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001435 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1436 request = (MainThreadRequest) msg.obj;
1437 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1438 int subscriptionMode = (int) request.argument;
Sarah Chinbaab1432020-10-28 13:46:24 -07001439 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1440 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001441 break;
1442 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1443 ar = (AsyncResult) msg.obj;
1444 request = (MainThreadRequest) ar.userObj;
1445 request.result = ar.exception == null;
1446 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001447 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 case CMD_GET_ALL_CELL_INFO:
1449 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001451 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 case EVENT_GET_ALL_CELL_INFO_DONE:
1454 ar = (AsyncResult) msg.obj;
1455 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001456 // If a timeout occurs, the response will be null
1457 request.result = (ar.exception == null && ar.result != null)
1458 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001459 synchronized (request) {
1460 request.notifyAll();
1461 }
1462 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001463 case CMD_REQUEST_CELL_INFO_UPDATE:
1464 request = (MainThreadRequest) msg.obj;
1465 request.phone.requestCellInfoUpdate(request.workSource,
1466 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1467 break;
1468 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1469 ar = (AsyncResult) msg.obj;
1470 request = (MainThreadRequest) ar.userObj;
1471 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1472 try {
1473 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001474 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001475 cb.onError(
1476 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1477 ar.exception.getClass().getName(),
1478 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001479 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001481 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 } else {
1483 // use the result as returned
1484 cb.onCellInfo((List<CellInfo>) ar.result);
1485 }
1486 } catch (RemoteException re) {
1487 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1488 }
1489 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001490 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 request = (MainThreadRequest) msg.obj;
1492 WorkSource ws = (WorkSource) request.argument;
1493 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001494 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001496 }
1497 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 ar = (AsyncResult) msg.obj;
1499 request = (MainThreadRequest) ar.userObj;
1500 if (ar.exception == null) {
1501 request.result = ar.result;
1502 } else {
Sarah Chin679c08a2020-11-18 13:39:35 -08001503 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001505 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 }
1507
1508 synchronized (request) {
1509 request.notifyAll();
1510 }
1511 break;
Sarah Chin679c08a2020-11-18 13:39:35 -08001512 }
chen xu6dac5ab2018-10-26 17:39:23 -07001513 case CMD_MODEM_REBOOT:
1514 request = (MainThreadRequest) msg.obj;
1515 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001516 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001517 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001518 case EVENT_CMD_MODEM_REBOOT_DONE:
1519 handleNullReturnEvent(msg, "rebootModem");
1520 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001521 case CMD_REQUEST_ENABLE_MODEM:
1522 request = (MainThreadRequest) msg.obj;
1523 boolean enable = (boolean) request.argument;
1524 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001525 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001526 PhoneConfigurationManager.getInstance()
1527 .enablePhone(request.phone, enable, onCompleted);
1528 break;
1529 case EVENT_ENABLE_MODEM_DONE:
1530 ar = (AsyncResult) msg.obj;
1531 request = (MainThreadRequest) ar.userObj;
1532 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001533 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001534 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001535 if ((boolean) request.result) {
1536 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1537 updateModemStateMetrics();
1538 } else {
1539 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1540 + ar.exception);
1541 }
1542 notifyRequester(request);
1543 break;
1544 case CMD_GET_MODEM_STATUS:
1545 request = (MainThreadRequest) msg.obj;
1546 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1547 PhoneConfigurationManager.getInstance()
1548 .getPhoneStatusFromModem(request.phone, onCompleted);
1549 break;
1550 case EVENT_GET_MODEM_STATUS_DONE:
1551 ar = (AsyncResult) msg.obj;
1552 request = (MainThreadRequest) ar.userObj;
1553 int id = request.phone.getPhoneId();
1554 if (ar.exception == null && ar.result != null) {
1555 request.result = ar.result;
1556 //update the cache as modem status has changed
1557 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1558 (boolean) request.result);
1559 } else {
1560 // Return true if modem status cannot be retrieved. For most cases,
1561 // modem status is on. And for older version modems, GET_MODEM_STATUS
1562 // and disable modem are not supported. Modem is always on.
1563 // TODO: this should be fixed in R to support a third
1564 // status UNKNOWN b/131631629
1565 request.result = true;
1566 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1567 + ar.exception);
1568 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001569 notifyRequester(request);
1570 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001571 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1572 request = (MainThreadRequest) msg.obj;
1573 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1574 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1575 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1576 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1577 break;
1578 }
1579 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1580 ar = (AsyncResult) msg.obj;
1581 request = (MainThreadRequest) ar.userObj;
1582 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1583 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1584 args.second.accept(ar.exception == null);
1585 notifyRequester(request);
1586 break;
1587 }
Sarah Chin679c08a2020-11-18 13:39:35 -08001588 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1589 request = (MainThreadRequest) msg.obj;
1590 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1591 Phone phone = getPhoneFromRequest(request);
1592 if (phone != null) {
1593 phone.getSystemSelectionChannels(onCompleted);
1594 } else {
1595 loge("getSystemSelectionChannels: No phone object");
1596 request.result = new ArrayList<RadioAccessSpecifier>();
1597 notifyRequester(request);
1598 }
1599 break;
1600 }
1601 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1602 ar = (AsyncResult) msg.obj;
1603 request = (MainThreadRequest) ar.userObj;
1604 if (ar.exception == null && ar.result != null) {
1605 request.result = ar.result;
1606 } else {
1607 request.result = new IllegalArgumentException(
1608 "Failed to retrieve system selection channels");
1609 if (ar.result == null) {
1610 loge("getSystemSelectionChannels: Empty response");
1611 } else {
1612 loge("getSystemSelectionChannels: Unknown exception");
1613 }
1614 }
1615 notifyRequester(request);
1616 break;
yincheng zhao2737e882019-09-06 17:06:54 -07001617 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1618 ar = (AsyncResult) msg.obj;
1619 request = (MainThreadRequest) ar.userObj;
1620 if (ar.exception == null && ar.result != null) {
1621 request.result = ar.result;
1622 } else {
1623 request.result = -1;
1624 loge("Failed to set Forbidden Plmns");
1625 if (ar.result == null) {
1626 loge("setForbidenPlmns: Empty response");
1627 } else if (ar.exception != null) {
1628 loge("setForbiddenPlmns: Exception: " + ar.exception);
1629 request.result = -1;
1630 } else {
1631 loge("setForbiddenPlmns: Unknown exception");
1632 }
1633 }
1634 notifyRequester(request);
1635 break;
1636 case CMD_SET_FORBIDDEN_PLMNS:
1637 request = (MainThreadRequest) msg.obj;
1638 uiccCard = getUiccCardFromRequest(request);
1639 if (uiccCard == null) {
1640 loge("setForbiddenPlmns: UiccCard is null");
1641 request.result = -1;
1642 notifyRequester(request);
1643 break;
1644 }
1645 Pair<Integer, List<String>> setFplmnsArgs =
1646 (Pair<Integer, List<String>>) request.argument;
1647 appType = setFplmnsArgs.first;
1648 List<String> fplmns = setFplmnsArgs.second;
1649 uiccApp = uiccCard.getApplicationByType(appType);
1650 if (uiccApp == null) {
1651 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1652 request.result = -1;
1653 loge("Failed to get UICC App");
1654 notifyRequester(request);
1655 } else {
1656 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1657 ((SIMRecords) uiccApp.getIccRecords())
1658 .setForbiddenPlmns(onCompleted, fplmns);
1659 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001660 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001661 case CMD_ERASE_MODEM_CONFIG:
1662 request = (MainThreadRequest) msg.obj;
1663 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1664 defaultPhone.eraseModemConfig(onCompleted);
1665 break;
1666 case EVENT_ERASE_MODEM_CONFIG_DONE:
1667 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001668 break;
zoey chene02881a2019-12-30 16:11:23 +08001669
1670 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1673 Pair<String, String> changed = (Pair<String, String>) request.argument;
1674 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1675 changed.first, changed.second, onCompleted);
1676 break;
1677 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1678 ar = (AsyncResult) msg.obj;
1679 request = (MainThreadRequest) ar.userObj;
1680 if (ar.exception == null) {
1681 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1682 } else {
1683 request.result = msg.arg1;
1684 }
1685 notifyRequester(request);
1686 break;
1687
1688 case CMD_SET_ICC_LOCK_ENABLED:
1689 request = (MainThreadRequest) msg.obj;
1690 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1691 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1692 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1693 enabled.first, enabled.second, onCompleted);
1694 break;
1695 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1696 ar = (AsyncResult) msg.obj;
1697 request = (MainThreadRequest) ar.userObj;
1698 if (ar.exception == null) {
1699 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1700 } else {
1701 request.result = msg.arg1;
1702 }
1703 notifyRequester(request);
1704 break;
1705
Peter Wangdafb9ac2020-01-15 14:13:38 -08001706 case MSG_NOTIFY_USER_ACTIVITY:
1707 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001708 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001709 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1710 getDefaultPhone().getContext().sendBroadcastAsUser(
1711 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1712 break;
Jack Nudelmanb0b87642020-11-12 15:04:39 -08001713
1714 case CMD_SET_DATA_THROTTLING: {
1715 request = (MainThreadRequest) msg.obj;
1716 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1717 DataThrottlingRequest dataThrottlingRequest =
1718 (DataThrottlingRequest) request.argument;
1719 Phone phone = getPhoneFromRequest(request);
1720 if (phone != null) {
1721 phone.setDataThrottling(onCompleted,
1722 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1723 dataThrottlingRequest.getCompletionDurationMillis());
1724 } else {
1725 loge("setDataThrottling: No phone object");
1726 request.result =
1727 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1728 notifyRequester(request);
1729 }
1730
1731 break;
1732 }
1733 case EVENT_SET_DATA_THROTTLING_DONE:
1734 ar = (AsyncResult) msg.obj;
1735 request = (MainThreadRequest) ar.userObj;
1736
1737 if (ar.exception == null) {
1738 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1739 } else if (ar.exception instanceof CommandException) {
1740 loge("setDataThrottling: CommandException: " + ar.exception);
1741 CommandException.Error error =
1742 ((CommandException) (ar.exception)).getCommandError();
1743
1744 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1745 request.result = TelephonyManager
1746 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1747 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1748 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1749 } else {
1750 request.result =
1751 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1752 }
1753 } else {
1754 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1755 }
1756 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1757 notifyRequester(request);
1758 break;
Jordan Liu109698e2020-11-24 14:50:34 -08001759
1760 case CMD_SET_SIM_POWER: {
1761 request = (MainThreadRequest) msg.obj;
1762 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1763 request = (MainThreadRequest) msg.obj;
1764 int stateToSet =
1765 ((Pair<Integer, IIntegerConsumer>)
1766 request.argument).first;
1767 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1768 break;
1769 }
1770 case EVENT_SET_SIM_POWER_DONE: {
1771 ar = (AsyncResult) msg.obj;
1772 request = (MainThreadRequest) ar.userObj;
1773 IIntegerConsumer callback =
1774 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1775 if (ar.exception != null) {
1776 loge("setSimPower exception: " + ar.exception);
1777 int errorCode = TelephonyManager.CallForwardingInfoCallback
1778 .RESULT_ERROR_UNKNOWN;
1779 if (ar.exception instanceof CommandException) {
1780 CommandException.Error error =
1781 ((CommandException) (ar.exception)).getCommandError();
1782 if (error == CommandException.Error.SIM_ERR) {
1783 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1784 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1785 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1786 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1787 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1788 } else {
1789 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1790 }
1791 }
1792 try {
1793 callback.accept(errorCode);
1794 } catch (RemoteException e) {
1795 // Ignore if the remote process is no longer available to call back.
1796 Log.w(LOG_TAG, "setSimPower: callback not available.");
1797 }
1798 } else {
1799 try {
1800 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1801 } catch (RemoteException e) {
1802 // Ignore if the remote process is no longer available to call back.
1803 Log.w(LOG_TAG, "setSimPower: callback not available.");
1804 }
1805 }
1806 break;
1807 }
1808
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 default:
1810 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1811 break;
1812 }
1813 }
Jake Hambye994d462014-02-03 13:10:13 -08001814
Pengquan Menga1bb6272018-09-06 09:59:22 -07001815 private void notifyRequester(MainThreadRequest request) {
1816 synchronized (request) {
1817 request.notifyAll();
1818 }
1819 }
1820
Jake Hambye994d462014-02-03 13:10:13 -08001821 private void handleNullReturnEvent(Message msg, String command) {
1822 AsyncResult ar = (AsyncResult) msg.obj;
1823 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1824 if (ar.exception == null) {
1825 request.result = true;
1826 } else {
1827 request.result = false;
1828 if (ar.exception instanceof CommandException) {
1829 loge(command + ": CommandException: " + ar.exception);
1830 } else {
1831 loge(command + ": Unknown exception");
1832 }
1833 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001834 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001835 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001836 }
1837
1838 /**
1839 * Posts the specified command to be executed on the main thread,
1840 * waits for the request to complete, and returns the result.
1841 * @see #sendRequestAsync
1842 */
1843 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001844 return sendRequest(
1845 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001846 }
1847
1848 /**
1849 * Posts the specified command to be executed on the main thread,
1850 * waits for the request to complete, and returns the result.
1851 * @see #sendRequestAsync
1852 */
1853 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1854 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001855 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001856 }
1857
1858 /**
1859 * Posts the specified command to be executed on the main thread,
1860 * waits for the request to complete, and returns the result.
1861 * @see #sendRequestAsync
1862 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001863 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001864 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001865 }
1866
1867 /**
1868 * Posts the specified command to be executed on the main thread,
1869 * waits for the request to complete, and returns the result.
1870 * @see #sendRequestAsync
1871 */
Nathan Harold92bed182018-10-12 18:16:49 -07001872 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1873 return sendRequest(command, argument, subId, null, workSource);
1874 }
1875
1876 /**
1877 * Posts the specified command to be executed on the main thread,
1878 * waits for the request to complete, and returns the result.
1879 * @see #sendRequestAsync
1880 */
1881 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1882 return sendRequest(
1883 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1884 }
1885
1886 /**
1887 * Posts the specified command to be executed on the main thread,
1888 * waits for the request to complete, and returns the result.
1889 * @see #sendRequestAsync
1890 */
1891 private Object sendRequest(
1892 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1894 throw new RuntimeException("This method will deadlock if called from the main thread.");
1895 }
1896
Nathan Harold92bed182018-10-12 18:16:49 -07001897 MainThreadRequest request = null;
1898 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1899 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1900 } else if (phone != null) {
1901 request = new MainThreadRequest(argument, phone, workSource);
1902 } else {
1903 request = new MainThreadRequest(argument, subId, workSource);
1904 }
1905
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001906 Message msg = mMainThreadHandler.obtainMessage(command, request);
1907 msg.sendToTarget();
1908
1909 // Wait for the request to complete
1910 synchronized (request) {
1911 while (request.result == null) {
1912 try {
1913 request.wait();
1914 } catch (InterruptedException e) {
1915 // Do nothing, go back and wait until the request is complete
1916 }
1917 }
1918 }
1919 return request.result;
1920 }
1921
1922 /**
1923 * Asynchronous ("fire and forget") version of sendRequest():
1924 * Posts the specified command to be executed on the main thread, and
1925 * returns immediately.
1926 * @see #sendRequest
1927 */
1928 private void sendRequestAsync(int command) {
1929 mMainThreadHandler.sendEmptyMessage(command);
1930 }
1931
1932 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001933 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001934 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001935 */
1936 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001937 sendRequestAsync(command, argument, null, null);
1938 }
1939
1940 /**
1941 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1942 * @see {@link #sendRequest(int,Object)}
1943 */
1944 private void sendRequestAsync(
1945 int command, Object argument, Phone phone, WorkSource workSource) {
1946 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001947 Message msg = mMainThreadHandler.obtainMessage(command, request);
1948 msg.sendToTarget();
1949 }
1950
1951 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 * Initialize the singleton PhoneInterfaceManager instance.
1953 * This is only done once, at startup, from PhoneApp.onCreate().
1954 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001955 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 synchronized (PhoneInterfaceManager.class) {
1957 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001958 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 } else {
1960 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1961 }
1962 return sInstance;
1963 }
1964 }
1965
1966 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001967 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001969 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001970 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001971 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001972 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1973 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001974 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001975 mTelephonySharedPreferences =
1976 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001977 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001978 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001979 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001980
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001981 publish();
1982 }
1983
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001984 private Phone getDefaultPhone() {
1985 Phone thePhone = getPhone(getDefaultSubscription());
1986 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1987 }
1988
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001989 private void publish() {
1990 if (DBG) log("publish: " + this);
1991
Peter Wangc035ce42020-01-08 21:00:22 -08001992 TelephonyFrameworkInitializer
1993 .getTelephonyServiceManager()
1994 .getTelephonyServiceRegisterer()
1995 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997
Stuart Scott584921c2015-01-15 17:10:34 -08001998 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001999 if (request.phone != null) {
2000 return request.phone;
2001 } else {
2002 return getPhoneFromSubId(request.subId);
2003 }
2004 }
2005
2006 private Phone getPhoneFromSubId(int subId) {
2007 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2008 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002009 }
2010
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002011 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2012 Phone phone = getPhoneFromRequest(request);
2013 return phone == null ? null :
2014 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2015 }
2016
Wink Saville36469e72014-06-11 15:17:00 -07002017 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002018 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002019 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002020 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021
Naina Nallurid63128d2019-09-17 14:10:30 -07002022 private void sendEraseModemConfig(Phone phone) {
2023 if (phone != null) {
2024 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2025 mApp, phone.getSubId(), "eraseModemConfig");
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2029 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
2033 }
2034 }
2035
Peter Wang44b186e2020-01-13 23:33:09 -08002036 private boolean isImsAvailableOnDevice() {
2037 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2038 if (pm == null) {
2039 // For some reason package manger is not available.. This will fail internally anyway,
2040 // so do not throw error and allow.
2041 return true;
2042 }
2043 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2044 }
2045
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002046 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002047 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002048 }
2049
Wink Savilleb564aae2014-10-23 10:18:09 -07002050 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 if (DBG) log("dial: " + number);
2052 // No permission check needed here: This is just a wrapper around the
2053 // ACTION_DIAL intent, which is available to any app since it puts up
2054 // the UI before it does anything.
2055
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 String url = createTelUrl(number);
2059 if (url == null) {
2060 return;
2061 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002062
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002063 // PENDING: should we just silently fail if phone is offhook or ringing?
2064 PhoneConstants.State state = mCM.getState(subId);
2065 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2066 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2067 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2068 mApp.startActivity(intent);
2069 }
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
2073 }
2074
2075 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002076 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002077 }
2078
Wink Savilleb564aae2014-10-23 10:18:09 -07002079 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 if (DBG) log("call: " + number);
2081
2082 // This is just a wrapper around the ACTION_CALL intent, but we still
2083 // need to do a permission check since we're calling startActivity()
2084 // from the context of the phone app.
2085 enforceCallPermission();
2086
Jordan Liu1617b712019-07-10 15:06:26 -07002087 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 != AppOpsManager.MODE_ALLOWED) {
2089 return;
2090 }
2091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002092 final long identity = Binder.clearCallingIdentity();
2093 try {
2094 String url = createTelUrl(number);
2095 if (url == null) {
2096 return;
2097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 boolean isValid = false;
2100 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2101 if (slist != null) {
2102 for (SubscriptionInfo subInfoRecord : slist) {
2103 if (subInfoRecord.getSubscriptionId() == subId) {
2104 isValid = true;
2105 break;
2106 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002107 }
Wink Saville08874612014-08-31 19:19:58 -07002108 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002109 if (!isValid) {
2110 return;
2111 }
Wink Saville08874612014-08-31 19:19:58 -07002112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002113 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2114 intent.putExtra(SUBSCRIPTION_KEY, subId);
2115 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2116 mApp.startActivity(intent);
2117 } finally {
2118 Binder.restoreCallingIdentity(identity);
2119 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 }
2121
Wink Savilleb564aae2014-10-23 10:18:09 -07002122 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002123 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002124 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2125 }
2126
Wink Savilleb564aae2014-10-23 10:18:09 -07002127 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002128 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002129 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2130 }
2131
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2138 checkSimPin.start();
2139 return checkSimPin.unlockSim(null, pin);
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
Wink Savilleb564aae2014-10-23 10:18:09 -07002145 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147
2148 final long identity = Binder.clearCallingIdentity();
2149 try {
2150 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2151 checkSimPuk.start();
2152 return checkSimPuk.unlockSim(puk, pin);
2153 } finally {
2154 Binder.restoreCallingIdentity(identity);
2155 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157
2158 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002159 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 * a synchronous one.
2161 */
2162 private static class UnlockSim extends Thread {
2163
2164 private final IccCard mSimCard;
2165
2166 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002167 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2168 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169
2170 // For replies from SimCard interface
2171 private Handler mHandler;
2172
2173 // For async handler to identify request type
2174 private static final int SUPPLY_PIN_COMPLETE = 100;
2175
2176 public UnlockSim(IccCard simCard) {
2177 mSimCard = simCard;
2178 }
2179
2180 @Override
2181 public void run() {
2182 Looper.prepare();
2183 synchronized (UnlockSim.this) {
2184 mHandler = new Handler() {
2185 @Override
2186 public void handleMessage(Message msg) {
2187 AsyncResult ar = (AsyncResult) msg.obj;
2188 switch (msg.what) {
2189 case SUPPLY_PIN_COMPLETE:
2190 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2191 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002192 mRetryCount = msg.arg1;
2193 if (ar.exception != null) {
2194 if (ar.exception instanceof CommandException &&
2195 ((CommandException)(ar.exception)).getCommandError()
2196 == CommandException.Error.PASSWORD_INCORRECT) {
2197 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002198 } //When UiccCardApp dispose,handle message and return exception
2199 else if (ar.exception instanceof CommandException &&
2200 ((CommandException) (ar.exception)).getCommandError()
2201 == CommandException.Error.ABORTED) {
2202 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002203 } else {
2204 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2205 }
2206 } else {
2207 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002209 mDone = true;
2210 UnlockSim.this.notifyAll();
2211 }
2212 break;
2213 }
2214 }
2215 };
2216 UnlockSim.this.notifyAll();
2217 }
2218 Looper.loop();
2219 }
2220
2221 /*
2222 * Use PIN or PUK to unlock SIM card
2223 *
2224 * If PUK is null, unlock SIM card with PIN
2225 *
2226 * If PUK is not null, unlock SIM card with PUK and set PIN code
2227 */
Wink Saville9de0f752013-10-22 19:04:03 -07002228 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002229
2230 while (mHandler == null) {
2231 try {
2232 wait();
2233 } catch (InterruptedException e) {
2234 Thread.currentThread().interrupt();
2235 }
2236 }
2237 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2238
2239 if (puk == null) {
2240 mSimCard.supplyPin(pin, callback);
2241 } else {
2242 mSimCard.supplyPuk(puk, pin, callback);
2243 }
2244
2245 while (!mDone) {
2246 try {
2247 Log.d(LOG_TAG, "wait for done");
2248 wait();
2249 } catch (InterruptedException e) {
2250 // Restore the interrupted status
2251 Thread.currentThread().interrupt();
2252 }
2253 }
2254 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002255 int[] resultArray = new int[2];
2256 resultArray[0] = mResult;
2257 resultArray[1] = mRetryCount;
2258 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260 }
2261
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002262 /**
2263 * This method has been removed due to privacy and stability concerns.
2264 */
2265 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002267 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2268 return;
Wink Saville36469e72014-06-11 15:17:00 -07002269 }
2270
Nathan Harold1f889d82020-06-04 17:05:26 -07002271 @Override
2272 public void updateServiceLocationWithPackageName(String callingPackage) {
2273 mApp.getSystemService(AppOpsManager.class)
2274 .checkPackage(Binder.getCallingUid(), callingPackage);
2275
Nathan Haroldf096d982020-11-18 17:18:06 -08002276 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002277 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2278 // Callers targeting S have no business invoking this method.
2279 return;
2280 }
2281
2282 LocationAccessPolicy.LocationPermissionResult locationResult =
2283 LocationAccessPolicy.checkLocationPermission(mApp,
2284 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2285 .setCallingPackage(callingPackage)
2286 .setCallingFeatureId(null)
2287 .setCallingPid(Binder.getCallingPid())
2288 .setCallingUid(Binder.getCallingUid())
2289 .setMethod("updateServiceLocation")
2290 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2291 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2292 .build());
2293 // Apps that lack location permission have no business calling this method;
2294 // however, because no permission was declared in the public API, denials must
2295 // all be "soft".
2296 switch (locationResult) {
2297 case DENIED_HARD: /* fall through */
2298 case DENIED_SOFT:
2299 return;
2300 }
2301
2302 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002303 final long identity = Binder.clearCallingIdentity();
2304 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002305 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002307 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002308 }
2309 } finally {
2310 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002311 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002312 }
2313
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002314 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 @Override
2316 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002317 return isRadioOnWithFeature(callingPackage, null);
2318 }
2319
2320
2321 @Override
2322 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2323 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2324 callingFeatureId);
2325 }
2326
2327 @Deprecated
2328 @Override
2329 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
2330 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002331 }
2332
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002334 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2335 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002336 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002337 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002338 return false;
2339 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340
2341 final long identity = Binder.clearCallingIdentity();
2342 try {
2343 return isRadioOnForSubscriber(subId);
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
2346 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002347 }
2348
2349 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350 final long identity = Binder.clearCallingIdentity();
2351 try {
2352 final Phone phone = getPhone(subId);
2353 if (phone != null) {
2354 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2355 } else {
2356 return false;
2357 }
2358 } finally {
2359 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002360 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002361 }
2362
2363 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 }
Wink Saville36469e72014-06-11 15:17:00 -07002366
Wink Savilleb564aae2014-10-23 10:18:09 -07002367 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002368 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002369
2370 final long identity = Binder.clearCallingIdentity();
2371 try {
2372 final Phone phone = getPhone(subId);
2373 if (phone != null) {
2374 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2375 }
2376 } finally {
2377 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002378 }
Wink Saville36469e72014-06-11 15:17:00 -07002379 }
2380
2381 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002382 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002383 }
2384
Wink Savilleb564aae2014-10-23 10:18:09 -07002385 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387
2388 final long identity = Binder.clearCallingIdentity();
2389 try {
2390 final Phone phone = getPhone(subId);
2391 if (phone == null) {
2392 return false;
2393 }
2394 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2395 toggleRadioOnOffForSubscriber(subId);
2396 }
2397 return true;
2398 } finally {
2399 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002401 }
Wink Saville36469e72014-06-11 15:17:00 -07002402
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002403 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002404 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002405 /*
2406 * If any of the Radios are available, it will need to be
2407 * shutdown. So return true if any Radio is available.
2408 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 final long identity = Binder.clearCallingIdentity();
2410 try {
2411 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2412 Phone phone = PhoneFactory.getPhone(i);
2413 if (phone != null && phone.isRadioAvailable()) return true;
2414 }
2415 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2416 return false;
2417 } finally {
2418 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002419 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002420 }
2421
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002422 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002423 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424 enforceModifyPermission();
2425
2426 final long identity = Binder.clearCallingIdentity();
2427 try {
2428 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2429 logv("Shutting down Phone " + i);
2430 shutdownRadioUsingPhoneId(i);
2431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002434 }
2435 }
2436
2437 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002438 Phone phone = PhoneFactory.getPhone(phoneId);
2439 if (phone != null && phone.isRadioAvailable()) {
2440 phone.shutdownRadio();
2441 }
2442 }
2443
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002444 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002445 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002446
2447 final long identity = Binder.clearCallingIdentity();
2448 try {
2449 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2450 if (defaultPhone != null) {
2451 defaultPhone.setRadioPower(turnOn);
2452 return true;
2453 } else {
2454 loge("There's no default phone.");
2455 return false;
2456 }
2457 } finally {
2458 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002459 }
Wink Saville36469e72014-06-11 15:17:00 -07002460 }
2461
Wink Savilleb564aae2014-10-23 10:18:09 -07002462 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 final Phone phone = getPhone(subId);
2468 if (phone != null) {
2469 phone.setRadioPower(turnOn);
2470 return true;
2471 } else {
2472 return false;
2473 }
2474 } finally {
2475 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002476 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Wink Saville36469e72014-06-11 15:17:00 -07002479 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002480 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 public boolean enableDataConnectivity() {
2482 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002483
2484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 int subId = mSubscriptionController.getDefaultDataSubId();
2487 final Phone phone = getPhone(subId);
2488 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002489 phone.getDataEnabledSettings().setDataEnabled(
2490 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491 return true;
2492 } else {
2493 return false;
2494 }
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002497 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002498 }
2499
Wink Saville36469e72014-06-11 15:17:00 -07002500 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002502 public boolean disableDataConnectivity() {
2503 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002504
2505 final long identity = Binder.clearCallingIdentity();
2506 try {
2507 int subId = mSubscriptionController.getDefaultDataSubId();
2508 final Phone phone = getPhone(subId);
2509 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002510 phone.getDataEnabledSettings().setDataEnabled(
2511 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002512 return true;
2513 } else {
2514 return false;
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002518 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002519 }
2520
Sanket Padawe356d7632015-06-22 14:03:32 -07002521 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002522 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002523 final long identity = Binder.clearCallingIdentity();
2524 try {
2525 final Phone phone = getPhone(subId);
2526 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002527 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528 } else {
2529 return false;
2530 }
2531 } finally {
2532 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002533 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002534 }
2535
2536 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002537 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002538 }
2539
pkanwarae03a6b2016-11-06 20:37:09 -08002540 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541 enforceCallPermission();
2542
2543 final long identity = Binder.clearCallingIdentity();
2544 try {
2545 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2546 return;
2547 }
2548 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2549 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
2552 }
pkanwar32d516d2016-10-14 19:37:38 -07002553 };
2554
Wink Savilleb564aae2014-10-23 10:18:09 -07002555 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002557
2558 final long identity = Binder.clearCallingIdentity();
2559 try {
2560 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2561 return false;
2562 }
2563 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2564 } finally {
2565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 }
2568
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002571 }
2572
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002573 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574 final long identity = Binder.clearCallingIdentity();
2575 try {
2576 Phone phone = PhoneFactory.getPhone(slotIndex);
2577 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2578 PhoneConstantConversions.convertCallState(phone.getState());
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
2581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
Sanket Padawe356d7632015-06-22 14:03:32 -07002584 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002585 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002586 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2587 }
2588
2589 @Override
2590 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002591 final long identity = Binder.clearCallingIdentity();
2592 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002594 if (phone != null) {
2595 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2596 } else {
2597 return PhoneConstantConversions.convertDataState(
2598 PhoneConstants.DataState.DISCONNECTED);
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002606 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002607 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2608 }
2609
2610 @Override
2611 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 final long identity = Binder.clearCallingIdentity();
2613 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002614 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 if (phone != null) {
2616 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2617 } else {
2618 return TelephonyManager.DATA_ACTIVITY_NONE;
2619 }
2620 } finally {
2621 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002622 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002623 }
2624
2625 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002626 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002627 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002628 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002629
2630 LocationAccessPolicy.LocationPermissionResult locationResult =
2631 LocationAccessPolicy.checkLocationPermission(mApp,
2632 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2633 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002634 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002635 .setCallingPid(Binder.getCallingPid())
2636 .setCallingUid(Binder.getCallingUid())
2637 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002638 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002639 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2640 .build());
2641 switch (locationResult) {
2642 case DENIED_HARD:
2643 throw new SecurityException("Not allowed to access cell location");
2644 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002645 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2646 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002649 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002650 final long identity = Binder.clearCallingIdentity();
2651 try {
2652 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002653 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002654 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 } finally {
2656 Binder.restoreCallingIdentity(identity);
2657 }
Svetoslav64fad262015-04-14 14:35:21 -07002658 }
2659
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002660 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002661 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002662 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2663 // registered cell info, so return a NULL country instead.
2664 final long identity = Binder.clearCallingIdentity();
2665 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002666 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2667 // Get default phone in this case.
2668 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2669 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002670 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002671 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002672 if (phone == null) return "";
2673 ServiceStateTracker sst = phone.getServiceStateTracker();
2674 if (sst == null) return "";
2675 LocaleTracker lt = sst.getLocaleTracker();
2676 if (lt == null) return "";
2677 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2678 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2679 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002680 } finally {
2681 Binder.restoreCallingIdentity(identity);
2682 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002683 }
2684
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002685 /**
2686 * This method was removed due to potential issues caused by performing partial
2687 * updates of service state, and lack of a credible use case.
2688 *
2689 * This has the ability to break the telephony implementation by disabling notification of
2690 * changes in device connectivity. DO NOT USE THIS!
2691 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002692 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 public void enableLocationUpdates() {
2694 mApp.enforceCallingOrSelfPermission(
2695 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002698 /**
2699 * This method was removed due to potential issues caused by performing partial
2700 * updates of service state, and lack of a credible use case.
2701 *
2702 * This has the ability to break the telephony implementation by disabling notification of
2703 * changes in device connectivity. DO NOT USE THIS!
2704 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 @Override
2706 public void disableLocationUpdates() {
2707 mApp.enforceCallingOrSelfPermission(
2708 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002709 }
2710
2711 @Override
2712 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002713 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2714 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002715 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002716 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2717 throw new SecurityException(
2718 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2719 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002720
Jordan Liu1617b712019-07-10 15:06:26 -07002721 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2723 return null;
2724 }
Svetoslav64fad262015-04-14 14:35:21 -07002725
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002726 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002728 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002729 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730
Nathan Haroldf180aac2018-06-01 18:43:55 -07002731 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2732 for (CellInfo ci : info) {
2733 if (ci instanceof CellInfoGsm) {
2734 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2735 } else if (ci instanceof CellInfoWcdma) {
2736 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2737 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002738 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002739 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002740 }
2741
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002742 private List<CellInfo> getCachedCellInfo() {
2743 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2744 for (Phone phone : PhoneFactory.getPhones()) {
2745 List<CellInfo> info = phone.getAllCellInfo();
2746 if (info != null) cellInfos.addAll(info);
2747 }
2748 return cellInfos;
2749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750
2751 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002752 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002753 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002754 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002755
2756 LocationAccessPolicy.LocationPermissionResult locationResult =
2757 LocationAccessPolicy.checkLocationPermission(mApp,
2758 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2759 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002760 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002761 .setCallingPid(Binder.getCallingPid())
2762 .setCallingUid(Binder.getCallingUid())
2763 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002764 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002765 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2766 .build());
2767 switch (locationResult) {
2768 case DENIED_HARD:
2769 throw new SecurityException("Not allowed to access cell info");
2770 case DENIED_SOFT:
2771 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002772 }
2773
Nathan Haroldf096d982020-11-18 17:18:06 -08002774 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002775 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2776 return getCachedCellInfo();
2777 }
2778
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002779 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002781 final long identity = Binder.clearCallingIdentity();
2782 try {
2783 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2784 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002785 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002786 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 if (info != null) cellInfos.addAll(info);
2788 }
2789 return cellInfos;
2790 } finally {
2791 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002792 }
2793 }
2794
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002795 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002796 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2797 String callingFeatureId) {
2798 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2799 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002800 }
2801
2802 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002803 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2804 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002805 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002806 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002807 }
2808
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002809 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2810 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002811 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002812 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002813
2814 LocationAccessPolicy.LocationPermissionResult locationResult =
2815 LocationAccessPolicy.checkLocationPermission(mApp,
2816 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2817 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002818 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002819 .setCallingPid(Binder.getCallingPid())
2820 .setCallingUid(Binder.getCallingUid())
2821 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002822 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2823 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002824 .build());
2825 switch (locationResult) {
2826 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002827 if (TelephonyPermissions
2828 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002829 // Safetynet logging for b/154934934
2830 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2831 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002832 throw new SecurityException("Not allowed to access cell info");
2833 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002834 if (TelephonyPermissions
2835 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liud60acc92020-05-21 17:09:35 -07002836 // Safetynet logging for b/154934934
2837 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2838 }
Nathan Harold5320c422019-05-09 10:26:08 -07002839 try {
2840 cb.onCellInfo(new ArrayList<CellInfo>());
2841 } catch (RemoteException re) {
2842 // Drop without consequences
2843 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002844 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002845 }
2846
Nathan Harolda939a962019-05-09 10:13:47 -07002847
2848 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002849 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2850
2851 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2852 }
2853
2854 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002856 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002857 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002858
2859 final long identity = Binder.clearCallingIdentity();
2860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002861 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862 } finally {
2863 Binder.restoreCallingIdentity(identity);
2864 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002865 }
2866
Shishir Agrawala9f32182016-04-12 12:00:16 -07002867 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002868 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002869 Phone phone = PhoneFactory.getPhone(slotIndex);
2870 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002871 return null;
2872 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002873 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002874 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002875 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002876 return null;
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 return phone.getImei();
2882 } finally {
2883 Binder.restoreCallingIdentity(identity);
2884 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002885 }
2886
2887 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002888 public String getTypeAllocationCodeForSlot(int slotIndex) {
2889 Phone phone = PhoneFactory.getPhone(slotIndex);
2890 String tac = null;
2891 if (phone != null) {
2892 String imei = phone.getImei();
2893 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2894 }
2895 return tac;
2896 }
2897
2898 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002899 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002900 Phone phone = PhoneFactory.getPhone(slotIndex);
2901 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002902 return null;
2903 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002904
Jeff Davidson913390f2018-02-23 17:11:49 -08002905 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002906 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002907 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002908 return null;
2909 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910
2911 final long identity = Binder.clearCallingIdentity();
2912 try {
2913 return phone.getMeid();
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
2916 }
Jack Yu2af8d712017-03-15 17:14:14 -07002917 }
2918
2919 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002920 public String getManufacturerCodeForSlot(int slotIndex) {
2921 Phone phone = PhoneFactory.getPhone(slotIndex);
2922 String manufacturerCode = null;
2923 if (phone != null) {
2924 String meid = phone.getMeid();
2925 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2926 }
2927 return manufacturerCode;
2928 }
2929
2930 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002931 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2932 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002933 Phone phone = PhoneFactory.getPhone(slotIndex);
2934 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002935 return null;
2936 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002937 int subId = phone.getSubId();
2938 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002939 mApp, subId, callingPackage, callingFeatureId,
2940 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002941 return null;
2942 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002943
2944 final long identity = Binder.clearCallingIdentity();
2945 try {
2946 return phone.getDeviceSvn();
2947 } finally {
2948 Binder.restoreCallingIdentity(identity);
2949 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002950 }
2951
fionaxu43304da2017-11-27 22:51:16 -08002952 @Override
2953 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 final long identity = Binder.clearCallingIdentity();
2955 try {
2956 final Phone phone = getPhone(subId);
2957 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2958 } finally {
2959 Binder.restoreCallingIdentity(identity);
2960 }
fionaxu43304da2017-11-27 22:51:16 -08002961 }
2962
2963 @Override
2964 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 final Phone phone = getPhone(subId);
2968 return phone == null ? null : phone.getCarrierName();
2969 } finally {
2970 Binder.restoreCallingIdentity(identity);
2971 }
fionaxu43304da2017-11-27 22:51:16 -08002972 }
2973
calvinpanffe225e2018-11-01 19:43:06 +08002974 @Override
chen xu0026ca62019-03-06 15:28:50 -08002975 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002976 final long identity = Binder.clearCallingIdentity();
2977 try {
2978 final Phone phone = getPhone(subId);
2979 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002980 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
2983 }
2984 }
2985
2986 @Override
chen xu0026ca62019-03-06 15:28:50 -08002987 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002988 final long identity = Binder.clearCallingIdentity();
2989 try {
2990 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002991 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002992 } finally {
2993 Binder.restoreCallingIdentity(identity);
2994 }
2995 }
2996
chen xu651eec72018-11-11 19:03:44 -08002997 @Override
chen xu864e11c2018-12-06 22:10:03 -08002998 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2999 if (!isSubscriptionMccMnc) {
3000 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3001 }
chen xu651eec72018-11-11 19:03:44 -08003002 final Phone phone = PhoneFactory.getPhone(slotIndex);
3003 if (phone == null) {
3004 return TelephonyManager.UNKNOWN_CARRIER_ID;
3005 }
3006 final long identity = Binder.clearCallingIdentity();
3007 try {
3008 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
3012 }
3013
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003014 //
3015 // Internal helper methods.
3016 //
3017
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003018 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003019 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3020 *
3021 * @throws SecurityException if the caller does not have the required permission
3022 */
3023 private void enforceModifyPermission() {
3024 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3025 }
3026
Shuo Qiancd19c462020-01-16 20:51:11 -08003027 /**
3028 * Make sure the caller is system.
3029 *
3030 * @throws SecurityException if the caller is not system.
3031 */
3032 private void enforceSystemCaller() {
3033 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3034 throw new SecurityException("Caller must be system");
3035 }
3036 }
3037
Shuo Qian3b6ee772019-11-13 17:43:31 -08003038 private void enforceActiveEmergencySessionPermission() {
3039 mApp.enforceCallingOrSelfPermission(
3040 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3041 }
3042
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003043 /**
3044 * Make sure the caller has the CALL_PHONE permission.
3045 *
3046 * @throws SecurityException if the caller does not have the required permission
3047 */
3048 private void enforceCallPermission() {
3049 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3050 }
3051
paulhu5a773602019-08-23 19:17:33 +08003052 private void enforceSettingsPermission() {
3053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003054 }
3055
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003056 private String createTelUrl(String number) {
3057 if (TextUtils.isEmpty(number)) {
3058 return null;
3059 }
3060
Jake Hambye994d462014-02-03 13:10:13 -08003061 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003062 }
3063
Ihab Awadf9e92732013-12-05 18:02:52 -08003064 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003065 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3066 }
3067
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003068 private static void logv(String msg) {
3069 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3070 }
3071
Ihab Awadf9e92732013-12-05 18:02:52 -08003072 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003073 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3074 }
3075
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003076 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003078 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003079 }
3080
Sanket Padawe356d7632015-06-22 14:03:32 -07003081 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003082 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083 final long identity = Binder.clearCallingIdentity();
3084 try {
3085 final Phone phone = PhoneFactory.getPhone(slotIndex);
3086 if (phone == null) {
3087 return PhoneConstants.PHONE_TYPE_NONE;
3088 } else {
3089 return phone.getPhoneType();
3090 }
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003093 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003094 }
3095
3096 /**
3097 * Returns the CDMA ERI icon index to display
3098 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003099 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003100 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3101 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3102 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003103 }
3104
Sanket Padawe356d7632015-06-22 14:03:32 -07003105 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003106 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3107 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003109 mApp, subId, callingPackage, callingFeatureId,
3110 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003111 return -1;
3112 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003113
3114 final long identity = Binder.clearCallingIdentity();
3115 try {
3116 final Phone phone = getPhone(subId);
3117 if (phone != null) {
3118 return phone.getCdmaEriIconIndex();
3119 } else {
3120 return -1;
3121 }
3122 } finally {
3123 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003124 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003125 }
3126
3127 /**
3128 * Returns the CDMA ERI icon mode,
3129 * 0 - ON
3130 * 1 - FLASHING
3131 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003132 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003133 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3134 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3135 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003136 }
3137
Sanket Padawe356d7632015-06-22 14:03:32 -07003138 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003139 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3140 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003141 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003142 mApp, subId, callingPackage, callingFeatureId,
3143 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003144 return -1;
3145 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146
3147 final long identity = Binder.clearCallingIdentity();
3148 try {
3149 final Phone phone = getPhone(subId);
3150 if (phone != null) {
3151 return phone.getCdmaEriIconMode();
3152 } else {
3153 return -1;
3154 }
3155 } finally {
3156 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003157 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003158 }
3159
3160 /**
3161 * Returns the CDMA ERI text,
3162 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003163 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003164 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3165 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3166 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003167 }
3168
Sanket Padawe356d7632015-06-22 14:03:32 -07003169 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003170 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3171 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003172 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003173 mApp, subId, callingPackage, callingFeatureId,
3174 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003175 return null;
3176 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003177
3178 final long identity = Binder.clearCallingIdentity();
3179 try {
3180 final Phone phone = getPhone(subId);
3181 if (phone != null) {
3182 return phone.getCdmaEriText();
3183 } else {
3184 return null;
3185 }
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
3191 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003192 * Returns the CDMA MDN.
3193 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003194 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003195 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003196 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3197 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003198
3199 final long identity = Binder.clearCallingIdentity();
3200 try {
3201 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003202 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003203 return phone.getLine1Number();
3204 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003205 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 return null;
3207 }
3208 } finally {
3209 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003210 }
3211 }
3212
3213 /**
3214 * Returns the CDMA MIN.
3215 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003216 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003217 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3219 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220
3221 final long identity = Binder.clearCallingIdentity();
3222 try {
3223 final Phone phone = getPhone(subId);
3224 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3225 return phone.getCdmaMin();
3226 } else {
3227 return null;
3228 }
3229 } finally {
3230 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003231 }
3232 }
3233
Hall Liud892bec2018-11-30 14:51:45 -08003234 @Override
3235 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3236 INumberVerificationCallback callback, String callingPackage) {
3237 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3238 != PERMISSION_GRANTED) {
3239 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3240 }
3241 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3242
3243 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3244 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3245 throw new SecurityException("Calling package must be configured in the device config");
3246 }
3247
3248 if (range == null) {
3249 throw new NullPointerException("Range must be non-null");
3250 }
3251
3252 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003253 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003254
3255 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3256 }
3257
Junda Liuca05d5d2014-08-14 22:36:34 -07003258 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003259 * Returns true if CDMA provisioning needs to run.
3260 */
3261 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003262 final long identity = Binder.clearCallingIdentity();
3263 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003264 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003268 }
3269
3270 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003271 * Sets the voice mail number of a given subId.
3272 */
3273 @Override
3274 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003275 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3276 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003277
3278 final long identity = Binder.clearCallingIdentity();
3279 try {
3280 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3281 new Pair<String, String>(alphaTag, number), new Integer(subId));
3282 return success;
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
3285 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003286 }
3287
Ta-wei Yen87c49842016-05-13 21:19:52 -07003288 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003289 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3290 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003291 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3292 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003293 if (!TextUtils.equals(callingPackage, systemDialer)) {
3294 throw new SecurityException("caller must be system dialer");
3295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003296
3297 final long identity = Binder.clearCallingIdentity();
3298 try {
3299 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3300 if (phoneAccountHandle == null) {
3301 return null;
3302 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003303 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304 } finally {
3305 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003306 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003307 }
3308
3309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003310 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3311 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003312 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003314 mApp, subId, callingPackage, callingFeatureId,
3315 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003316 return null;
3317 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003318
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003319 final long identity = Binder.clearCallingIdentity();
3320 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003325 }
3326
3327 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003328 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3329 VisualVoicemailSmsFilterSettings settings) {
3330 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331
3332 final long identity = Binder.clearCallingIdentity();
3333 try {
3334 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003335 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003336 } finally {
3337 Binder.restoreCallingIdentity(identity);
3338 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003339 }
3340
3341 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003342 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3343 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003352 }
3353
3354 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003355 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3356 String callingPackage, int subId) {
3357 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003358
3359 final long identity = Binder.clearCallingIdentity();
3360 try {
3361 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003362 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363 } finally {
3364 Binder.restoreCallingIdentity(identity);
3365 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003366 }
3367
3368 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003369 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003370 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003371
3372 final long identity = Binder.clearCallingIdentity();
3373 try {
3374 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003375 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003376 } finally {
3377 Binder.restoreCallingIdentity(identity);
3378 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003379 }
3380
3381 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003382 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3383 String callingAttributionTag, int subId, String number, int port, String text,
3384 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003385 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003386 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003387 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003388 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003389 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3390 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003391 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003392
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003393 /**
fionaxu0152e512016-11-14 13:36:14 -08003394 * Sets the voice activation state of a given subId.
3395 */
3396 @Override
3397 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3399 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003400
3401 final long identity = Binder.clearCallingIdentity();
3402 try {
3403 final Phone phone = getPhone(subId);
3404 if (phone != null) {
3405 phone.setVoiceActivationState(activationState);
3406 } else {
3407 loge("setVoiceActivationState fails with invalid subId: " + subId);
3408 }
3409 } finally {
3410 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003411 }
3412 }
3413
3414 /**
3415 * Sets the data activation state of a given subId.
3416 */
3417 @Override
3418 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3420 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003421
3422 final long identity = Binder.clearCallingIdentity();
3423 try {
3424 final Phone phone = getPhone(subId);
3425 if (phone != null) {
3426 phone.setDataActivationState(activationState);
3427 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003428 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 }
3430 } finally {
3431 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003432 }
3433 }
3434
3435 /**
3436 * Returns the voice activation state of a given subId.
3437 */
3438 @Override
3439 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003440 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003441
fionaxu0152e512016-11-14 13:36:14 -08003442 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003443 final long identity = Binder.clearCallingIdentity();
3444 try {
3445 if (phone != null) {
3446 return phone.getVoiceActivationState();
3447 } else {
3448 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3449 }
3450 } finally {
3451 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003452 }
3453 }
3454
3455 /**
3456 * Returns the data activation state of a given subId.
3457 */
3458 @Override
3459 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
fionaxu0152e512016-11-14 13:36:14 -08003462 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003463 final long identity = Binder.clearCallingIdentity();
3464 try {
3465 if (phone != null) {
3466 return phone.getDataActivationState();
3467 } else {
3468 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3469 }
3470 } finally {
3471 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003472 }
3473 }
3474
3475 /**
Wink Saville36469e72014-06-11 15:17:00 -07003476 * Returns the unread count of voicemails for a subId
3477 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003478 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003479 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3480 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003481 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003482 mApp, subId, callingPackage, callingFeatureId,
3483 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003484 return 0;
3485 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486 final long identity = Binder.clearCallingIdentity();
3487 try {
3488 final Phone phone = getPhone(subId);
3489 if (phone != null) {
3490 return phone.getVoiceMessageCount();
3491 } else {
3492 return 0;
3493 }
3494 } finally {
3495 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003496 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003497 }
3498
3499 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003500 * returns true, if the device is in a state where both voice and data
3501 * are supported simultaneously. This can change based on location or network condition.
3502 */
3503 @Override
3504 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 final long identity = Binder.clearCallingIdentity();
3506 try {
3507 final Phone phone = getPhone(subId);
3508 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3509 } finally {
3510 Binder.restoreCallingIdentity(identity);
3511 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003512 }
3513
3514 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003515 * Send the dialer code if called from the current default dialer or the caller has
3516 * carrier privilege.
3517 * @param inputCode The dialer code to send
3518 */
3519 @Override
3520 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003522 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003523 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3524 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003525 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003526 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003532 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533 } finally {
3534 Binder.restoreCallingIdentity(identity);
3535 }
fionaxu235cc5e2017-03-06 22:25:57 -08003536 }
3537
Pengquan Menga1bb6272018-09-06 09:59:22 -07003538 @Override
3539 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003540 TelephonyPermissions
3541 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3542 mApp, subId, "getNetworkSelectionMode");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 if (!isActiveSubscription(subId)) {
3546 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3547 }
3548 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3549 } finally {
3550 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003552 }
3553
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003555 public boolean isInEmergencySmsMode() {
3556 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 for (Phone phone : PhoneFactory.getPhones()) {
3560 if (phone.isInEmergencySmsMode()) {
3561 return true;
3562 }
3563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
3566 }
3567 return false;
3568 }
3569
shilu366312e2019-12-17 09:28:10 -08003570 /**
3571 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3572 * @param subId The subscription to use to check the configuration.
3573 * @param c The callback that will be used to send the result.
3574 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003575 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003576 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3577 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003578 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3579 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003580
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003581 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3582 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3583 "IMS not available on device.");
3584 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003585 final long token = Binder.clearCallingIdentity();
3586 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003587 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003590 } catch (ImsException e) {
3591 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 } finally {
3593 Binder.restoreCallingIdentity(token);
3594 }
3595 }
3596
shilu366312e2019-12-17 09:28:10 -08003597 /**
3598 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3599 * @param subId The subscription to use to check the configuration.
3600 * @param c The callback that will be used to send the result.
3601 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003603 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003604 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3605 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003606 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3607 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3608 }
Meng Wangafbc5852019-09-19 17:37:13 -07003609 final long token = Binder.clearCallingIdentity();
3610 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003611 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003612 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3613 .removeRegistrationCallbackForSubscription(c, subId);
3614 } catch (ImsException e) {
3615 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3616 + "is inactive, ignoring unregister.");
3617 // If the subscription is no longer active, just return, since the callback
3618 // will already have been removed internally.
3619 } finally {
3620 Binder.restoreCallingIdentity(token);
3621 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 }
3623
Brad Ebingera34a6c22019-10-22 17:36:18 -07003624 /**
3625 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3626 */
3627 @Override
3628 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3629 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3630 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3631 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3632 "IMS not available on device.");
3633 }
3634 final long token = Binder.clearCallingIdentity();
3635 try {
3636 Phone phone = getPhone(subId);
3637 if (phone == null) {
3638 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3639 + subId + "'");
3640 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3641 }
3642 phone.getImsRegistrationState(regState -> {
3643 try {
3644 consumer.accept((regState == null)
3645 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3646 } catch (RemoteException e) {
3647 // Ignore if the remote process is no longer available to call back.
3648 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3649 }
3650 });
3651 } finally {
3652 Binder.restoreCallingIdentity(token);
3653 }
3654 }
3655
3656 /**
3657 * Get the transport type for the IMS service registration state.
3658 */
3659 @Override
3660 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003661 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3662 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003663 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3665 "IMS not available on device.");
3666 }
3667 final long token = Binder.clearCallingIdentity();
3668 try {
3669 Phone phone = getPhone(subId);
3670 if (phone == null) {
3671 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3672 + subId + "'");
3673 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3674 }
3675 phone.getImsRegistrationTech(regTech -> {
3676 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3677 int regTechConverted = (regTech == null)
3678 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3679 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3680 regTechConverted);
3681 try {
3682 consumer.accept(regTechConverted);
3683 } catch (RemoteException e) {
3684 // Ignore if the remote process is no longer available to call back.
3685 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3686 }
3687 });
3688 } finally {
3689 Binder.restoreCallingIdentity(token);
3690 }
3691 }
3692
shilu366312e2019-12-17 09:28:10 -08003693 /**
3694 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3695 * @param subId The subscription to use to check the configuration.
3696 * @param c The callback that will be used to send the result.
3697 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003699 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3700 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003701 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3702 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003703 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3704 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3705 "IMS not available on device.");
3706 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3708 final long token = Binder.clearCallingIdentity();
3709 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003710 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003712 } catch (ImsException e) {
3713 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 } finally {
3715 Binder.restoreCallingIdentity(token);
3716 }
3717 }
3718
shilu366312e2019-12-17 09:28:10 -08003719 /**
3720 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3721 * @param subId The subscription to use to check the configuration.
3722 * @param c The callback that will be used to send the result.
3723 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003725 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003726 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3727 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003728 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3729 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3730 }
Meng Wangafbc5852019-09-19 17:37:13 -07003731
3732 final long token = Binder.clearCallingIdentity();
3733 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003734 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003735 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003736 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003737 } catch (ImsException e) {
3738 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3739 + "is inactive, ignoring unregister.");
3740 // If the subscription is no longer active, just return, since the callback
3741 // will already have been removed internally.
3742 } finally {
3743 Binder.restoreCallingIdentity(token);
3744 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 }
3746
3747 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003748 public boolean isCapable(int subId, int capability, int regTech) {
3749 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3751 final long token = Binder.clearCallingIdentity();
3752 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003753 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3757 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003758 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003759 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3760 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 } finally {
3762 Binder.restoreCallingIdentity(token);
3763 }
3764 }
3765
3766 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003767 public boolean isAvailable(int subId, int capability, int regTech) {
3768 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 final long token = Binder.clearCallingIdentity();
3770 try {
3771 Phone phone = getPhone(subId);
3772 if (phone == null) return false;
3773 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003774 } catch (com.android.ims.ImsException e) {
3775 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3776 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003777 } finally {
3778 Binder.restoreCallingIdentity(token);
3779 }
3780 }
3781
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003782 /**
3783 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3784 * subscription.
3785 * @param subId The subscription to use to check the configuration.
3786 * @param callback The callback that will be used to send the result.
3787 * @param capability The MmTelFeature capability that will be used to send the result.
3788 * @param transportType The transport type of the MmTelFeature capability.
3789 */
3790 @Override
3791 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3792 int transportType) {
3793 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3794 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3795 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3796 "IMS not available on device.");
3797 }
3798 final long token = Binder.clearCallingIdentity();
3799 try {
3800 int slotId = getSlotIndex(subId);
3801 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3802 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3803 + subId + "'");
3804 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3805 }
3806 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3807 transportType, aBoolean -> {
3808 try {
3809 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3810 } catch (RemoteException e) {
3811 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3812 + "running. Ignore");
3813 }
3814 });
3815 } finally {
3816 Binder.restoreCallingIdentity(token);
3817 }
3818 }
3819
shilu366312e2019-12-17 09:28:10 -08003820 /**
3821 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3822 * @param subId The subscription to use to check the configuration.
3823 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003824 @Override
3825 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003826 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3827 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003828
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3830 final long token = Binder.clearCallingIdentity();
3831 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003832 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003834 } catch (ImsException e) {
3835 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 } finally {
3837 Binder.restoreCallingIdentity(token);
3838 }
3839 }
3840
3841 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003842 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003844 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 final long identity = Binder.clearCallingIdentity();
3846 try {
3847 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003848 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003850 } catch (ImsException e) {
3851 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 } finally {
3853 Binder.restoreCallingIdentity(identity);
3854 }
3855 }
3856
shilu366312e2019-12-17 09:28:10 -08003857 /**
3858 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3859 * @param subId The subscription to use to check the configuration.
3860 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003861 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003862 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003863 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3864 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 final long identity = Binder.clearCallingIdentity();
3866 try {
3867 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003868 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3869 } catch (ImsException e) {
3870 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874 }
3875
3876 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003877 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003879 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 final long identity = Binder.clearCallingIdentity();
3881 try {
3882 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003884 } catch (ImsException e) {
3885 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 } finally {
3887 Binder.restoreCallingIdentity(identity);
3888 }
3889 }
3890
shilu366312e2019-12-17 09:28:10 -08003891 /**
3892 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3893 * @param subId The subscription to use to check the configuration.
3894 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 @Override
3896 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003897 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3898 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 final long identity = Binder.clearCallingIdentity();
3900 try {
3901 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003902 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003904 } catch (ImsException e) {
3905 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 } finally {
3907 Binder.restoreCallingIdentity(identity);
3908 }
3909 }
3910
3911 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003912 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003913 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003914 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 final long identity = Binder.clearCallingIdentity();
3916 try {
3917 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003918 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003919 } catch (ImsException e) {
3920 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003921 } finally {
3922 Binder.restoreCallingIdentity(identity);
3923 }
3924 }
3925
shilu366312e2019-12-17 09:28:10 -08003926 /**
Sooraj Sasindrane655add2020-11-23 19:40:38 -08003927 * @return true if the user's setting for Voice over Cross SIM is enabled and false if it is not
3928 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3929 * @param subId The subscription to use to check the configuration.
3930 */
3931 @Override
3932 public boolean isCrossSimCallingEnabledByUser(int subId) {
3933 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3934 mApp, subId, "isCrossSimCallingEnabledByUser");
3935 final long identity = Binder.clearCallingIdentity();
3936 try {
3937 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3938 return ImsManager.getInstance(mApp,
3939 getSlotIndexOrException(subId)).isCrossSimCallingEnabledByUser();
3940 } catch (ImsException e) {
3941 throw new ServiceSpecificException(e.getCode());
3942 } finally {
3943 Binder.restoreCallingIdentity(identity);
3944 }
3945 }
3946
3947 /**
3948 * Sets the user's setting for whether or not Voice over Cross SIM is enabled.
3949 * Requires MODIFY_PHONE_STATE permission.
3950 * @param subId The subscription to use to check the configuration.
3951 * @param isEnabled true if the user's setting for Voice over Cross SIM is enabled,
3952 * false otherwise
3953 */
3954 @Override
3955 public void setCrossSimCallingEnabled(int subId, boolean isEnabled) {
3956 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3957 "setCrossSimCallingEnabled");
3958 final long identity = Binder.clearCallingIdentity();
3959 try {
3960 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3961 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3962 .setCrossSimCallingEnabled(isEnabled);
3963 } catch (ImsException e) {
3964 throw new ServiceSpecificException(e.getCode());
3965 } finally {
3966 Binder.restoreCallingIdentity(identity);
3967 }
3968 }
3969
3970 /**
shilu366312e2019-12-17 09:28:10 -08003971 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3972 * @param subId The subscription to use to check the configuration.
3973 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 @Override
3975 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003976 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3977 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 final long identity = Binder.clearCallingIdentity();
3979 try {
3980 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003981 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003983 } catch (ImsException e) {
3984 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 } finally {
3986 Binder.restoreCallingIdentity(identity);
3987 }
3988 }
3989
3990 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003991 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003993 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003997 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003998 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003999 } catch (ImsException e) {
4000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 }
4005
4006 @Override
4007 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4009 "setVoWiFiNonPersistent");
4010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004014 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004015 } catch (ImsException e) {
4016 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004017 } finally {
4018 Binder.restoreCallingIdentity(identity);
4019 }
4020 }
4021
shilu366312e2019-12-17 09:28:10 -08004022 /**
4023 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4024 * @param subId The subscription to use to check the configuration.
4025 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 @Override
4027 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004028 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4029 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004030 final long identity = Binder.clearCallingIdentity();
4031 try {
4032 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004033 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004035 } catch (ImsException e) {
4036 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 } finally {
4038 Binder.restoreCallingIdentity(identity);
4039 }
4040 }
4041
4042 @Override
4043 public void setVoWiFiModeSetting(int subId, int mode) {
4044 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4045 "setVoWiFiModeSetting");
4046 final long identity = Binder.clearCallingIdentity();
4047 try {
4048 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004049 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004051 } catch (ImsException e) {
4052 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004053 } finally {
4054 Binder.restoreCallingIdentity(identity);
4055 }
4056 }
4057
4058 @Override
4059 public int getVoWiFiRoamingModeSetting(int subId) {
4060 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4061 final long identity = Binder.clearCallingIdentity();
4062 try {
4063 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004064 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004065 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004066 } catch (ImsException e) {
4067 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 } finally {
4069 Binder.restoreCallingIdentity(identity);
4070 }
4071 }
4072
4073 @Override
4074 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4076 "setVoWiFiRoamingModeSetting");
4077 final long identity = Binder.clearCallingIdentity();
4078 try {
4079 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004080 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004081 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004082 } catch (ImsException e) {
4083 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 } finally {
4085 Binder.restoreCallingIdentity(identity);
4086 }
4087 }
4088
4089 @Override
4090 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4092 "setRttCapabilityEnabled");
4093 final long identity = Binder.clearCallingIdentity();
4094 try {
4095 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4097 } catch (ImsException e) {
4098 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004099 } finally {
4100 Binder.restoreCallingIdentity(identity);
4101 }
4102 }
4103
shilu366312e2019-12-17 09:28:10 -08004104 /**
4105 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4106 * @param subId The subscription to use to check the configuration.
4107 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004108 @Override
4109 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004110 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4111 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 final long identity = Binder.clearCallingIdentity();
4113 try {
4114 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004115 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004117 } catch (ImsException e) {
4118 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004124 @Override
4125 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4126 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4127 final long identity = Binder.clearCallingIdentity();
4128 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08004129 if (!isImsAvailableOnDevice()) {
4130 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4131 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08004132 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004135 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
4137 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
4144 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4145 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4146 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004147 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4148 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4149 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004150 try {
4151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004152 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004153 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004154 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004155 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4156 + "is inactive, ignoring unregister.");
4157 // If the subscription is no longer active, just return, since the callback will already
4158 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004159 } finally {
4160 Binder.restoreCallingIdentity(identity);
4161 }
4162 }
4163
allenwtsu99c623b2020-01-03 18:24:23 +08004164
4165 private void checkModifyPhoneStatePermission(int subId, String message) {
4166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4167 message);
4168 }
4169
4170 private boolean isImsProvisioningRequired(int subId, int capability,
4171 boolean isMmtelCapability) {
4172 Phone phone = getPhone(subId);
4173 if (phone == null) {
4174 loge("phone instance null for subid " + subId);
4175 return false;
4176 }
4177 if (isMmtelCapability) {
4178 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4179 return false;
4180 }
4181 } else {
4182 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4183 return false;
4184 }
4185 }
4186 return true;
4187 }
4188
4189 @Override
4190 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4191 boolean isProvisioned) {
4192 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4193
4194 final long identity = Binder.clearCallingIdentity();
4195 try {
4196 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4197 if (!isImsProvisioningRequired(subId, capability, false)) {
4198 return;
4199 }
4200
4201 // this capability requires provisioning, route to the correct API.
4202 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4203 switch (capability) {
4204 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4205 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4206 ims.setEabProvisioned(isProvisioned);
4207 break;
4208 default: {
4209 throw new IllegalArgumentException("Tried to set provisioning for "
4210 + "rcs capability '" + capability + "', which does not require "
4211 + "provisioning.");
4212 }
4213 }
4214 } finally {
4215 Binder.restoreCallingIdentity(identity);
4216 }
4217
4218 }
4219
4220
4221 @Override
4222 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4223 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4224 final long identity = Binder.clearCallingIdentity();
4225 try {
4226 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4227 if (!isImsProvisioningRequired(subId, capability, false)) {
4228 return true;
4229 }
4230
4231 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4232 switch (capability) {
4233 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4234 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4235 return ims.isEabProvisionedOnDevice();
4236
4237 default: {
4238 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4239 + "capability '" + capability + "', which does not require "
4240 + "provisioning.");
4241 }
4242 }
4243
4244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004249 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004250 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4251 boolean isProvisioned) {
4252 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4253 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4254 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4255 }
allenwtsu99c623b2020-01-03 18:24:23 +08004256 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004260 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004261 return;
4262 }
4263
4264 // this capability requires provisioning, route to the correct API.
4265 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4266 switch (capability) {
4267 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4268 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4269 ims.setVolteProvisioned(isProvisioned);
4270 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4271 ims.setWfcProvisioned(isProvisioned);
4272 }
4273 break;
4274 }
4275 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4276 // There is currently no difference in VT provisioning type.
4277 ims.setVtProvisioned(isProvisioned);
4278 break;
4279 }
4280 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4281 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4282 // change the capability of the feature instead if needed.
4283 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4284 == isProvisioned) {
4285 // No change in provisioning.
4286 return;
4287 }
4288 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4289 try {
4290 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004291 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004292 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4293 + ", Exception" + e.getMessage());
4294 }
4295 break;
4296 }
4297 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004298 throw new IllegalArgumentException("Tried to set provisioning for "
4299 + "MmTel capability '" + capability + "', which does not require "
4300 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004301 }
4302 }
4303
4304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307 }
4308
4309 @Override
4310 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4311 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4312 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4313 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4314 }
4315 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004319 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004320 return true;
4321 }
4322
4323 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4324 switch (capability) {
4325 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4326 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4327 return ims.isVolteProvisionedOnDevice();
4328 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4329 return ims.isWfcProvisionedOnDevice();
4330 }
4331 // This should never happen, since we are checking tech above to make sure it
4332 // is either LTE or IWLAN.
4333 throw new IllegalArgumentException("Invalid radio technology for voice "
4334 + "capability.");
4335 }
4336 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4337 // There is currently no difference in VT provisioning type.
4338 return ims.isVtProvisionedOnDevice();
4339 }
4340 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4341 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4342 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4343 }
4344 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004345 throw new IllegalArgumentException(
4346 "Tried to get provisioning for MmTel capability '" + capability
4347 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004348 }
4349 }
4350
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
4353 }
4354 }
4355
4356 @Override
4357 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4358 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4359 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4360 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4361 }
4362 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4363 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4364 return (provisionedBits & capability) > 0;
4365 }
4366
4367 @Override
4368 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4369 boolean isProvisioned) {
4370 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4371 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4372 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4373 }
4374 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4375 "setProvisioningStatusForCapability");
4376 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4377 // If the current provisioning status for capability already matches isProvisioned,
4378 // do nothing.
4379 if (((provisionedBits & capability) > 0) == isProvisioned) {
4380 return;
4381 }
4382 if (isProvisioned) {
4383 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4384 } else {
4385 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4386 }
4387 }
4388
4389 /**
4390 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4391 * technology. The bitfield should mirror the bitfield defined by
4392 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4393 */
4394 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4395 String key = getMmTelProvisioningKey(subId, tech);
4396 // Default is no capabilities are provisioned.
4397 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4398 }
4399
4400 /**
4401 * Sets the MmTel capability provisioning bitfield (defined by
4402 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4403 * technology specified.
4404 *
4405 * Note: This is a synchronous command and should not be called on UI thread.
4406 */
4407 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4408 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4409 String key = getMmTelProvisioningKey(subId, tech);
4410 editor.putInt(key, newField);
4411 editor.commit();
4412 }
4413
4414 private static String getMmTelProvisioningKey(int subId, int tech) {
4415 // resulting key is provision_ims_mmtel_{subId}_{tech}
4416 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4417 }
4418
4419 /**
4420 * Query CarrierConfig to see if the specified capability requires provisioning for the
4421 * carrier associated with the subscription id.
4422 */
4423 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4424 int capability) {
4425 CarrierConfigManager configManager = new CarrierConfigManager(context);
4426 PersistableBundle c = configManager.getConfigForSubId(subId);
4427 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004428 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004429 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4430 false);
4431 boolean requireVoiceVtProvisioning = c.getBoolean(
4432 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4433
4434 // First check to make sure that the capability requires provisioning.
4435 switch (capability) {
4436 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4437 // intentional fallthrough
4438 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4439 if (requireVoiceVtProvisioning) {
4440 // Voice and Video requires provisioning
4441 return true;
4442 }
4443 break;
4444 }
4445 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4446 if (requireUtProvisioning) {
4447 // UT requires provisioning
4448 return true;
4449 }
4450 break;
4451 }
4452 }
4453 return false;
4454 }
4455
allenwtsu99c623b2020-01-03 18:24:23 +08004456 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4457 int capability) {
4458 CarrierConfigManager configManager = new CarrierConfigManager(context);
4459 PersistableBundle c = configManager.getConfigForSubId(subId);
4460
4461 boolean requireRcsProvisioning = c.getBoolean(
4462 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4463
4464 // First check to make sure that the capability requires provisioning.
4465 switch (capability) {
4466 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4467 // intentional fallthrough
4468 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4469 if (requireRcsProvisioning) {
4470 // OPTION or PRESENCE requires provisioning
4471 return true;
4472 }
4473 break;
4474 }
4475 }
4476 return false;
4477 }
4478
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004479 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004480 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004481 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4482 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4483 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004484 enforceReadPrivilegedPermission("getImsProvisioningInt");
4485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004488 int slotId = getSlotIndex(subId);
4489 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4490 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4491 + subId + "' for key:" + key);
4492 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4493 }
4494 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004495 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004496 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4497 + subId + "' for key:" + key);
4498 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004499 } finally {
4500 Binder.restoreCallingIdentity(identity);
4501 }
4502 }
4503
4504 @Override
4505 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004506 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4507 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4508 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004509 enforceReadPrivilegedPermission("getImsProvisioningString");
4510 final long identity = Binder.clearCallingIdentity();
4511 try {
4512 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 int slotId = getSlotIndex(subId);
4514 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4515 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4516 + subId + "' for key:" + key);
4517 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4518 }
4519 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004520 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4522 + subId + "' for key:" + key);
4523 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004524 } finally {
4525 Binder.restoreCallingIdentity(identity);
4526 }
4527 }
4528
4529 @Override
4530 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4532 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4533 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4535 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 final long identity = Binder.clearCallingIdentity();
4537 try {
4538 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004539 int slotId = getSlotIndex(subId);
4540 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4541 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4542 + subId + "' for key:" + key);
4543 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4544 }
4545 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004546 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004547 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4548 + "' for key:" + key);
4549 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004550 } finally {
4551 Binder.restoreCallingIdentity(identity);
4552 }
4553 }
4554
4555 @Override
4556 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004557 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4558 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4559 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4561 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004562 final long identity = Binder.clearCallingIdentity();
4563 try {
4564 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 int slotId = getSlotIndex(subId);
4566 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4567 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4568 + subId + "' for key:" + key);
4569 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4570 }
4571 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004572 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4574 + "' for key:" + key);
4575 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004576 } finally {
4577 Binder.restoreCallingIdentity(identity);
4578 }
4579 }
4580
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004581 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004582 int slotId = SubscriptionManager.getSlotIndex(subId);
4583 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004584 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4585 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004586 }
4587 return slotId;
4588 }
4589
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 private int getSlotIndex(int subId) {
4591 int slotId = SubscriptionManager.getSlotIndex(subId);
4592 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4593 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4594 }
4595 return slotId;
4596 }
4597
Wink Saville36469e72014-06-11 15:17:00 -07004598 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004599 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004600 */
4601 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004602 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4603 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004604 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004605 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004606 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004607 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004608 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004609 mApp, subId, callingPackage, callingFeatureId,
4610 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004611 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4612 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004613
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004614 final long identity = Binder.clearCallingIdentity();
4615 try {
4616 final Phone phone = getPhone(subId);
4617 if (phone != null) {
4618 return phone.getServiceState().getDataNetworkType();
4619 } else {
4620 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4621 }
4622 } finally {
4623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004625 }
4626
4627 /**
4628 * Returns the data network type
4629 */
4630 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004631 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4632 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4633 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004634 }
4635
4636 /**
4637 * Returns the data network type for a subId
4638 */
4639 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004640 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4641 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004642 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004643 mApp, subId, callingPackage, callingFeatureId,
4644 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004645 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4646 }
4647
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 final Phone phone = getPhone(subId);
4651 if (phone != null) {
4652 return phone.getServiceState().getDataNetworkType();
4653 } else {
4654 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4655 }
4656 } finally {
4657 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004658 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004659 }
4660
4661 /**
Wink Saville36469e72014-06-11 15:17:00 -07004662 * Returns the Voice network type for a subId
4663 */
4664 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004665 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4666 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004667 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004668 mApp, subId, callingPackage, callingFeatureId,
4669 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004670 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4671 }
4672
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004673 final long identity = Binder.clearCallingIdentity();
4674 try {
4675 final Phone phone = getPhone(subId);
4676 if (phone != null) {
4677 return phone.getServiceState().getVoiceNetworkType();
4678 } else {
4679 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4680 }
4681 } finally {
4682 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004683 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004684 }
4685
4686 /**
4687 * @return true if a ICC card is present
4688 */
4689 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004690 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004691 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4692 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004693 }
4694
4695 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004696 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004697 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004698 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004699 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 final Phone phone = PhoneFactory.getPhone(slotIndex);
4703 if (phone != null) {
4704 return phone.getIccCard().hasIccCard();
4705 } else {
4706 return false;
4707 }
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004711 }
4712
4713 /**
4714 * Return if the current radio is LTE on CDMA. This
4715 * is a tri-state return value as for a period of time
4716 * the mode may be unknown.
4717 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004718 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004719 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004720 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004721 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004722 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004723 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4724 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4725 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004726 }
4727
Sanket Padawe356d7632015-06-22 14:03:32 -07004728 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004729 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4730 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004731 try {
4732 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4733 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004734 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4735 }
4736
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 final long identity = Binder.clearCallingIdentity();
4738 try {
4739 final Phone phone = getPhone(subId);
4740 if (phone == null) {
4741 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4742 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004743 return TelephonyProperties.lte_on_cdma_device()
4744 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004745 }
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004748 }
Wink Saville36469e72014-06-11 15:17:00 -07004749 }
4750
Wink Saville36469e72014-06-11 15:17:00 -07004751 /**
4752 * {@hide}
4753 * Returns Default subId, 0 in the case of single standby.
4754 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004755 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004756 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004757 }
4758
Shishir Agrawala9f32182016-04-12 12:00:16 -07004759 private int getSlotForDefaultSubscription() {
4760 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4761 }
4762
Wink Savilleb564aae2014-10-23 10:18:09 -07004763 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004764 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004765 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004766
Pengquan Menge92a50d2018-09-21 15:54:48 -07004767 private boolean isActiveSubscription(int subId) {
4768 return mSubscriptionController.isActiveSubId(subId);
4769 }
4770
Ihab Awadf2177b72013-11-25 13:33:23 -08004771 /**
4772 * @see android.telephony.TelephonyManager.WifiCallingChoices
4773 */
4774 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 final long identity = Binder.clearCallingIdentity();
4776 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004777 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4779 getWhenToMakeWifiCallsDefaultPreference());
4780 } finally {
4781 Binder.restoreCallingIdentity(identity);
4782 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004783 }
4784
4785 /**
4786 * @see android.telephony.TelephonyManager.WifiCallingChoices
4787 */
4788 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004792 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004793 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
4796 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004797 }
4798
Sailesh Nepald1e68152013-12-12 19:08:02 -08004799 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004800 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004801 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004802 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004803
Jordan Liu4c733742019-02-28 12:03:40 -08004804 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4805 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4806 if (phoneId == -1) {
4807 throw new IllegalArgumentException("Given slot index: " + slotIndex
4808 + " does not correspond to an active phone");
4809 }
4810 return PhoneFactory.getPhone(phoneId);
4811 }
4812
Shishir Agrawal566b7612013-10-28 14:41:00 -07004813 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004814 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4815 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004819 if (DBG) {
4820 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4821 }
4822 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4823 p2);
4824 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004825
Jordan Liu4c733742019-02-28 12:03:40 -08004826
4827 @Override
4828 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4829 int slotIndex, String callingPackage, String aid, int p2) {
4830 enforceModifyPermission();
4831 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4832 if (DBG) {
4833 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4834 }
4835 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4836 callingPackage, aid, p2);
4837 }
4838
4839 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4840 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004841 final long identity = Binder.clearCallingIdentity();
4842 try {
4843 if (TextUtils.equals(ISDR_AID, aid)) {
4844 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004845 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4846 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004847 if (bestComponent == null
4848 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4849 loge("The calling package is not allowed to access ISD-R.");
4850 throw new SecurityException(
4851 "The calling package is not allowed to access ISD-R.");
4852 }
Derek Tan740e1672017-06-27 14:56:27 -07004853 }
Derek Tan740e1672017-06-27 14:56:27 -07004854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004855 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004856 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4857 null /* workSource */);
4858 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 return response;
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004863 }
4864
4865 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004866 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4868 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004869 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4870 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4871 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004872
Jordan Liu4c733742019-02-28 12:03:40 -08004873 @Override
4874 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4875 enforceModifyPermission();
4876 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4877 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4878 channel);
4879 }
4880
4881 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004882 final long identity = Binder.clearCallingIdentity();
4883 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004884 if (channel < 0) {
4885 return false;
4886 }
Jordan Liu4c733742019-02-28 12:03:40 -08004887 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4888 null /* workSource */);
4889 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004890 return success;
4891 } finally {
4892 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004893 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004894 }
4895
4896 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004897 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004898 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4900 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004901 if (DBG) {
4902 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4903 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4904 + p3 + " data=" + data);
4905 }
4906 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4907 command, p1, p2, p3, data);
4908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004909
Jordan Liu4c733742019-02-28 12:03:40 -08004910 @Override
4911 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4912 int command, int p1, int p2, int p3, String data) {
4913 enforceModifyPermission();
4914 if (DBG) {
4915 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4916 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4917 + p3 + " data=" + data);
4918 }
4919 return iccTransmitApduLogicalChannelWithPermission(
4920 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4921 data);
4922 }
4923
4924 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4925 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004928 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 return "";
4930 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004931
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004933 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4934 null /* workSource */);
4935 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004936
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 // Append the returned status code to the end of the response payload.
4938 String s = Integer.toHexString(
4939 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4940 if (response.payload != null) {
4941 s = IccUtils.bytesToHexString(response.payload) + s;
4942 }
4943 return s;
4944 } finally {
4945 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004947 }
Jake Hambye994d462014-02-03 13:10:13 -08004948
Evan Charltonc66da362014-05-16 14:06:40 -07004949 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004950 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4951 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4953 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004954 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004955 if (DBG) {
4956 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4957 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4958 }
4959 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4960 cla, command, p1, p2, p3, data);
4961 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004962
Jordan Liu4c733742019-02-28 12:03:40 -08004963 @Override
4964 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4965 int command, int p1, int p2, int p3, String data) {
4966 enforceModifyPermission();
4967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4968 if (DBG) {
4969 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4970 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4971 + " data=" + data);
4972 }
4973
4974 return iccTransmitApduBasicChannelWithPermission(
4975 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4976 p2, p3, data);
4977 }
4978
4979 // open APDU basic channel assuming the caller has sufficient permissions
4980 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4981 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004982 final long identity = Binder.clearCallingIdentity();
4983 try {
4984 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4985 && TextUtils.equals(ISDR_AID, data)) {
4986 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004987 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4988 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 if (bestComponent == null
4990 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4991 loge("The calling package is not allowed to select ISD-R.");
4992 throw new SecurityException(
4993 "The calling package is not allowed to select ISD-R.");
4994 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004995 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004997 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004998 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4999 null /* workSource */);
5000 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005001
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 // Append the returned status code to the end of the response payload.
5003 String s = Integer.toHexString(
5004 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5005 if (response.payload != null) {
5006 s = IccUtils.bytesToHexString(response.payload) + s;
5007 }
5008 return s;
5009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005011 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005012 }
5013
5014 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005015 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005016 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5018 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005019
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 final long identity = Binder.clearCallingIdentity();
5021 try {
5022 if (DBG) {
5023 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5024 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5025 }
5026
5027 IccIoResult response =
5028 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5029 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5030 subId);
5031
5032 if (DBG) {
5033 log("Exchange SIM_IO [R]" + response);
5034 }
5035
5036 byte[] result = null;
5037 int length = 2;
5038 if (response.payload != null) {
5039 length = 2 + response.payload.length;
5040 result = new byte[length];
5041 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5042 } else {
5043 result = new byte[length];
5044 }
5045
5046 result[length - 1] = (byte) response.sw2;
5047 result[length - 2] = (byte) response.sw1;
5048 return result;
5049 } finally {
5050 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005051 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005052 }
5053
Nathan Haroldb3014052017-01-25 15:57:32 -08005054 /**
5055 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5056 * on a particular subscription
5057 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005058 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5059 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005061 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005062 return null;
5063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005064
5065 final long identity = Binder.clearCallingIdentity();
5066 try {
5067 if (appType != TelephonyManager.APPTYPE_USIM
5068 && appType != TelephonyManager.APPTYPE_SIM) {
5069 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5070 return null;
5071 }
5072 Object response = sendRequest(
5073 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5074 if (response instanceof String[]) {
5075 return (String[]) response;
5076 }
yincheng zhao2737e882019-09-06 17:06:54 -07005077 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005078 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005079 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005082 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005083 }
5084
yincheng zhao2737e882019-09-06 17:06:54 -07005085 /**
5086 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5087 * subscription.
5088 *
5089 * @param subId the id of the subscription.
5090 * @param appType the uicc app type, must be USIM or SIM.
5091 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5092 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005093 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07005094 * @return number of fplmns that is successfully written to the SIM.
5095 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005096 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5097 String callingFeatureId) {
5098 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5099 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07005100 if (DBG) logv("no permissions for setForbiddenplmns");
5101 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5102 }
5103 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5104 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5105 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5106 }
5107 if (fplmns == null) {
5108 throw new IllegalArgumentException("Fplmn List provided is null");
5109 }
5110 for (String fplmn : fplmns) {
5111 if (!CellIdentity.isValidPlmn(fplmn)) {
5112 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5113 }
5114 }
5115 final long identity = Binder.clearCallingIdentity();
5116 try {
5117 Object response = sendRequest(
5118 CMD_SET_FORBIDDEN_PLMNS,
5119 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5120 subId);
5121 return (int) response;
5122 } finally {
5123 Binder.restoreCallingIdentity(identity);
5124 }
5125 }
5126
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005127 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005128 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5130 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
5134 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5135 if (response.payload == null) {
5136 return "";
5137 }
Evan Charltonc66da362014-05-16 14:06:40 -07005138
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005139 // Append the returned status code to the end of the response payload.
5140 String s = Integer.toHexString(
5141 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5142 s = IccUtils.bytesToHexString(response.payload) + s;
5143 return s;
5144 } finally {
5145 Binder.restoreCallingIdentity(identity);
5146 }
Evan Charltonc66da362014-05-16 14:06:40 -07005147 }
5148
Jake Hambye994d462014-02-03 13:10:13 -08005149 /**
5150 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5151 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5152 *
5153 * @param itemID the ID of the item to read
5154 * @return the NV item as a String, or null on error.
5155 */
5156 @Override
5157 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5160 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005161
5162 final long identity = Binder.clearCallingIdentity();
5163 try {
5164 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005165 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5167 return value;
5168 } finally {
5169 Binder.restoreCallingIdentity(identity);
5170 }
Jake Hambye994d462014-02-03 13:10:13 -08005171 }
5172
5173 /**
5174 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5175 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5176 *
5177 * @param itemID the ID of the item to read
5178 * @param itemValue the value to write, as a String
5179 * @return true on success; false on any failure
5180 */
5181 @Override
5182 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005183 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005184 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5185 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186
5187 final long identity = Binder.clearCallingIdentity();
5188 try {
5189 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5190 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005191 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5193 return success;
5194 } finally {
5195 Binder.restoreCallingIdentity(identity);
5196 }
Jake Hambye994d462014-02-03 13:10:13 -08005197 }
5198
5199 /**
5200 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5201 * Used for device configuration by some CDMA operators.
5202 *
5203 * @param preferredRoamingList byte array containing the new PRL
5204 * @return true on success; false on any failure
5205 */
5206 @Override
5207 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
5213 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5214 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5215 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5216 return success;
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
Jake Hambye994d462014-02-03 13:10:13 -08005220 }
5221
5222 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005223 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005224 * Used for device configuration by some CDMA operators.
5225 *
chen xu6dac5ab2018-10-26 17:39:23 -07005226 * @param slotIndex - device slot.
5227 *
Jake Hambye994d462014-02-03 13:10:13 -08005228 * @return true on success; false on any failure
5229 */
5230 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005231 public boolean resetModemConfig(int slotIndex) {
5232 Phone phone = PhoneFactory.getPhone(slotIndex);
5233 if (phone != null) {
5234 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5235 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236
chen xu6dac5ab2018-10-26 17:39:23 -07005237 final long identity = Binder.clearCallingIdentity();
5238 try {
5239 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5240 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5241 return success;
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245 }
chen xu6dac5ab2018-10-26 17:39:23 -07005246 return false;
5247 }
5248
5249 /**
5250 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5251 *
5252 * @param slotIndex - device slot.
5253 *
5254 * @return true on success; false on any failure
5255 */
5256 @Override
5257 public boolean rebootModem(int slotIndex) {
5258 Phone phone = PhoneFactory.getPhone(slotIndex);
5259 if (phone != null) {
5260 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5261 mApp, phone.getSubId(), "rebootModem");
5262
5263 final long identity = Binder.clearCallingIdentity();
5264 try {
5265 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5266 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5267 return success;
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
5271 }
5272 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005273 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005274
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005275 public String[] getPcscfAddress(String apnType, String callingPackage,
5276 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005277 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005278 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5279 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005280 return new String[0];
5281 }
5282
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 final long identity = Binder.clearCallingIdentity();
5284 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005285 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Wink Saville36469e72014-06-11 15:17:00 -07005289 }
5290
Brad Ebinger51f743a2017-01-23 13:50:20 -08005291 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005292 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5293 * {@link #disableIms(int)}.
5294 * @param slotIndex device slot.
5295 */
5296 public void resetIms(int slotIndex) {
5297 enforceModifyPermission();
5298
5299 final long identity = Binder.clearCallingIdentity();
5300 try {
5301 if (mImsResolver == null) {
5302 // may happen if the does not support IMS.
5303 return;
5304 }
5305 mImsResolver.disableIms(slotIndex);
5306 mImsResolver.enableIms(slotIndex);
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
5310 }
5311
5312 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005313 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5314 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005315 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005316 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005317 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005318
5319 final long identity = Binder.clearCallingIdentity();
5320 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005321 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005322 // may happen if the device does not support IMS.
5323 return;
5324 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005325 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005329 }
5330
5331 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005332 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5333 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005334 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005335 public void disableIms(int slotId) {
5336 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005337
5338 final long identity = Binder.clearCallingIdentity();
5339 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005340 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005341 // may happen if the device does not support IMS.
5342 return;
5343 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005344 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005345 } finally {
5346 Binder.restoreCallingIdentity(identity);
5347 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005348 }
5349
5350 /**
Brad Ebinger67b3e042020-09-11 12:45:11 -07005351 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5352 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005353 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005354 @Override
Brad Ebingerf6aca002020-10-01 13:51:05 -07005355 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005356 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005357
5358 final long identity = Binder.clearCallingIdentity();
5359 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005360 if (mImsResolver == null) {
Brad Ebinger67b3e042020-09-11 12:45:11 -07005361 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5362 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005363 }
Brad Ebingerf6aca002020-10-01 13:51:05 -07005364 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005368 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005369 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005370 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5371 */
Brad Ebinger67b3e042020-09-11 12:45:11 -07005372 @Override
5373 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005374 enforceModifyPermission();
5375
5376 final long identity = Binder.clearCallingIdentity();
5377 try {
5378 if (mImsResolver == null) return;
Brad Ebinger67b3e042020-09-11 12:45:11 -07005379 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005380 } finally {
5381 Binder.restoreCallingIdentity(identity);
5382 }
5383 }
5384
5385 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005386 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005387 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005388 */
5389 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5390 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005391
5392 final long identity = Binder.clearCallingIdentity();
5393 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005394 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005395 // may happen if the device does not support IMS.
5396 return null;
5397 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005398 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399 } finally {
5400 Binder.restoreCallingIdentity(identity);
5401 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005402 }
5403
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005404 /**
5405 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005406 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005407 */
5408 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5409 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410
5411 final long identity = Binder.clearCallingIdentity();
5412 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005413 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005414 // may happen if the device does not support IMS.
5415 return null;
5416 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005417 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005418 } finally {
5419 Binder.restoreCallingIdentity(identity);
5420 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005421 }
5422
Brad Ebinger884c07b2018-02-15 16:17:40 -08005423 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005424 * Sets the ImsService Package Name that Telephony will bind to.
5425 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005426 * @param slotIndex the slot ID that the ImsService should bind for.
5427 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005428 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005429 * @param featureTypes An integer array of feature types associated with a packageName.
5430 * @param packageName The name of the package that the current configuration will be replaced
5431 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005432 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005433 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005434 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5435 int[] featureTypes, String packageName) {
5436 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005438 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5439 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005440 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005441
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442 final long identity = Binder.clearCallingIdentity();
5443 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005444 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005445 // may happen if the device does not support IMS.
5446 return false;
5447 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005448 Map<Integer, String> featureConfig = new HashMap<>();
5449 for (int featureType : featureTypes) {
5450 featureConfig.put(featureType, packageName);
5451 }
5452 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5453 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005454 } finally {
5455 Binder.restoreCallingIdentity(identity);
5456 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005457 }
5458
5459 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005460 * Clears any carrier ImsService overrides for the slot index specified that were previously
5461 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5462 *
5463 * This should only be used for testing.
5464 *
5465 * @param slotIndex the slot ID that the ImsService should bind for.
5466 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5467 */
5468 @Override
5469 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5470 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5471 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5472 "clearCarrierImsServiceOverride");
5473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5474 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5475 "clearCarrierImsServiceOverride");
5476
5477 final long identity = Binder.clearCallingIdentity();
5478 try {
5479 if (mImsResolver == null) {
5480 // may happen if the device does not support IMS.
5481 return false;
5482 }
5483 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
5487 }
5488
5489 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005490 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005491 *
5492 * @param slotId The slot that the ImsService is associated with.
5493 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5494 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005495 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005496 * @return the package name of the ImsService configuration.
5497 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005498 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5499 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005500 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005501 TelephonyPermissions
5502 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5503 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5504 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 final long identity = Binder.clearCallingIdentity();
5507 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005508 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005509 // may happen if the device does not support IMS.
5510 return "";
5511 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005512 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005513 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5514 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515 } finally {
5516 Binder.restoreCallingIdentity(identity);
5517 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005518 }
5519
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005520 /**
5521 * Get the MmTelFeature state associated with the requested subscription id.
5522 * @param subId The subscription that the MmTelFeature is associated with.
5523 * @param callback A callback with an integer containing the
5524 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5525 */
5526 @Override
5527 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5528 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5529 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5530 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5531 "IMS not available on device.");
5532 }
5533 final long token = Binder.clearCallingIdentity();
5534 try {
5535 int slotId = getSlotIndex(subId);
5536 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5537 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5538 + subId + "'");
5539 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5540 }
5541 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5542 try {
5543 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5544 } catch (RemoteException e) {
5545 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5546 + "Ignore");
5547 }
5548 });
5549 } finally {
5550 Binder.restoreCallingIdentity(token);
5551 }
5552 }
5553
Wink Saville36469e72014-06-11 15:17:00 -07005554 public void setImsRegistrationState(boolean registered) {
5555 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005559 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005560 } finally {
5561 Binder.restoreCallingIdentity(identity);
5562 }
Wink Saville36469e72014-06-11 15:17:00 -07005563 }
5564
5565 /**
Stuart Scott54788802015-03-30 13:18:01 -07005566 * Set the network selection mode to automatic.
5567 *
5568 */
5569 @Override
5570 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005571 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5572 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005573
5574 final long identity = Binder.clearCallingIdentity();
5575 try {
shilufc958392020-01-20 11:36:01 -08005576 if (!isActiveSubscription(subId)) {
5577 return;
5578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005579 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5580 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5581 } finally {
5582 Binder.restoreCallingIdentity(identity);
5583 }
Stuart Scott54788802015-03-30 13:18:01 -07005584 }
5585
Jack Yud10cdd42020-09-28 20:28:01 -07005586 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005587 * Ask the radio to connect to the input network and change selection mode to manual.
5588 *
5589 * @param subId the id of the subscription.
5590 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5591 * the operator to attach to.
5592 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5593 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5594 * normal network selection next time.
5595 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005596 */
5597 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005598 public boolean setNetworkSelectionModeManual(
5599 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5601 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005602
5603 if (!isActiveSubscription(subId)) {
5604 return false;
5605 }
5606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005607 final long identity = Binder.clearCallingIdentity();
5608 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005609 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005611 if (DBG) {
5612 log("setNetworkSelectionModeManual: subId: " + subId
5613 + " operator: " + operatorInfo);
5614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005615 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5616 } finally {
5617 Binder.restoreCallingIdentity(identity);
5618 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005619 }
shilu84f6e8b2019-12-19 13:58:01 -08005620 /**
5621 * Get the manual network selection
5622 *
5623 * @param subId the id of the subscription.
5624 *
5625 * @return the previously saved user selected PLMN
5626 */
5627 @Override
5628 public String getManualNetworkSelectionPlmn(int subId) {
5629 TelephonyPermissions
5630 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5631 mApp, subId, "getManualNetworkSelectionPlmn");
5632
5633 final long identity = Binder.clearCallingIdentity();
5634 try {
5635 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005636 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005637 }
5638
5639 final Phone phone = getPhone(subId);
5640 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005641 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005642 }
5643 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5644 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5645 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5646 } finally {
5647 Binder.restoreCallingIdentity(identity);
5648 }
5649 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005650
5651 /**
5652 * Scans for available networks.
5653 */
5654 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005655 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5656 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005659 LocationAccessPolicy.LocationPermissionResult locationResult =
5660 LocationAccessPolicy.checkLocationPermission(mApp,
5661 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5662 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005663 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005664 .setCallingPid(Binder.getCallingPid())
5665 .setCallingUid(Binder.getCallingUid())
5666 .setMethod("getCellNetworkScanResults")
5667 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005668 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5669 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005670 .build());
5671 switch (locationResult) {
5672 case DENIED_HARD:
5673 throw new SecurityException("Not allowed to access scan results -- location");
5674 case DENIED_SOFT:
5675 return null;
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677
Pengquan Menga1bb6272018-09-06 09:59:22 -07005678 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 try {
5680 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005681 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 } finally {
5684 Binder.restoreCallingIdentity(identity);
5685 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005686 }
5687
5688 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005689 * Get the call forwarding info, given the call forwarding reason.
5690 */
5691 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005692 public void getCallForwarding(int subId, int callForwardingReason,
5693 ICallForwardingInfoCallback callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005694 enforceReadPrivilegedPermission("getCallForwarding");
5695 long identity = Binder.clearCallingIdentity();
5696 try {
5697 if (DBG) {
5698 log("getCallForwarding: subId " + subId
5699 + " callForwardingReason" + callForwardingReason);
5700 }
Hall Liu27d24262020-09-18 19:04:59 -07005701
5702 Phone phone = getPhone(subId);
5703 if (phone == null) {
5704 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005705 callback.onError(
5706 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005707 } catch (RemoteException e) {
5708 // ignore
5709 }
5710 return;
5711 }
5712
5713 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5714 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5715 @Override
5716 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5717 try {
5718 callback.onCallForwardingInfoAvailable(info);
5719 } catch (RemoteException e) {
5720 // ignore
5721 }
5722 }
5723
5724 @Override
5725 public void onError(int error) {
5726 try {
5727 callback.onError(error);
5728 } catch (RemoteException e) {
5729 // ignore
5730 }
5731 }
5732 });
5733 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005734 } finally {
5735 Binder.restoreCallingIdentity(identity);
5736 }
5737 }
5738
5739 /**
5740 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5741 * reason, the number to forward, and the timeout before the forwarding is attempted.
5742 */
5743 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005744 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5745 IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005746 enforceModifyPermission();
5747 long identity = Binder.clearCallingIdentity();
5748 try {
5749 if (DBG) {
5750 log("setCallForwarding: subId " + subId
5751 + " callForwardingInfo" + callForwardingInfo);
5752 }
Hall Liu27d24262020-09-18 19:04:59 -07005753
5754 Phone phone = getPhone(subId);
5755 if (phone == null) {
5756 try {
Hall Liu940c4ca2020-09-29 17:10:18 -07005757 callback.accept(
5758 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liu27d24262020-09-18 19:04:59 -07005759 } catch (RemoteException e) {
5760 // ignore
5761 }
5762 return;
5763 }
5764
5765 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5766 FunctionalUtils.ignoreRemoteException(callback::accept));
5767
5768 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005769 } finally {
5770 Binder.restoreCallingIdentity(identity);
5771 }
5772 }
5773
5774 /**
Hall Liu27d24262020-09-18 19:04:59 -07005775 * Get the call waiting status for a subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005776 */
5777 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005778 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005779 enforceReadPrivilegedPermission("getCallForwarding");
5780 long identity = Binder.clearCallingIdentity();
5781 try {
Hall Liu27d24262020-09-18 19:04:59 -07005782
5783 Phone phone = getPhone(subId);
5784 if (phone == null) {
5785 try {
5786 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5787 } catch (RemoteException e) {
5788 // ignore
5789 }
5790 return;
5791 }
5792
5793 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5794
Shuo Qian4a594052020-01-23 11:59:30 -08005795 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liu27d24262020-09-18 19:04:59 -07005796 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005797 } finally {
5798 Binder.restoreCallingIdentity(identity);
5799 }
5800 }
5801
5802 /**
Hall Liu27d24262020-09-18 19:04:59 -07005803 * Sets whether call waiting is enabled for a given subId.
Shuo Qian4a594052020-01-23 11:59:30 -08005804 */
5805 @Override
Hall Liu27d24262020-09-18 19:04:59 -07005806 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
Shuo Qian4a594052020-01-23 11:59:30 -08005807 enforceModifyPermission();
5808 long identity = Binder.clearCallingIdentity();
5809 try {
Hall Liu27d24262020-09-18 19:04:59 -07005810 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5811
5812 Phone phone = getPhone(subId);
5813 if (phone == null) {
5814 try {
5815 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5816 } catch (RemoteException e) {
5817 // ignore
5818 }
5819 return;
5820 }
5821
5822 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5823 FunctionalUtils.ignoreRemoteException(callback::accept));
5824
5825 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
Shuo Qian4a594052020-01-23 11:59:30 -08005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 /**
yinxub1bed742017-04-17 11:45:04 -07005832 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005833 *
yinxub1bed742017-04-17 11:45:04 -07005834 * @param subId id of the subscription
5835 * @param request contains the radio access networks with bands/channels to scan
5836 * @param messenger callback messenger for scan results or errors
5837 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005838 * @return the id of the requested scan which can be used to stop the scan.
5839 */
5840 @Override
5841 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005842 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5844 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005845 LocationAccessPolicy.LocationPermissionResult locationResult =
5846 LocationAccessPolicy.checkLocationPermission(mApp,
5847 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5848 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005849 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005850 .setCallingPid(Binder.getCallingPid())
5851 .setCallingUid(Binder.getCallingUid())
5852 .setMethod("requestNetworkScan")
5853 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005854 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5855 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005856 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005857 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005858 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5859 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005860 if (e != null) {
5861 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5862 throw e;
5863 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005864 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005865 return TelephonyScanManager.INVALID_SCAN_ID;
5866 }
5867 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005868 }
Hall Liu912dfd32019-04-25 14:02:26 -07005869 int callingUid = Binder.getCallingUid();
5870 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005871 final long identity = Binder.clearCallingIdentity();
5872 try {
5873 return mNetworkScanRequestTracker.startNetworkScan(
5874 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005875 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
yinxu504e1392017-04-12 16:03:22 -07005879 }
5880
Hall Liub2ac8ef2019-02-28 15:56:23 -08005881 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005882 NetworkScanRequest request, int subId, String callingPackage) {
5883 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005884 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5885 boolean hasNetworkScanPermission =
5886 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5887 == PERMISSION_GRANTED;
5888
5889 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5890 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5891 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005892 }
5893
5894 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5895 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005896 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5897 return new SecurityException("Specific channels must not be"
5898 + " scanned without location access.");
5899 }
5900 }
5901 }
5902
Hall Liub2ac8ef2019-02-28 15:56:23 -08005903 return null;
5904 }
5905
yinxu504e1392017-04-12 16:03:22 -07005906 /**
5907 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005908 *
5909 * @param subId id of the subscription
5910 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005911 */
5912 @Override
5913 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005914 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5915 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916
Hall Liu912dfd32019-04-25 14:02:26 -07005917 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005918 final long identity = Binder.clearCallingIdentity();
5919 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005920 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921 } finally {
5922 Binder.restoreCallingIdentity(identity);
5923 }
yinxu504e1392017-04-12 16:03:22 -07005924 }
5925
5926 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005927 * Get the calculated preferred network type.
5928 * Used for debugging incorrect network type.
5929 *
5930 * @return the preferred network type, defined in RILConstants.java.
5931 */
5932 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005933 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005934 final Phone defaultPhone = getDefaultPhone();
5935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005936 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005937 return RILConstants.PREFERRED_NETWORK_MODE;
5938 }
5939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005940 final long identity = Binder.clearCallingIdentity();
5941 try {
5942 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005943 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005944 } finally {
5945 Binder.restoreCallingIdentity(identity);
5946 }
Junda Liu84d15a22014-07-02 11:21:04 -07005947 }
5948
5949 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005950 * Get the preferred network type.
5951 * Used for device configuration by some CDMA operators.
5952 *
5953 * @return the preferred network type, defined in RILConstants.java.
5954 */
5955 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005956 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005957 TelephonyPermissions
5958 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5959 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005960
5961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 if (DBG) log("getPreferredNetworkType");
5964 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5965 int networkType = (result != null ? result[0] : -1);
5966 if (DBG) log("getPreferredNetworkType: " + networkType);
5967 return networkType;
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005971 }
5972
5973 /**
5974 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005975 *
5976 * @param networkType the preferred network type, defined in RILConstants.java.
5977 * @return true on success; false on any failure.
5978 */
5979 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005980 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005981 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5982 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005983
5984 final long identity = Binder.clearCallingIdentity();
5985 try {
calvinpan8ed33732020-03-12 14:17:55 +08005986 Boolean success = (Boolean) sendRequest(
5987 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005988
5989 if (success) {
5990 Settings.Global.putInt(mApp.getContentResolver(),
5991 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5992 }
calvinpan8ed33732020-03-12 14:17:55 +08005993 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5994 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 } finally {
5996 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005997 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005998 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005999
6000 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08006001 * Get the allowed network types that store in the telephony provider.
6002 *
6003 * @param subId the id of the subscription.
6004 * @return allowedNetworkTypes the allowed network types.
6005 */
6006 @Override
6007 public long getAllowedNetworkTypes(int subId) {
6008 TelephonyPermissions
6009 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6010 mApp, subId, "getAllowedNetworkTypes");
6011
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 return SubscriptionManager.getLongSubscriptionProperty(
6015 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
6019 }
6020
6021 /**
6022 * Set the allowed network types.
6023 *
6024 * @param subId the id of the subscription.
6025 * @param allowedNetworkTypes the allowed network types.
6026 * @return true on success; false on any failure.
6027 */
6028 @Override
6029 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6031 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08006032
calvinpan8ed33732020-03-12 14:17:55 +08006033 SubscriptionManager.setSubscriptionProperty(subId,
6034 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6035 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08006036
calvinpan8ed33732020-03-12 14:17:55 +08006037 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6038 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6039 RILConstants.PREFERRED_NETWORK_MODE);
6040 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08006041 }
6042
6043 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006044 * Get the allowed network types for certain reason.
6045 *
6046 * @param subId the id of the subscription.
6047 * @param reason the reason the allowed network type change is taking place
6048 * @return the allowed network types.
6049 */
6050 @Override
6051 public long getAllowedNetworkTypesForReason(int subId,
6052 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6053 TelephonyPermissions
6054 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6055 mApp, subId, "getAllowedNetworkTypesForReason");
6056 final long identity = Binder.clearCallingIdentity();
6057 try {
6058 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6059 } finally {
6060 Binder.restoreCallingIdentity(identity);
6061 }
6062 }
6063
6064 /**
Sooraj Sasindran37444802020-08-11 10:40:43 -07006065 * Enable/Disable E-UTRA-NR Dual Connectivity
6066 * @param subId subscription id of the sim card
6067 * @param nrDualConnectivityState expected NR dual connectivity state
6068 * This can be passed following states
6069 * <ol>
6070 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6071 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6072 * <li>Disable NR dual connectivity and force secondary cell to be released
6073 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6074 * </ol>
6075 * @return operation result.
6076 */
6077 @Override
6078 public int setNrDualConnectivityState(int subId,
6079 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6080 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6081 mApp, subId, "enableNRDualConnectivity");
6082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6086 nrDualConnectivityState, subId,
6087 workSource);
6088 if (DBG) log("enableNRDualConnectivity result: " + result);
6089 return result;
6090 } finally {
6091 Binder.restoreCallingIdentity(identity);
6092 }
6093 }
6094
6095 /**
6096 * Is E-UTRA-NR Dual Connectivity enabled
6097 * @return true if dual connectivity is enabled else false
6098 */
6099 @Override
6100 public boolean isNrDualConnectivityEnabled(int subId) {
6101 TelephonyPermissions
6102 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6103 mApp, subId, "isNRDualConnectivityEnabled");
6104 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6105 final long identity = Binder.clearCallingIdentity();
6106 try {
6107 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6108 null, subId, workSource);
6109 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6110 return isEnabled;
6111 } finally {
6112 Binder.restoreCallingIdentity(identity);
6113 }
6114 }
6115
6116 /**
Sooraj Sasindran4deb8872020-10-30 13:17:53 -07006117 * get carrier bandwidth per primary and secondary carrier
6118 * @param subId subscription id of the sim card
6119 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6120 */
6121 @Override
6122 public CarrierBandwidth getCarrierBandwidth(int subId) {
6123 TelephonyPermissions
6124 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6125 mApp, subId, "isNRDualConnectivityEnabled");
6126 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6127 final long identity = Binder.clearCallingIdentity();
6128 try {
6129 CarrierBandwidth carrierBandwidth =
6130 getPhoneFromSubId(subId).getCarrierBandwidth();
6131 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6132 return carrierBandwidth;
6133 } finally {
6134 Binder.restoreCallingIdentity(identity);
6135 }
6136 }
6137
6138 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07006139 * Get the effective allowed network types on the device.
6140 * This API will return an intersection of allowed network types for all reasons,
6141 * including the configuration done through setAllowedNetworkTypes
6142 *
6143 * @param subId the id of the subscription.
6144 * @return the allowed network types
6145 */
6146 @Override
6147 public long getEffectiveAllowedNetworkTypes(int subId) {
6148 TelephonyPermissions
6149 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6150 mApp, subId, "getEffectiveAllowedNetworkTypes");
6151 final long identity = Binder.clearCallingIdentity();
6152 try {
6153 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6154 } finally {
6155 Binder.restoreCallingIdentity(identity);
6156 }
6157 }
6158
6159 /**
6160 * Set the allowed network types of the device and
6161 * provide the reason triggering the allowed network change.
6162 *
6163 * @param subId the id of the subscription.
6164 * @param reason the reason the allowed network type change is taking place
6165 * @param allowedNetworkTypes the allowed network types.
6166 * @return true on success; false on any failure.
6167 */
6168 @Override
6169 public boolean setAllowedNetworkTypesForReason(int subId,
6170 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6172 mApp, subId, "setAllowedNetworkTypesForReason");
6173 final long identity = Binder.clearCallingIdentity();
6174 try {
6175 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6176 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6177 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6178 RILConstants.PREFERRED_NETWORK_MODE);
6179 return setPreferredNetworkType(subId, preferredNetworkMode);
6180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
6183 }
6184
6185 /**
Miaoa84611c2019-03-15 09:21:10 +08006186 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006187 *
Miaoa84611c2019-03-15 09:21:10 +08006188 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006189 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006190 * @hide
6191 */
6192 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006193 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006194 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006195 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006196 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006197 try {
Miaoa84611c2019-03-15 09:21:10 +08006198 if (phone != null) {
6199 return phone.hasMatchedTetherApnSetting();
6200 } else {
6201 return false;
6202 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006203 } finally {
6204 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006205 }
Junda Liu475951f2014-11-07 16:45:03 -08006206 }
6207
6208 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08006209 * Enable or disable always reporting signal strength changes from radio.
6210 *
6211 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6212 */
6213 @Override
6214 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6215 enforceModifyPermission();
6216 enforceSystemCaller();
6217
6218 final long identity = Binder.clearCallingIdentity();
6219 final Phone phone = getPhone(subId);
6220 try {
6221 if (phone != null) {
6222 if (DBG) {
6223 log("setAlwaysReportSignalStrength: subId=" + subId
6224 + " isEnable=" + isEnable);
6225 }
6226 phone.setAlwaysReportSignalStrength(isEnable);
6227 } else {
6228 loge("setAlwaysReportSignalStrength: no phone found for subId="
6229 + subId);
6230 }
6231 } finally {
6232 Binder.restoreCallingIdentity(identity);
6233 }
6234 }
6235
6236 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006237 * Get the user enabled state of Mobile Data.
6238 *
6239 * TODO: remove and use isUserDataEnabled.
6240 * This can't be removed now because some vendor codes
6241 * calls through ITelephony directly while they should
6242 * use TelephonyManager.
6243 *
6244 * @return true on enabled
6245 */
6246 @Override
6247 public boolean getDataEnabled(int subId) {
6248 return isUserDataEnabled(subId);
6249 }
6250
6251 /**
6252 * Get whether mobile data is enabled per user setting.
6253 *
6254 * There are other factors deciding whether mobile data is actually enabled, but they are
6255 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006256 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006257 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006258 *
6259 * @return {@code true} if data is enabled else {@code false}
6260 */
6261 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006262 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006263 try {
6264 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6265 null);
6266 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006267 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6268 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006269 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006270
6271 final long identity = Binder.clearCallingIdentity();
6272 try {
6273 int phoneId = mSubscriptionController.getPhoneId(subId);
6274 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6275 Phone phone = PhoneFactory.getPhone(phoneId);
6276 if (phone != null) {
6277 boolean retVal = phone.isUserDataEnabled();
6278 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6279 return retVal;
6280 } else {
6281 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6282 return false;
6283 }
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006286 }
6287 }
6288
6289 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08006290 * Checks if the device is capable of mobile data by considering whether whether the
6291 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6292 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006293 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08006294 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006295 */
6296 @Override
6297 public boolean isDataEnabled(int subId) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006298 try {
6299 try {
6300 mApp.enforceCallingOrSelfPermission(
6301 android.Manifest.permission.ACCESS_NETWORK_STATE,
6302 null);
6303 } catch (Exception e) {
6304 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6305 "isDataEnabled");
6306 }
6307 } catch (Exception e) {
6308 enforceReadPrivilegedPermission("isDataEnabled");
6309 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 int phoneId = mSubscriptionController.getPhoneId(subId);
6314 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6315 Phone phone = PhoneFactory.getPhone(phoneId);
6316 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006317 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006318 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6319 return retVal;
6320 } else {
6321 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6322 return false;
6323 }
6324 } finally {
6325 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006326 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006327 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006328
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006329 /**
6330 * Check if data is enabled for a specific reason
6331 * @param subId Subscription index
6332 * @param reason the reason the data enable change is taking place
6333 * @return {@code true} if the overall data is enabled; {@code false} if not.
6334 */
6335 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006336 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006337 @TelephonyManager.DataEnabledReason int reason) {
6338 try {
6339 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6340 null);
6341 } catch (Exception e) {
6342 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006343 "isDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006344 }
6345
6346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
6349 int phoneId = mSubscriptionController.getPhoneId(subId);
6350 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006351 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006352 + " reason=" + reason);
6353 }
6354 Phone phone = PhoneFactory.getPhone(phoneId);
6355 if (phone != null) {
6356 boolean retVal;
6357 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6358 retVal = phone.isUserDataEnabled();
6359 } else {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006360 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006361 }
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006362 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006363 return retVal;
6364 } else {
6365 if (DBG) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07006366 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006367 + subId + " retVal=false");
6368 }
6369 return false;
6370 }
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006376 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006377 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07006378 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6379 // Skip the check if it's one of these special uids
6380 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6381 }
6382
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006383 //load access rules from carrier configs, and check those as well: b/139133814
6384 SubscriptionController subController = SubscriptionController.getInstance();
6385 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6386 || subController == null) return privilegeFromSim;
6387
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006388 PackageManager pkgMgr = phone.getContext().getPackageManager();
6389 String[] packages = pkgMgr.getPackagesForUid(uid);
6390
6391 final long identity = Binder.clearCallingIdentity();
6392 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006393 int subId = phone.getSubId();
6394 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6395 // A test override is in place for the privileges for this subId, so don't try to
6396 // read the subscription privileges.
6397 return privilegeFromSim;
6398 }
6399 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006400 SubscriptionManager subManager = (SubscriptionManager)
6401 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6402 for (String pkg : packages) {
6403 if (subManager.canManageSubscription(subInfo, pkg)) {
6404 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6405 }
6406 }
6407 return privilegeFromSim;
6408 } finally {
6409 Binder.restoreCallingIdentity(identity);
6410 }
6411 }
6412
6413 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6414 String pkgName) {
6415 //load access rules from carrier configs, and check those as well: b/139133814
6416 SubscriptionController subController = SubscriptionController.getInstance();
6417 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6418 || subController == null) return privilegeFromSim;
6419
6420 final long identity = Binder.clearCallingIdentity();
6421 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07006422 int subId = phone.getSubId();
6423 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6424 // A test override is in place for the privileges for this subId, so don't try to
6425 // read the subscription privileges.
6426 return privilegeFromSim;
6427 }
6428 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006429 SubscriptionManager subManager = (SubscriptionManager)
6430 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6431 return subManager.canManageSubscription(subInfo, pkgName)
6432 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6433 } finally {
6434 Binder.restoreCallingIdentity(identity);
6435 }
6436 }
6437
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006438 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006439 public int getCarrierPrivilegeStatus(int subId) {
6440 final Phone phone = getPhone(subId);
6441 if (phone == null) {
6442 loge("getCarrierPrivilegeStatus: Invalid subId");
6443 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6444 }
6445 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006446 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006447 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006448 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6449 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006450
6451 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6452 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006453 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006454 }
Junda Liu29340342014-07-10 15:23:27 -07006455
6456 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006457 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006458 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006459 final Phone phone = getPhone(subId);
6460 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006461 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006462 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6463 }
6464 UiccProfile profile =
6465 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6466 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006467 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006468 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6469 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006470 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08006471 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006472 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006473 }
6474
6475 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006476 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6477 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006478 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006479 }
6480
6481 int phoneId = SubscriptionManager.getPhoneId(subId);
6482 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006483 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006484 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006485 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6486 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006487 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6488 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6489 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006490 }
6491
6492 @Override
6493 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006494 if (TextUtils.isEmpty(pkgName))
6495 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006496 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6497 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6498 UiccCard card = UiccController.getInstance().getUiccCard(i);
6499 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006500 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006501 continue;
6502 }
6503
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006504 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6505 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6506 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006507 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6508 break;
6509 }
6510 }
6511
6512 return result;
Junda Liu29340342014-07-10 15:23:27 -07006513 }
Derek Tan89e89d42014-07-08 17:00:10 -07006514
6515 @Override
Junda Liue64de782015-04-16 17:19:16 -07006516 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6517 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6518 loge("phoneId " + phoneId + " is not valid.");
6519 return null;
6520 }
6521 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006522 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006523 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006524 return null ;
6525 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006526 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006527 }
6528
Amith Yamasani6e118872016-02-19 12:53:51 -08006529 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006530 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006531 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006532 List<String> privilegedPackages = new ArrayList<>();
6533 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006534 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6535 // has UICC in that slot.
6536 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006537 if (card.hasCarrierPrivilegeRules()) {
6538 if (packages == null) {
6539 // Only check packages in user 0 for now
6540 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006541 PackageManager.MATCH_DISABLED_COMPONENTS
6542 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006543 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006544 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006545 }
6546 for (int p = packages.size() - 1; p >= 0; p--) {
6547 PackageInfo pkgInfo = packages.get(p);
6548 if (pkgInfo != null && pkgInfo.packageName != null
6549 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006550 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006551 privilegedPackages.add(pkgInfo.packageName);
6552 }
6553 }
6554 }
6555 }
6556 return privilegedPackages;
6557 }
6558
chen xuf7e9fe82019-05-09 19:31:02 -07006559 @Override
6560 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006561 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6562
6563 final long identity = Binder.clearCallingIdentity();
6564
chen xuf7e9fe82019-05-09 19:31:02 -07006565 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006566 try {
6567 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6568 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6569 }
6570 } finally {
6571 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006572 }
6573 return privilegedPackages;
6574 }
6575
Wink Savilleb564aae2014-10-23 10:18:09 -07006576 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006577 final Phone phone = getPhone(subId);
6578 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006579 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006580 return null;
6581 }
6582 String iccId = card.getIccId();
6583 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006584 return null;
6585 }
6586 return iccId;
6587 }
6588
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006589 @Override
Shuo Qiane4e11672020-12-15 22:15:33 -08006590 public void setCallComposerStatus(int subId, int status) {
6591 enforceModifyPermission();
6592
6593 final long identity = Binder.clearCallingIdentity();
6594 try {
6595 Phone phone = getPhone(subId);
6596 if (phone != null) {
6597 Phone defaultPhone = phone.getImsPhone();
6598 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6599 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6600 imsPhone.setCallComposerStatus(status);
Shuo Qian284ae752020-12-22 19:10:14 -08006601 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6602 .updateImsServiceConfig();
Shuo Qiane4e11672020-12-15 22:15:33 -08006603 }
6604 }
Shuo Qian284ae752020-12-22 19:10:14 -08006605 } catch (ImsException e) {
6606 throw new ServiceSpecificException(e.getCode());
6607 } finally {
Shuo Qiane4e11672020-12-15 22:15:33 -08006608 Binder.restoreCallingIdentity(identity);
6609 }
6610 }
6611
6612 @Override
6613 public int getCallComposerStatus(int subId) {
6614 enforceReadPrivilegedPermission("getCallComposerStatus");
6615
6616 final long identity = Binder.clearCallingIdentity();
6617 try {
6618 Phone phone = getPhone(subId);
6619 if (phone != null) {
6620 Phone defaultPhone = phone.getImsPhone();
6621 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6622 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6623 return imsPhone.getCallComposerStatus();
6624 }
6625 }
6626 } finally {
6627 Binder.restoreCallingIdentity(identity);
6628 }
6629 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6630 }
6631
6632 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006633 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6634 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006635 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006636 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006638 final long identity = Binder.clearCallingIdentity();
6639 try {
6640 final String iccId = getIccId(subId);
6641 final Phone phone = getPhone(subId);
6642 if (phone == null) {
6643 return false;
6644 }
6645 final String subscriberId = phone.getSubscriberId();
6646
6647 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006648 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006649 + subscriberId + " to " + number);
6650 }
6651
6652 if (TextUtils.isEmpty(iccId)) {
6653 return false;
6654 }
6655
6656 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6657
6658 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6659 if (alphaTag == null) {
6660 editor.remove(alphaTagPrefKey);
6661 } else {
6662 editor.putString(alphaTagPrefKey, alphaTag);
6663 }
6664
6665 // Record both the line number and IMSI for this ICCID, since we need to
6666 // track all merged IMSIs based on line number
6667 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6668 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6669 if (number == null) {
6670 editor.remove(numberPrefKey);
6671 editor.remove(subscriberPrefKey);
6672 } else {
6673 editor.putString(numberPrefKey, number);
6674 editor.putString(subscriberPrefKey, subscriberId);
6675 }
6676
6677 editor.commit();
6678 return true;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006681 }
Derek Tan7226c842014-07-02 17:42:23 -07006682 }
6683
6684 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006685 public String getLine1NumberForDisplay(int subId, String callingPackage,
6686 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006687 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006688 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006689 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006690 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006691 return null;
6692 }
Derek Tan97ebb422014-09-05 16:55:38 -07006693
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006694 final long identity = Binder.clearCallingIdentity();
6695 try {
6696 String iccId = getIccId(subId);
6697 if (iccId != null) {
6698 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6699 if (DBG_MERGE) {
6700 log("getLine1NumberForDisplay returning "
6701 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6702 }
6703 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006704 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6706 return null;
6707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006709 }
Derek Tan7226c842014-07-02 17:42:23 -07006710 }
6711
6712 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006713 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6714 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006715 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006716 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006717 return null;
6718 }
Derek Tan97ebb422014-09-05 16:55:38 -07006719
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 final long identity = Binder.clearCallingIdentity();
6721 try {
6722 String iccId = getIccId(subId);
6723 if (iccId != null) {
6724 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6725 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6726 }
6727 return null;
6728 } finally {
6729 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006730 }
Derek Tan7226c842014-07-02 17:42:23 -07006731 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006732
6733 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006734 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6735 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006736 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6737 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006738 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006739 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006740 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006741 return null;
6742 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006743
Jordan Liub49b04b2019-05-06 14:45:15 -07006744 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6745 // the process, where TelephonyManager was instantiated.
6746 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006747 final long identity = Binder.clearCallingIdentity();
6748 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006749 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006750 final TelephonyManager tele = TelephonyManager.from(context);
6751 final SubscriptionManager sub = SubscriptionManager.from(context);
6752
6753 // Figure out what subscribers are currently active
6754 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006755
Jordan Liub49b04b2019-05-06 14:45:15 -07006756 // Only consider subs which match the current subId
6757 // This logic can be simplified. See b/131189269 for progress.
6758 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006759 activeSubscriberIds.add(tele.getSubscriberId(subId));
6760 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761
6762 // First pass, find a number override for an active subscriber
6763 String mergeNumber = null;
6764 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6765 for (String key : prefs.keySet()) {
6766 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6767 final String subscriberId = (String) prefs.get(key);
6768 if (activeSubscriberIds.contains(subscriberId)) {
6769 final String iccId = key.substring(
6770 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6771 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6772 mergeNumber = (String) prefs.get(numberKey);
6773 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006774 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006775 + " for active subscriber " + subscriberId);
6776 }
6777 if (!TextUtils.isEmpty(mergeNumber)) {
6778 break;
6779 }
6780 }
6781 }
6782 }
6783
6784 // Shortcut when no active merged subscribers
6785 if (TextUtils.isEmpty(mergeNumber)) {
6786 return null;
6787 }
6788
6789 // Second pass, find all subscribers under that line override
6790 final ArraySet<String> result = new ArraySet<>();
6791 for (String key : prefs.keySet()) {
6792 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6793 final String number = (String) prefs.get(key);
6794 if (mergeNumber.equals(number)) {
6795 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6796 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6797 final String subscriberId = (String) prefs.get(subscriberKey);
6798 if (!TextUtils.isEmpty(subscriberId)) {
6799 result.add(subscriberId);
6800 }
6801 }
6802 }
6803 }
6804
6805 final String[] resultArray = result.toArray(new String[result.size()]);
6806 Arrays.sort(resultArray);
6807 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006808 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006809 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6810 }
6811 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006812 } finally {
6813 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006814 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006815 }
6816
6817 @Override
zoey chen38003472019-12-13 17:16:31 +08006818 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6819 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006820
6821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 final TelephonyManager telephonyManager = mApp.getSystemService(
6824 TelephonyManager.class);
6825 String subscriberId = telephonyManager.getSubscriberId(subId);
6826 if (subscriberId == null) {
6827 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006828 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006829 + subId);
6830 }
6831 return null;
6832 }
6833
6834 final SubscriptionInfo info = SubscriptionController.getInstance()
6835 .getSubscriptionInfo(subId);
6836 final ParcelUuid groupUuid = info.getGroupUuid();
6837 // If it doesn't belong to any group, return just subscriberId of itself.
6838 if (groupUuid == null) {
6839 return new String[]{subscriberId};
6840 }
6841
6842 // Get all subscriberIds from the group.
6843 final List<String> mergedSubscriberIds = new ArrayList<>();
6844 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006845 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006846 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006847 for (SubscriptionInfo subInfo : groupInfos) {
6848 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6849 if (subscriberId != null) {
6850 mergedSubscriberIds.add(subscriberId);
6851 }
6852 }
6853
6854 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857
6858 }
6859 }
6860
6861 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006862 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006863 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006864 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865
6866 final long identity = Binder.clearCallingIdentity();
6867 try {
6868 final Phone phone = getPhone(subId);
6869 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006873 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006874
6875 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006876 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006877 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6878 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6880 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
6884 final Phone phone = getPhone(subId);
6885 if (phone == null) {
6886 return false;
6887 }
6888 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6889 cdmaNonRoamingList);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006892 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006893 }
6894
6895 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006896 @Deprecated
6897 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6898 enforceModifyPermission();
6899
6900 int returnValue = 0;
6901 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006902 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006903 if(result.exception == null) {
6904 if (result.result != null) {
6905 byte[] responseData = (byte[])(result.result);
6906 if(responseData.length > oemResp.length) {
6907 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6908 responseData.length + "bytes. Buffer Size is " +
6909 oemResp.length + "bytes.");
6910 }
6911 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6912 returnValue = responseData.length;
6913 }
6914 } else {
6915 CommandException ex = (CommandException) result.exception;
6916 returnValue = ex.getCommandError().ordinal();
6917 if(returnValue > 0) returnValue *= -1;
6918 }
6919 } catch (RuntimeException e) {
6920 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6921 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6922 if(returnValue > 0) returnValue *= -1;
6923 }
6924
6925 return returnValue;
6926 }
6927
6928 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006929 public void setRadioCapability(RadioAccessFamily[] rafs) {
6930 try {
6931 ProxyController.getInstance().setRadioCapability(rafs);
6932 } catch (RuntimeException e) {
6933 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6934 }
6935 }
6936
6937 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006938 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006939 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006940 try {
6941 TelephonyPermissions
6942 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6943 mApp, phone.getSubId(), "getRadioAccessFamily");
6944 } catch (SecurityException e) {
6945 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6946 throw e;
6947 }
chen xub97461a2018-10-26 14:17:57 -07006948 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006949 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006950 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006951 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
chen xub97461a2018-10-26 14:17:57 -07006954 TelephonyPermissions
6955 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6956 mApp, phone.getSubId(), "getRadioAccessFamily");
6957 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006958 } finally {
6959 Binder.restoreCallingIdentity(identity);
6960 }
chen xub97461a2018-10-26 14:17:57 -07006961 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006962 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006963
6964 @Override
6965 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006966 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006967 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968
6969 final long identity = Binder.clearCallingIdentity();
6970 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006971 ImsManager.getInstance(defaultPhone.getContext(),
6972 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006976 }
6977
6978 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006979 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006980 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6982 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006983 return false;
6984 }
Svet Ganovb320e182015-04-16 12:30:10 -07006985
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 final long identity = Binder.clearCallingIdentity();
6987 try {
6988 // Check the user preference and the system-level IMS setting. Even if the user has
6989 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6990 // In the long run, we may instead need to check if there exists a connection service
6991 // which can support video calling.
6992 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006993 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 return imsManager.isVtEnabledByPlatform()
6995 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6996 && imsManager.isVtEnabledByUser();
6997 } finally {
6998 Binder.restoreCallingIdentity(identity);
6999 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007000 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007001
Andrew Leea1239f22015-03-02 17:44:07 -08007002 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007003 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7004 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007006 mApp, subId, callingPackage, callingFeatureId,
7007 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 return false;
7009 }
7010
7011 final long identity = Binder.clearCallingIdentity();
7012 try {
7013 CarrierConfigManager configManager =
7014 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007015 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
Andrew Leea1239f22015-03-02 17:44:07 -08007020 }
7021
7022 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007023 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007025 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 return false;
7027 }
7028
7029 final long identity = Binder.clearCallingIdentity();
7030 try {
7031 CarrierConfigManager configManager =
7032 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007033 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7035 } finally {
7036 Binder.restoreCallingIdentity(identity);
7037 }
Andrew Leea1239f22015-03-02 17:44:07 -08007038 }
7039
Andrew Lee9431b832015-03-09 18:46:45 -07007040 @Override
7041 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007042 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007043 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007044 }
7045
7046 @Override
7047 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 final long identity = Binder.clearCallingIdentity();
7049 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007050 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 } finally {
7052 Binder.restoreCallingIdentity(identity);
7053 }
Andrew Lee9431b832015-03-09 18:46:45 -07007054 }
7055
Hall Liuf6668912018-10-31 17:05:23 -07007056 /**
7057 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7058 * support for the feature and device firmware support.
7059 *
7060 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7061 */
7062 @Override
7063 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007065 final Phone phone = getPhone(subscriptionId);
7066 if (phone == null) {
7067 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7068 return false;
7069 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007070 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007071 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007072 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7073 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007074 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075 return isCarrierSupported && isDeviceSupported;
7076 } finally {
7077 Binder.restoreCallingIdentity(identity);
7078 }
Hall Liu98187582018-01-22 19:15:32 -08007079 }
7080
Hall Liuf6668912018-10-31 17:05:23 -07007081 /**
Hall Liuf2daa022019-07-23 18:39:00 -07007082 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7083 * RTT setting, will return true if the device and carrier both support RTT.
7084 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007085 */
7086 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 final long identity = Binder.clearCallingIdentity();
7088 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00007089 boolean isRttSupported = isRttSupported(subscriptionId);
7090 boolean isUserRttSettingOn = Settings.Secure.getInt(
7091 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7092 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7093 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7094 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007098 }
7099
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007100 @Deprecated
7101 @Override
7102 public String getDeviceId(String callingPackage) {
7103 return getDeviceIdWithFeature(callingPackage, null);
7104 }
7105
Sanket Padawe7310cc72015-01-14 09:53:20 -08007106 /**
7107 * Returns the unique device ID of phone, for example, the IMEI for
7108 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7109 *
7110 * <p>Requires Permission:
7111 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7112 */
7113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007114 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007115 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007116 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007117 return null;
7118 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007119 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007120 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007121 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007122 return null;
7123 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007124
7125 final long identity = Binder.clearCallingIdentity();
7126 try {
7127 return phone.getDeviceId();
7128 } finally {
7129 Binder.restoreCallingIdentity(identity);
7130 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007131 }
7132
Ping Sunc67b7c22016-03-02 19:16:45 +08007133 /**
7134 * {@hide}
7135 * Returns the IMS Registration Status on a particular subid
7136 *
7137 * @param subId
7138 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007139 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007140 Phone phone = getPhone(subId);
7141 if (phone != null) {
7142 return phone.isImsRegistered();
7143 } else {
7144 return false;
7145 }
7146 }
7147
Santos Cordon7a1885b2015-02-03 11:15:19 -08007148 @Override
7149 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007150 final long identity = Binder.clearCallingIdentity();
7151 try {
7152 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7153 } finally {
7154 Binder.restoreCallingIdentity(identity);
7155 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007156 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007157
Tyler Gunnf70ed162019-04-03 15:28:53 -07007158 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07007159 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007160 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007161 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007162 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07007163 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7164 }
7165 final long identity = Binder.clearCallingIdentity();
7166 try {
7167 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7168 } finally {
7169 Binder.restoreCallingIdentity(identity);
7170 }
7171 }
7172
7173 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007174 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007175 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7176 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007177 final long identity = Binder.clearCallingIdentity();
7178 try {
7179 Phone phone = getPhone(subscriptionId);
7180 if (phone == null) {
7181 return null;
7182 }
7183 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7184 } finally {
7185 Binder.restoreCallingIdentity(identity);
7186 }
7187 }
7188
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 /**
7190 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007191 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007192 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007193 final long identity = Binder.clearCallingIdentity();
7194 try {
7195 Phone phone = getPhone(subId);
7196 if (phone != null) {
7197 return phone.isWifiCallingEnabled();
7198 } else {
7199 return false;
7200 }
7201 } finally {
7202 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007203 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007204 }
7205
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007206 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007207 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007208 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007209 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 Phone phone = getPhone(subId);
7213 if (phone != null) {
7214 return phone.isVideoEnabled();
7215 } else {
7216 return false;
7217 }
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007220 }
7221 }
7222
7223 /**
7224 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7225 * defined in {@link ImsRegistrationImplBase}.
7226 */
7227 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007228 final long identity = Binder.clearCallingIdentity();
7229 try {
7230 Phone phone = getPhone(subId);
7231 if (phone != null) {
7232 return phone.getImsRegistrationTech();
7233 } else {
7234 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7235 }
7236 } finally {
7237 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007238 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007239 }
7240
Stuart Scott8eef64f2015-04-08 15:13:54 -07007241 @Override
7242 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08007243 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007244 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7245 return;
7246 }
7247
Svet Ganovcc087f82015-05-12 20:35:54 -07007248 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007249
Svet Ganovcc087f82015-05-12 20:35:54 -07007250 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007251 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7252 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007253 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007254 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007255 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007256 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007257 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7258 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007259 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007260 // There has been issues when Sms raw table somehow stores orphan
7261 // fragments. They lead to garbled message when new fragments come
7262 // in and combined with those stale ones. In case this happens again,
7263 // user can reset all network settings which will clean up this table.
7264 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07007265 // Clean up IMS settings as well here.
7266 int slotId = getSlotIndex(subId);
7267 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7268 ImsManager.getInstance(mApp, slotId).factoryReset();
7269 }
Naina Nallurid63128d2019-09-17 14:10:30 -07007270
7271 // Erase modem config if erase modem on network setting is enabled.
7272 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7273 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7274 if (configValue != null && Boolean.parseBoolean(configValue)) {
7275 sendEraseModemConfig(getDefaultPhone());
7276 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007277 } finally {
7278 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007279 }
7280 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007281
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007282 private void cleanUpSmsRawTable(Context context) {
7283 ContentResolver resolver = context.getContentResolver();
7284 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7285 resolver.delete(uri, null, null);
7286 }
7287
Narayan Kamath1c496c22015-04-16 14:40:19 +01007288 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007289 public String getSimLocaleForSubscriber(int subId) {
7290 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7291 final Phone phone = getPhone(subId);
7292 if (phone == null) {
7293 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007294 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007296 final long identity = Binder.clearCallingIdentity();
7297 try {
chen xu5d3637b2019-01-21 23:31:38 -08007298 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007299 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007300 if (info == null) {
7301 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7302 return null;
7303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007304 // Try and fetch the locale from the carrier properties or from the SIM language
7305 // preferences (EF-PL and EF-LI)...
7306 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007307 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007308 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7309 if (localeFromDefaultSim != null) {
7310 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7311 if (DBG) log("Using locale from subId: " + subId + " locale: "
7312 + localeFromDefaultSim);
7313 return localeFromDefaultSim.toLanguageTag();
7314 } else {
7315 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 }
7317 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007318
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 // The SIM language preferences only store a language (e.g. fr = French), not an
7320 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7321 // the SIM and carrier preferences does not include a country we add the country
7322 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08007323 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007325 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007326 return mccLocale.toLanguageTag();
7327 }
7328
7329 if (DBG) log("No locale found - returning null");
7330 return null;
7331 } finally {
7332 Binder.restoreCallingIdentity(identity);
7333 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007334 }
7335
7336 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007338 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007339 }
7340
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007341 /**
7342 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7343 */
7344 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007345 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08007346 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007347 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007348
Chenjie Yu1ba97252018-01-11 18:16:20 -08007349 private final ModemActivityInfo mLastModemActivityInfo =
Hall Liu49656c02020-10-09 19:00:11 -07007350 new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007351
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007352 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007353 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7354 * representing the state of the modem.
7355 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007356 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7357 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007358 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007359 */
7360 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007361 public void requestModemActivityInfo(ResultReceiver result) {
7362 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007363 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007364
7365 final long identity = Binder.clearCallingIdentity();
7366 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08007367 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 } finally {
7369 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007370 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007371 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007372
Siddharth Rayb8114062018-06-17 15:02:38 -07007373 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7374 // less than total activity duration.
7375 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7376 if (info == null) {
7377 return false;
7378 }
7379 int activityDurationMs =
Hall Liu49656c02020-10-09 19:00:11 -07007380 (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis());
7381 int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum();
7382
Siddharth Rayb8114062018-06-17 15:02:38 -07007383 return (info.isValid()
7384 && (info.getSleepTimeMillis() <= activityDurationMs)
7385 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07007386 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007387 && (totalTxTimeMs <= activityDurationMs));
7388 }
7389
Jack Yu85bd38a2015-11-09 11:34:32 -08007390 /**
7391 * {@hide}
7392 * Returns the service state information on specified subscription.
7393 */
7394 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007395 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7396 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007397 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007398 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007399 return null;
7400 }
7401
Hall Liuf19c44f2018-11-27 14:38:17 -08007402 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7403 LocationAccessPolicy.checkLocationPermission(mApp,
7404 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7405 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007406 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007407 .setCallingPid(Binder.getCallingPid())
7408 .setCallingUid(Binder.getCallingUid())
7409 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007410 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007411 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7413 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007414 .build());
7415
7416 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7417 LocationAccessPolicy.checkLocationPermission(mApp,
7418 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7419 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07007420 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007421 .setCallingPid(Binder.getCallingPid())
7422 .setCallingUid(Binder.getCallingUid())
7423 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007424 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007425 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07007426 .setMinSdkVersionForFine(Integer.MAX_VALUE)
7427 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08007428 .build());
7429 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7430 boolean hasFinePermission =
7431 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7432 boolean hasCoarsePermission =
7433 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7434
Jack Yu479f40e2020-10-27 21:29:25 -07007435 final Phone phone = getPhone(subId);
7436 if (phone == null) {
7437 return null;
7438 }
7439
Jordan Liu0f2bc442020-11-18 16:47:37 -08007440 final long identity = Binder.clearCallingIdentity();
7441
Jack Yu479f40e2020-10-27 21:29:25 -07007442 boolean isCallingPackageDataService = phone.getDataServicePackages()
7443 .contains(callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007444 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007445 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7446 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7447 Rlog.d(LOG_TAG,
7448 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7449 return null;
7450 }
7451
Hall Liuf19c44f2018-11-27 14:38:17 -08007452 ServiceState ss = phone.getServiceState();
7453
7454 // Scrub out the location info in ServiceState depending on what level of access
7455 // the caller has.
Jack Yu479f40e2020-10-27 21:29:25 -07007456 if (hasFinePermission || isCallingPackageDataService) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08007457 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7458 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 } finally {
7460 Binder.restoreCallingIdentity(identity);
7461 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007462 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007463
7464 /**
7465 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7466 *
7467 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7468 * voicemail ringtone.
7469 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7470 * PhoneAccount.
7471 */
7472 @Override
7473 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007474 final long identity = Binder.clearCallingIdentity();
7475 try {
7476 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7477 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007478 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007479 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7482 } finally {
7483 Binder.restoreCallingIdentity(identity);
7484 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007485 }
7486
7487 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007488 * Sets the per-account voicemail ringtone.
7489 *
7490 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7491 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7492 *
7493 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7494 * voicemail ringtone.
7495 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7496 * PhoneAccount.
7497 */
7498 @Override
7499 public void setVoicemailRingtoneUri(String callingPackage,
7500 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007501 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007502 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007503 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7504 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7506 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7507 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007509
7510 final long identity = Binder.clearCallingIdentity();
7511 try {
7512 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7513 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007514 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007515 }
7516 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7517 } finally {
7518 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007519 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007520 }
7521
7522 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007523 * Returns whether vibration is set for voicemail notification in Phone settings.
7524 *
7525 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7526 * voicemail vibration setting.
7527 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7528 */
7529 @Override
7530 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007531 final long identity = Binder.clearCallingIdentity();
7532 try {
7533 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7534 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007535 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007536 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
7541 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007542 }
7543
Youhan Wange64578a2016-05-02 15:32:42 -07007544 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007545 * Sets the per-account voicemail vibration.
7546 *
7547 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7548 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7549 *
7550 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7551 * voicemail vibration setting.
7552 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7553 * specific PhoneAccount.
7554 */
7555 @Override
7556 public void setVoicemailVibrationEnabled(String callingPackage,
7557 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007558 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007559 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07007560 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7561 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007562 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7563 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7564 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007565 }
7566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007567 final long identity = Binder.clearCallingIdentity();
7568 try {
7569 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7570 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007571 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572 }
7573 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7574 } finally {
7575 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007576 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007577 }
7578
7579 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007580 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7581 *
7582 * @throws SecurityException if the caller does not have the required permission
7583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007584 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007585 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007586 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007587 }
7588
7589 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007590 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7591 * permission.
7592 *
7593 * @throws SecurityException if the caller does not have the required permission
7594 */
7595 private void enforceSendSmsPermission() {
7596 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7597 }
7598
7599 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007600 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007601 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007602 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007603 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007604 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007605 final long identity = Binder.clearCallingIdentity();
7606 try {
7607 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007608 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 if (componentName == null) {
7610 throw new SecurityException(
7611 "Caller not current active visual voicemail package[null]");
7612 }
7613 String vvmPackage = componentName.getPackageName();
7614 if (!callingPackage.equals(vvmPackage)) {
7615 throw new SecurityException("Caller not current active visual voicemail package["
7616 + vvmPackage + "]");
7617 }
7618 } finally {
7619 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007620 }
7621 }
7622
7623 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007624 * Return the application ID for the app type.
7625 *
7626 * @param subId the subscription ID that this request applies to.
7627 * @param appType the uicc app type.
7628 * @return Application ID for specificied app type, or null if no uicc.
7629 */
7630 @Override
7631 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007632 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007633 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007634
7635 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007636 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007637 if (phone == null) {
7638 return null;
7639 }
7640 String aid = null;
7641 try {
7642 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7643 .getApplicationByType(appType).getAid();
7644 } catch (Exception e) {
7645 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7646 }
7647 return aid;
7648 } finally {
7649 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007650 }
Youhan Wange64578a2016-05-02 15:32:42 -07007651 }
7652
Youhan Wang4001d252016-05-11 10:29:41 -07007653 /**
7654 * Return the Electronic Serial Number.
7655 *
7656 * @param subId the subscription ID that this request applies to.
7657 * @return ESN or null if error.
7658 */
7659 @Override
7660 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007661 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007662 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007663
7664 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007665 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007666 if (phone == null) {
7667 return null;
7668 }
7669 String esn = null;
7670 try {
7671 esn = phone.getEsn();
7672 } catch (Exception e) {
7673 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7674 }
7675 return esn;
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007678 }
Youhan Wang4001d252016-05-11 10:29:41 -07007679 }
7680
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007681 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007682 * Return the Preferred Roaming List Version.
7683 *
7684 * @param subId the subscription ID that this request applies to.
7685 * @return PRLVersion or null if error.
7686 */
7687 @Override
7688 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007689 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007690 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007691
7692 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007693 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007694 if (phone == null) {
7695 return null;
7696 }
7697 String cdmaPrlVersion = null;
7698 try {
7699 cdmaPrlVersion = phone.getCdmaPrlVersion();
7700 } catch (Exception e) {
7701 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7702 }
7703 return cdmaPrlVersion;
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007706 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007707 }
7708
7709 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007710 * Get snapshot of Telephony histograms
7711 * @return List of Telephony histograms
7712 * @hide
7713 */
7714 @Override
7715 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7717 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 return RIL.getTelephonyRILTimingHistograms();
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007725 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007726
7727 /**
7728 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007729 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7730 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007731 * Require system privileges. In the future we may add this to carrier APIs.
7732 *
Michele Berionne482f8202018-11-27 18:57:59 -08007733 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007734 */
7735 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007736 @TelephonyManager.SetCarrierRestrictionResult
7737 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007739 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007740
Michele Berionne482f8202018-11-27 18:57:59 -08007741 if (carrierRestrictionRules == null) {
7742 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007743 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007745 final long identity = Binder.clearCallingIdentity();
7746 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007747 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007748 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007749 } finally {
7750 Binder.restoreCallingIdentity(identity);
7751 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007752 }
7753
7754 /**
7755 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007756 * Get the allowed carrier list and the excluded carrier list, including the priority between
7757 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007758 * Require system privileges. In the future we may add this to carrier APIs.
7759 *
Michele Berionne482f8202018-11-27 18:57:59 -08007760 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007761 */
7762 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007763 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007764 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007765 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007766
7767 final long identity = Binder.clearCallingIdentity();
7768 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007769 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7770 if (response instanceof CarrierRestrictionRules) {
7771 return (CarrierRestrictionRules) response;
7772 }
7773 // Response is an Exception of some kind,
7774 // which is signalled to the user as a NULL retval
7775 return null;
7776 } catch (Exception e) {
7777 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7778 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007779 } finally {
7780 Binder.restoreCallingIdentity(identity);
7781 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007782 }
7783
fionaxu59545b42016-05-25 15:53:37 -07007784 /**
fionaxu59545b42016-05-25 15:53:37 -07007785 * Action set from carrier signalling broadcast receivers to enable/disable radio
7786 * @param subId the subscription ID that this action applies to.
7787 * @param enabled control enable or disable radio.
7788 * {@hide}
7789 */
7790 @Override
7791 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7792 enforceModifyPermission();
7793 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794
7795 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007796 if (phone == null) {
7797 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7798 return;
7799 }
7800 try {
7801 phone.carrierActionSetRadioEnabled(enabled);
7802 } catch (Exception e) {
7803 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804 } finally {
7805 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007806 }
7807 }
7808
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007809 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007810 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7811 * network status based on which carrier apps could apply actions accordingly,
7812 * enable/disable default url handler for example.
7813 *
7814 * @param subId the subscription ID that this action applies to.
7815 * @param report control start/stop reporting the default network status.
7816 * {@hide}
7817 */
7818 @Override
7819 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7820 enforceModifyPermission();
7821 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822
7823 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007824 if (phone == null) {
7825 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7826 return;
7827 }
7828 try {
7829 phone.carrierActionReportDefaultNetworkStatus(report);
7830 } catch (Exception e) {
7831 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007832 } finally {
7833 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007834 }
7835 }
7836
7837 /**
fionaxud9622282017-07-17 17:51:30 -07007838 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7839 * @param subId the subscription ID that this action applies to.
7840 * {@hide}
7841 */
7842 @Override
7843 public void carrierActionResetAll(int subId) {
7844 enforceModifyPermission();
7845 final Phone phone = getPhone(subId);
7846 if (phone == null) {
7847 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7848 return;
7849 }
7850 try {
7851 phone.carrierActionResetAll();
7852 } catch (Exception e) {
7853 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7854 }
7855 }
7856
7857 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007858 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7859 * bug report is being generated.
7860 */
7861 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007862 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007863 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7864 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007865 writer.println("Permission Denial: can't dump Phone from pid="
7866 + Binder.getCallingPid()
7867 + ", uid=" + Binder.getCallingUid()
7868 + "without permission "
7869 + android.Manifest.permission.DUMP);
7870 return;
7871 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007872 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007873 }
Jack Yueb89b242016-06-22 13:27:47 -07007874
Brad Ebingerdac2f002018-04-03 15:17:52 -07007875 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007876 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7877 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7878 @NonNull String[] args) {
7879 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7880 this, in.getFileDescriptor(), out.getFileDescriptor(),
7881 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007882 }
7883
Jack Yueb89b242016-06-22 13:27:47 -07007884 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007885 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007886 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007887 * @param reason the reason the data enable change is taking place
7888 * @param enabled True if enabling the data, otherwise disabling.
7889 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007890 */
7891 @Override
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007892 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007893 boolean enabled) {
7894 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7895 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7896 try {
7897 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindran95c07a92020-07-15 01:35:24 -07007898 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007899 } catch (SecurityException se) {
7900 enforceModifyPermission();
7901 }
7902 } else {
7903 enforceModifyPermission();
7904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 Phone phone = getPhone(subId);
7909 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007910 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7911 phone.carrierActionSetMeteredApnsEnabled(enabled);
7912 } else {
7913 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 }
7916 } finally {
7917 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007918 }
7919 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007920
7921 /**
7922 * Get Client request stats
7923 * @return List of Client Request Stats
7924 * @hide
7925 */
7926 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007927 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7928 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007929 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007930 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007931 return null;
7932 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007933 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007934
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007935 final long identity = Binder.clearCallingIdentity();
7936 try {
7937 if (phone != null) {
7938 return phone.getClientRequestStats();
7939 }
7940
7941 return null;
7942 } finally {
7943 Binder.restoreCallingIdentity(identity);
7944 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007945 }
7946
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007947 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007948 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007949 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007950 }
Jack Yueb4124c2017-02-16 15:32:43 -08007951
7952 /**
Grace Chen70990072017-03-24 17:21:30 -07007953 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007954 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007955 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007956 * @param state State of SIM (power down, power up, pass through)
7957 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7958 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7959 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007960 *
7961 **/
7962 @Override
Grace Chen70990072017-03-24 17:21:30 -07007963 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007964 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007965 Phone phone = PhoneFactory.getPhone(slotIndex);
7966
vagdeviaf9a5b92018-08-15 16:01:53 -07007967 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7968
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007969 final long identity = Binder.clearCallingIdentity();
7970 try {
7971 if (phone != null) {
Jordan Liu109698e2020-11-24 14:50:34 -08007972 phone.setSimPowerState(state, null, workSource);
7973 }
7974 } finally {
7975 Binder.restoreCallingIdentity(identity);
7976 }
7977 }
7978
7979 /**
7980 * Set SIM card power state.
7981 *
7982 * @param slotIndex SIM slot id.
7983 * @param state State of SIM (power down, power up, pass through)
7984 * @param callback callback to trigger after success or failure
7985 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7986 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7987 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7988 *
7989 **/
7990 @Override
7991 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7992 IIntegerConsumer callback) {
7993 enforceModifyPermission();
7994 Phone phone = PhoneFactory.getPhone(slotIndex);
7995
7996 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 if (phone != null) {
8001 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8002 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008003 }
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008006 }
8007 }
Shuo Qiandd210312017-04-12 22:11:33 +00008008
Tyler Gunn65d45c22017-06-05 11:22:26 -07008009 private boolean isUssdApiAllowed(int subId) {
8010 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008011 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008012 if (configManager == null) {
8013 return false;
8014 }
8015 PersistableBundle pb = configManager.getConfigForSubId(subId);
8016 if (pb == null) {
8017 return false;
8018 }
8019 return pb.getBoolean(
8020 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8021 }
8022
Shuo Qiandd210312017-04-12 22:11:33 +00008023 /**
8024 * Check if phone is in emergency callback mode
8025 * @return true if phone is in emergency callback mode
8026 * @param subId sub id
8027 */
goneil9c5f4872017-12-05 14:07:56 -08008028 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008029 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008030 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008031 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008032
8033 final long identity = Binder.clearCallingIdentity();
8034 try {
8035 if (phone != null) {
8036 return phone.isInEcm();
8037 } else {
8038 return false;
8039 }
8040 } finally {
8041 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008042 }
8043 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008044
8045 /**
8046 * Get the current signal strength information for the given subscription.
8047 * Because this information is not updated when the device is in a low power state
8048 * it should not be relied-upon to be current.
8049 * @param subId Subscription index
8050 * @return the most recent cached signal strength info from the modem
8051 */
8052 @Override
8053 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008054 final long identity = Binder.clearCallingIdentity();
8055 try {
8056 Phone p = getPhone(subId);
8057 if (p == null) {
8058 return null;
8059 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008061 return p.getSignalStrength();
8062 } finally {
8063 Binder.restoreCallingIdentity(identity);
8064 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008065 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008066
Pengquan Meng77b7f132018-08-22 14:49:57 -07008067 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008068 * Get the current modem radio state for the given slot.
8069 * @param slotIndex slot index.
8070 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008071 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008072 * @return the current radio power state from the modem
8073 */
8074 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008075 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008076 Phone phone = PhoneFactory.getPhone(slotIndex);
8077 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008078 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8079 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008080 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8081 }
8082
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
8085 return phone.getRadioPowerState();
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
8090 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8091 }
8092
8093 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008094 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8095 *
8096 * <p>Requires one of the following permissions:
8097 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8098 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8099 * privileges.
8100 *
8101 * @param subId subscription id
8102 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8103 * {@code false}.
8104 */
8105 @Override
8106 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian093013d2020-08-13 15:42:55 -07008107 try {
8108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8109 null);
8110 } catch (Exception e) {
8111 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8112 mApp, subId, "isDataRoamingEnabled");
8113 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008114
Pengquan Menga1bb6272018-09-06 09:59:22 -07008115 boolean isEnabled = false;
8116 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008117 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008118 Phone phone = getPhone(subId);
8119 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008120 } finally {
8121 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008122 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008123 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008124 }
8125
8126
8127 /**
8128 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8129 *
8130 * <p> Requires permission:
8131 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8132 * privileges.
8133 *
8134 * @param subId subscription id
8135 * @param isEnabled {@code true} means enable, {@code false} means disable.
8136 */
8137 @Override
8138 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8140 mApp, subId, "setDataRoamingEnabled");
8141
Pengquan Menga1bb6272018-09-06 09:59:22 -07008142 final long identity = Binder.clearCallingIdentity();
8143 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008144 Phone phone = getPhone(subId);
8145 if (phone != null) {
8146 phone.setDataRoamingEnabled(isEnabled);
8147 }
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008150 }
8151 }
8152
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008153 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008154 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008155 TelephonyPermissions
8156 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008157 mApp, subId, "isManualNetworkSelectionAllowed");
8158
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008159 boolean isAllowed = true;
8160 final long identity = Binder.clearCallingIdentity();
8161 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008162 Phone phone = getPhone(subId);
8163 if (phone != null) {
8164 isAllowed = phone.isCspPlmnEnabled();
8165 }
8166 } finally {
8167 Binder.restoreCallingIdentity(identity);
8168 }
8169 return isAllowed;
8170 }
8171
8172 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008173 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07008174 // Verify that tha callingPackage belongs to the calling UID
8175 mApp.getSystemService(AppOpsManager.class)
8176 .checkPackage(Binder.getCallingUid(), callingPackage);
8177
Jordan Liu1e142fc2019-04-22 15:10:43 -07008178 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008179 try {
8180 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008181 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008182 } catch (SecurityException e) {
8183 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8184 // has carrier privileges on an active UICC
8185 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8186 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008187 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008188 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008189 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008190
8191 final long identity = Binder.clearCallingIdentity();
8192 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008193 UiccController uiccController = UiccController.getInstance();
8194 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008195 if (hasReadPermission) {
8196 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008197 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008198
8199 // Remove private info if the caller doesn't have access
8200 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8201 for (UiccCardInfo cardInfo : cardInfos) {
8202 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8203 // is available
8204 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8205 if (card == null || card.getUiccProfile() == null) {
8206 // assume no access if the card or profile is unavailable
8207 filteredInfos.add(cardInfo.getUnprivileged());
8208 continue;
8209 }
8210 UiccProfile profile = card.getUiccProfile();
8211 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8212 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8213 filteredInfos.add(cardInfo);
8214 } else {
8215 filteredInfos.add(cardInfo.getUnprivileged());
8216 }
8217 }
8218 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008219 } finally {
8220 Binder.restoreCallingIdentity(identity);
8221 }
8222 }
8223
8224 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008225 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008226 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008228 final long identity = Binder.clearCallingIdentity();
8229 try {
8230 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8231 if (slots == null) {
8232 Rlog.i(LOG_TAG, "slots is null.");
8233 return null;
8234 }
8235
8236 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8237 for (int i = 0; i < slots.length; i++) {
8238 UiccSlot slot = slots[i];
8239 if (slot == null) {
8240 continue;
8241 }
8242
Jordan Liu7be7e652019-05-06 18:55:02 +00008243 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008244 UiccCard card = slot.getUiccCard();
8245 if (card != null) {
8246 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008247 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07008248 cardId = slot.getEid();
8249 if (TextUtils.isEmpty(cardId)) {
8250 cardId = slot.getIccId();
8251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008252 }
8253
Jordan Liu857451f2019-05-09 16:35:35 -07008254 if (cardId != null) {
8255 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8256 // if cardId is an EID, it's all digits so this is fine
8257 cardId = IccUtils.stripTrailingFs(cardId);
8258 }
8259
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008260 int cardState = 0;
8261 switch (slot.getCardState()) {
8262 case CARDSTATE_ABSENT:
8263 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8264 break;
8265 case CARDSTATE_PRESENT:
8266 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8267 break;
8268 case CARDSTATE_ERROR:
8269 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8270 break;
8271 case CARDSTATE_RESTRICTED:
8272 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8273 break;
8274 default:
8275 break;
8276
8277 }
8278
8279 infos[i] = new UiccSlotInfo(
8280 slot.isActive(),
8281 slot.isEuicc(),
8282 cardId,
8283 cardState,
8284 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008285 slot.isExtendedApduSupported(),
8286 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 }
8288 return infos;
8289 } finally {
8290 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008291 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008292 }
8293
8294 @Override
8295 public boolean switchSlots(int[] physicalSlots) {
8296 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008297
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008304 }
Jack Yu4c988042018-02-27 15:30:01 -08008305
8306 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008307 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 return UiccController.getInstance().getCardIdForDefaultEuicc();
8311 } finally {
8312 Binder.restoreCallingIdentity(identity);
8313 }
8314 }
8315
Pengquan Meng85728fb2018-03-12 16:31:21 -07008316 /**
goneil47ffb6e2018-04-06 15:40:58 -07008317 * A test API to reload the UICC profile.
8318 *
8319 * <p>Requires that the calling app has permission
8320 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8321 * @hide
8322 */
8323 @Override
8324 public void refreshUiccProfile(int subId) {
8325 enforceModifyPermission();
8326
8327 final long identity = Binder.clearCallingIdentity();
8328 try {
8329 Phone phone = getPhone(subId);
8330 if (phone == null) {
8331 return;
8332 }
8333 UiccCard uiccCard = phone.getUiccCard();
8334 if (uiccCard == null) {
8335 return;
8336 }
8337 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8338 if (uiccProfile == null) {
8339 return;
8340 }
8341 uiccProfile.refresh();
8342 } finally {
8343 Binder.restoreCallingIdentity(identity);
8344 }
8345 }
8346
8347 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008348 * Returns false if the mobile data is disabled by default, otherwise return true.
8349 */
8350 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008351 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008352 }
8353
8354 /**
8355 * Returns true if the data roaming is enabled by default, i.e the system property
8356 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8357 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8358 */
8359 private boolean getDefaultDataRoamingEnabled(int subId) {
8360 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008361 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07008362 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008363 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8364 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8365 return isDataRoamingEnabled;
8366 }
8367
8368 /**
8369 * Returns the default network type for the given {@code subId}, if the default network type is
8370 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8371 */
8372 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09008373 List<Integer> list = TelephonyProperties.default_network();
8374 int phoneId = mSubscriptionController.getPhoneId(subId);
8375 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8376 return list.get(phoneId);
8377 }
8378 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008379 }
fionaxua13278b2018-03-21 00:08:13 -07008380
8381 @Override
8382 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008383 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008384 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008385
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 final Phone phone = getPhone(subId);
8389 if (phone == null) {
8390 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8391 return;
8392 }
chen xueaba88a2019-03-15 13:15:10 -07008393 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8394 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07008395 if (carrierPrivilegeRules == null) {
8396 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8397 } else {
8398 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008400 } finally {
8401 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008402 }
fionaxua13278b2018-03-21 00:08:13 -07008403 }
8404
8405 @Override
8406 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008407 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008408
8409 final long identity = Binder.clearCallingIdentity();
8410 try {
8411 final Phone phone = getPhone(subId);
8412 if (phone == null) {
8413 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8414 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8415 }
8416 return phone.getCarrierIdListVersion();
8417 } finally {
8418 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008419 }
fionaxua13278b2018-03-21 00:08:13 -07008420 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008421
8422 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008423 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8424 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008425 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008426 mApp, subId, callingPackage, callingFeatureId,
8427 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008428 return -1;
8429 }
8430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008438
8439 @Override
8440 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08008441 TelephonyPermissions
8442 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008443 mApp, subId, "getCdmaRoamingMode");
8444
8445 final long identity = Binder.clearCallingIdentity();
8446 try {
8447 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
8450 }
8451 }
8452
8453 @Override
8454 public boolean setCdmaRoamingMode(int subId, int mode) {
8455 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8456 mApp, subId, "setCdmaRoamingMode");
8457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
8466 @Override
Sarah Chinbaab1432020-10-28 13:46:24 -07008467 public int getCdmaSubscriptionMode(int subId) {
8468 TelephonyPermissions
8469 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8470 mApp, subId, "getCdmaSubscriptionMode");
8471
8472 final long identity = Binder.clearCallingIdentity();
8473 try {
8474 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8475 } finally {
8476 Binder.restoreCallingIdentity(identity);
8477 }
8478 }
8479
8480 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008481 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8482 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8483 mApp, subId, "setCdmaSubscriptionMode");
8484
8485 final long identity = Binder.clearCallingIdentity();
8486 try {
8487 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008492
sqianc5eccab2018-10-19 18:46:41 -07008493 @Override
sqian8c685422019-02-22 15:55:18 -08008494 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008495 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008496 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008497 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8498 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008499 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8500 }
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
sqian854d44b2018-12-12 16:48:18 -08008503 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8504 for (Phone phone: PhoneFactory.getPhones()) {
8505 if (phone.getEmergencyNumberTracker() != null
8506 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8507 emergencyNumberListInternal.put(
8508 phone.getSubId(),
8509 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8510 }
sqian11b7a0e2018-12-05 18:48:28 -08008511 }
sqian854d44b2018-12-12 16:48:18 -08008512 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008513 } finally {
8514 Binder.restoreCallingIdentity(identity);
8515 }
sqianc5eccab2018-10-19 18:46:41 -07008516 }
8517
8518 @Override
sqian8c685422019-02-22 15:55:18 -08008519 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008520 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008521 if (!exactMatch) {
8522 TelephonyPermissions
8523 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008524 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008525 }
8526 final long identity = Binder.clearCallingIdentity();
8527 try {
sqian854d44b2018-12-12 16:48:18 -08008528 for (Phone phone: PhoneFactory.getPhones()) {
8529 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008530 && phone.getEmergencyNumberTracker()
8531 .isEmergencyNumber(number, exactMatch)) {
8532 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008533 }
sqian11b7a0e2018-12-05 18:48:28 -08008534 }
8535 return false;
8536 } finally {
8537 Binder.restoreCallingIdentity(identity);
8538 }
8539 }
8540
sqianf4ca7ed2019-01-15 18:32:07 -08008541 /**
8542 * Update emergency number list for test mode.
8543 */
8544 @Override
8545 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8546 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8547 "updateEmergencyNumberListTestMode");
8548
8549 final long identity = Binder.clearCallingIdentity();
8550 try {
8551 for (Phone phone: PhoneFactory.getPhones()) {
8552 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8553 if (tracker != null) {
8554 tracker.executeEmergencyNumberTestModeCommand(action, num);
8555 }
8556 }
8557 } finally {
8558 Binder.restoreCallingIdentity(identity);
8559 }
8560 }
8561
8562 /**
8563 * Get the full emergency number list for test mode.
8564 */
8565 @Override
8566 public List<String> getEmergencyNumberListTestMode() {
8567 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8568 "getEmergencyNumberListTestMode");
8569
8570 final long identity = Binder.clearCallingIdentity();
8571 try {
8572 Set<String> emergencyNumbers = new HashSet<>();
8573 for (Phone phone: PhoneFactory.getPhones()) {
8574 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8575 if (tracker != null) {
8576 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8577 emergencyNumbers.add(num.getNumber());
8578 }
8579 }
8580 }
8581 return new ArrayList<>(emergencyNumbers);
8582 } finally {
8583 Binder.restoreCallingIdentity(identity);
8584 }
8585 }
8586
chen xud6b45bd2018-10-30 22:27:10 -07008587 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08008588 public int getEmergencyNumberDbVersion(int subId) {
8589 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 final Phone phone = getPhone(subId);
8594 if (phone == null) {
8595 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8596 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8597 }
8598 return phone.getEmergencyNumberDbVersion();
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
8603
8604 @Override
8605 public void notifyOtaEmergencyNumberDbInstalled() {
8606 enforceModifyPermission();
8607
8608 final long identity = Binder.clearCallingIdentity();
8609 try {
8610 for (Phone phone: PhoneFactory.getPhones()) {
8611 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8612 if (tracker != null) {
8613 tracker.updateOtaEmergencyNumberDatabase();
8614 }
8615 }
8616 } finally {
8617 Binder.restoreCallingIdentity(identity);
8618 }
8619 }
8620
8621 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08008622 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08008623 enforceActiveEmergencySessionPermission();
8624
8625 final long identity = Binder.clearCallingIdentity();
8626 try {
8627 for (Phone phone: PhoneFactory.getPhones()) {
8628 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8629 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008630 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8631 }
8632 }
8633 } finally {
8634 Binder.restoreCallingIdentity(identity);
8635 }
8636 }
8637
8638 @Override
8639 public void resetOtaEmergencyNumberDbFilePath() {
8640 enforceActiveEmergencySessionPermission();
8641
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 for (Phone phone: PhoneFactory.getPhones()) {
8645 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8646 if (tracker != null) {
8647 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008648 }
8649 }
8650 } finally {
8651 Binder.restoreCallingIdentity(identity);
8652 }
8653 }
8654
8655 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008656 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8657 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8658 Phone phone = getPhone(subId);
8659 if (phone == null) {
8660 return null;
8661 }
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 UiccProfile profile = UiccController.getInstance()
8665 .getUiccProfileForPhone(phone.getPhoneId());
8666 if (profile != null) {
8667 return profile.getCertsFromCarrierPrivilegeAccessRules();
8668 }
8669 } finally {
8670 Binder.restoreCallingIdentity(identity);
8671 }
8672 return null;
8673 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008674
8675 /**
8676 * Enable or disable a modem stack.
8677 */
8678 @Override
8679 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8680 enforceModifyPermission();
8681
8682 final long identity = Binder.clearCallingIdentity();
8683 try {
8684 Phone phone = PhoneFactory.getPhone(slotIndex);
8685 if (phone == null) {
8686 return false;
8687 } else {
8688 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8689 }
8690 } finally {
8691 Binder.restoreCallingIdentity(identity);
8692 }
8693 }
Michelecea4cf22018-12-21 15:00:11 -08008694
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008695 /**
8696 * Whether a modem stack is enabled or not.
8697 */
8698 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008699 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8700 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008701 Phone phone = PhoneFactory.getPhone(slotIndex);
8702 if (phone == null) return false;
8703
8704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008705 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8706 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008707 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8708 }
8709
8710 final long identity = Binder.clearCallingIdentity();
8711 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008712 try {
8713 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8714 } catch (NoSuchElementException ex) {
8715 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8716 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
Michelecea4cf22018-12-21 15:00:11 -08008722 @Override
Michele0ea7d782019-03-19 14:58:42 -07008723 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008724 enforceModifyPermission();
8725
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008729 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008730 .commit();
8731 } finally {
8732 Binder.restoreCallingIdentity(identity);
8733 }
8734 }
8735
8736 @Override
Michele0ea7d782019-03-19 14:58:42 -07008737 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008738 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008739 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008740 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8741 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008742 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008743 }
Michelecea4cf22018-12-21 15:00:11 -08008744
8745 final long identity = Binder.clearCallingIdentity();
8746 try {
Michele0ea7d782019-03-19 14:58:42 -07008747 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008748 } finally {
8749 Binder.restoreCallingIdentity(identity);
8750 }
8751 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008752
Michele0ea7d782019-03-19 14:58:42 -07008753 @TelephonyManager.IsMultiSimSupportedResult
8754 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008755 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8756 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8757 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008758 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8759 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008760 }
8761 // Check if the hardware supports multisim functionality. If usage of multisim is not
8762 // supported by the modem, indicate that it is restricted.
8763 PhoneCapability staticCapability =
8764 mPhoneConfigurationManager.getStaticPhoneCapability();
8765 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008766 loge("isMultiSimSupportedInternal: no static configuration available");
8767 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008768 }
Sarah Chin7caee492020-02-18 20:49:02 +00008769 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008770 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8771 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008772 }
8773 // Check if support of multiple SIMs is restricted by carrier
8774 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008775 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008776 }
8777
Michele0ea7d782019-03-19 14:58:42 -07008778 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008779 }
8780
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008781 /**
8782 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008783 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8784 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8785 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 * @param numOfSims number of active sims we want to switch to
8787 */
8788 @Override
8789 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008790 if (numOfSims == 1) {
8791 enforceModifyPermission();
8792 } else {
8793 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8794 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8795 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008796 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008797
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008798 try {
Michele30b57b22019-03-01 12:01:14 -08008799 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008800 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008801 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8802 return;
8803 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008804 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8805 } finally {
8806 Binder.restoreCallingIdentity(identity);
8807 }
8808 }
8809
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008810 @Override
8811 public boolean isApplicationOnUicc(int subId, int appType) {
8812 enforceReadPrivilegedPermission("isApplicationOnUicc");
8813 Phone phone = getPhone(subId);
8814 if (phone == null) {
8815 return false;
8816 }
8817 final long identity = Binder.clearCallingIdentity();
8818 try {
8819 UiccCard uiccCard = phone.getUiccCard();
8820 if (uiccCard == null) {
8821 return false;
8822 }
8823 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8824 if (uiccProfile == null) {
8825 return false;
8826 }
8827 if (TelephonyManager.APPTYPE_SIM <= appType
8828 && appType <= TelephonyManager.APPTYPE_ISIM) {
8829 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8830 }
8831 return false;
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
8835 }
8836
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008837 /**
chen xub4baa772019-04-03 10:23:41 -07008838 * Get whether making changes to modem configurations will trigger reboot.
8839 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008840 */
8841 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008842 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8843 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008845 mApp, subId, callingPackage, callingFeatureId,
8846 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008847 return false;
8848 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8852 } finally {
8853 Binder.restoreCallingIdentity(identity);
8854 }
8855 }
8856
Nathan Harold29f5f052019-02-15 13:41:57 -08008857 private void updateModemStateMetrics() {
8858 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8859 // TODO: check the state for each modem if the api is ready.
8860 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8861 }
8862
Pengquan Meng3889a572019-01-23 11:16:29 -08008863 @Override
8864 public int[] getSlotsMapping() {
8865 enforceReadPrivilegedPermission("getSlotsMapping");
8866
8867 final long identity = Binder.clearCallingIdentity();
8868 try {
8869 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8870 // All logical slots should have a mapping to a physical slot.
8871 int[] logicalSlotsMapping = new int[phoneCount];
8872 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8873 for (int i = 0; i < slotInfos.length; i++) {
8874 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8875 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8876 }
8877 }
8878 return logicalSlotsMapping;
8879 } finally {
8880 Binder.restoreCallingIdentity(identity);
8881 }
8882 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008883
8884 /**
8885 * Get the IRadio HAL Version
8886 */
8887 @Override
8888 public int getRadioHalVersion() {
8889 Phone phone = getDefaultPhone();
8890 if (phone == null) return -1;
8891 HalVersion hv = phone.getHalVersion();
8892 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8893 return hv.major * 100 + hv.minor;
8894 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008895
8896 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008897 * Get the current calling package name.
8898 * @return the current calling package name
8899 */
8900 @Override
8901 public String getCurrentPackageName() {
8902 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8903 }
8904
8905 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008906 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8907 * corresponding network requests on a subId.
8908 *
8909 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008910 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 * 2) APN is un-metered for this subscription, or
8912 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liu746e03c2020-09-25 11:13:49 -07008913 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008914 *
8915 * @return whether data is allowed for a apn type.
8916 *
8917 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008918 */
8919 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008920 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008921 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8922 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008923
8924 // Now that all security checks passes, perform the operation as ourselves.
8925 final long identity = Binder.clearCallingIdentity();
8926 try {
8927 Phone phone = getPhone(subId);
8928 if (phone == null) return false;
8929
Jack Yu41407ee2019-05-13 16:54:09 -07008930 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008931 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8932 } finally {
8933 Binder.restoreCallingIdentity(identity);
8934 }
8935 }
8936
8937 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008938 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008939 enforceReadPrivilegedPermission("isApnMetered");
8940
8941 // Now that all security checks passes, perform the operation as ourselves.
8942 final long identity = Binder.clearCallingIdentity();
8943 try {
8944 Phone phone = getPhone(subId);
8945 if (phone == null) return true; // By default return true.
8946
Jack Yu41407ee2019-05-13 16:54:09 -07008947 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008948 } finally {
8949 Binder.restoreCallingIdentity(identity);
8950 }
8951 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008952
8953 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008954 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8955 int subscriptionId, IBooleanConsumer resultCallback) {
8956 enforceModifyPermission();
8957 long token = Binder.clearCallingIdentity();
8958 try {
8959 Phone phone = getPhone(subscriptionId);
8960 if (phone == null) {
8961 try {
8962 if (resultCallback != null) {
8963 resultCallback.accept(false);
8964 }
8965 } catch (RemoteException e) {
8966 // ignore
8967 }
8968 return;
8969 }
8970 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8971 Pair.create(specifiers, (x) -> {
8972 try {
8973 if (resultCallback != null) {
8974 resultCallback.accept(x);
8975 }
8976 } catch (RemoteException e) {
8977 // ignore
8978 }
8979 });
8980 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8981 } finally {
8982 Binder.restoreCallingIdentity(token);
8983 }
8984 }
8985
8986 @Override
Sarah Chin679c08a2020-11-18 13:39:35 -08008987 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8988 TelephonyPermissions
8989 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8990 mApp, subId, "getSystemSelectionChannels");
8991 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8992 final long identity = Binder.clearCallingIdentity();
8993 try {
8994 List<RadioAccessSpecifier> specifiers =
8995 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8996 null, subId, workSource);
8997 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8998 return specifiers;
8999 } finally {
9000 Binder.restoreCallingIdentity(identity);
9001 }
9002 }
9003
9004 @Override
changbetty7157e9e2019-12-06 18:16:37 +08009005 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009006 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08009007 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9008 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9009 if (iccRecords == null) {
9010 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9011 return false;
9012 }
9013 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9014 }
9015
9016 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009017 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9018 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08009019 if (callingPackage == null) {
9020 callingPackage = getCurrentPackageName();
9021 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009022 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9023 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07009024 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9025 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009026 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9027 }
9028 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9029 Intent intent = new Intent();
9030 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9031 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9032 // Bring up choose default SMS subscription dialog right now
9033 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9034 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9035 mApp.startActivity(intent);
9036 }
chen xud5ca2d52019-05-28 15:20:57 -07009037
9038 @Override
9039 public String getMmsUAProfUrl(int subId) {
9040 //TODO investigate if this API should require proper permission check in R b/133791609
9041 final long identity = Binder.clearCallingIdentity();
9042 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009043 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9044 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9045 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9046 return carrierUAProfUrl;
9047 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009048 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9049 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07009050 } finally {
9051 Binder.restoreCallingIdentity(identity);
9052 }
9053 }
9054
9055 @Override
9056 public String getMmsUserAgent(int subId) {
9057 //TODO investigate if this API should require proper permission check in R b/133791609
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009060 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9061 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9062 if (!TextUtils.isEmpty(carrierUserAgent)) {
9063 return carrierUserAgent;
9064 }
Daniel Brightebb4eb72020-02-18 15:16:33 -08009065 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9066 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07009067 } finally {
9068 Binder.restoreCallingIdentity(identity);
9069 }
9070 }
Jack Yub07d4972019-05-28 16:12:25 -07009071
9072 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009073 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9074 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
Jack Yub07d4972019-05-28 16:12:25 -07009075
Jack Yub07d4972019-05-28 16:12:25 -07009076 final long identity = Binder.clearCallingIdentity();
9077 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009078 Phone phone = getPhone(subscriptionId);
Jack Yub07d4972019-05-28 16:12:25 -07009079 if (phone == null) return false;
9080
Hall Liua62f5da2020-09-25 10:42:19 -07009081 switch (policy) {
9082 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9083 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9084 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9085 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9086 default:
9087 throw new IllegalArgumentException(policy + " is not a valid policy");
9088 }
Jack Yub07d4972019-05-28 16:12:25 -07009089 } finally {
9090 Binder.restoreCallingIdentity(identity);
9091 }
9092 }
9093
9094 @Override
Hall Liua62f5da2020-09-25 10:42:19 -07009095 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9096 boolean enabled) {
changbettyd5c246e2019-12-24 15:40:37 +08009097 enforceModifyPermission();
9098
changbettyd5c246e2019-12-24 15:40:37 +08009099 final long identity = Binder.clearCallingIdentity();
9100 try {
Hall Liua62f5da2020-09-25 10:42:19 -07009101 Phone phone = getPhone(subscriptionId);
9102 if (phone == null) return;
changbettyd5c246e2019-12-24 15:40:37 +08009103
Hall Liua62f5da2020-09-25 10:42:19 -07009104 switch (policy) {
9105 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9106 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9107 break;
9108 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9109 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9110 break;
9111 default:
9112 throw new IllegalArgumentException(policy + " is not a valid policy");
9113 }
changbettyd5c246e2019-12-24 15:40:37 +08009114 } finally {
9115 Binder.restoreCallingIdentity(identity);
9116 }
9117 }
9118
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009119 /**
Hall Liu746e03c2020-09-25 11:13:49 -07009120 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009121 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9122 * otherwise.
9123 */
9124 @Override
9125 public void setCepEnabled(boolean isCepEnabled) {
9126 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9127
9128 final long identity = Binder.clearCallingIdentity();
9129 try {
9130 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9131 for (Phone phone : PhoneFactory.getPhones()) {
9132 Phone defaultPhone = phone.getImsPhone();
9133 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9134 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9135 ImsPhoneCallTracker imsPhoneCallTracker =
9136 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9137 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9138 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9139 + imsPhone.getMsisdn());
9140 }
9141 }
9142 } finally {
9143 Binder.restoreCallingIdentity(identity);
9144 }
9145 }
allenwtsu46dcc572020-01-08 18:24:03 +08009146
9147 /**
9148 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9149 *
9150 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9151 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9152 * before being read.
9153 */
9154 @Override
9155 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9156 isCompressed) {
9157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9158 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang761a6682020-10-31 05:12:53 +00009159 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9160 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9161 }
9162 if (!isImsAvailableOnDevice()) {
9163 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9164 "IMS not available on device.");
9165 }
9166
9167 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009168 try {
Hui Wang761a6682020-10-31 05:12:53 +00009169 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009172 }
9173 }
zoey chene02881a2019-12-30 16:11:23 +08009174
9175 @Override
9176 public boolean isIccLockEnabled(int subId) {
9177 enforceReadPrivilegedPermission("isIccLockEnabled");
9178
9179 // Now that all security checks passes, perform the operation as ourselves.
9180 final long identity = Binder.clearCallingIdentity();
9181 try {
9182 Phone phone = getPhone(subId);
9183 if (phone != null && phone.getIccCard() != null) {
9184 return phone.getIccCard().getIccLockEnabled();
9185 } else {
9186 return false;
9187 }
9188 } finally {
9189 Binder.restoreCallingIdentity(identity);
9190 }
9191 }
9192
9193 /**
9194 * Set the ICC pin lock enabled or disabled.
9195 *
9196 * @return an integer representing the status of IccLock enabled or disabled in the following
9197 * three cases:
9198 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9199 * successfully.
9200 * - Positive number and zero for remaining password attempts.
9201 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9202 *
9203 */
9204 @Override
9205 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9206 enforceModifyPermission();
9207
9208 Phone phone = getPhone(subId);
9209 if (phone == null) {
9210 return 0;
9211 }
9212 // Now that all security checks passes, perform the operation as ourselves.
9213 final long identity = Binder.clearCallingIdentity();
9214 try {
9215 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9216 new Pair<Boolean, String>(enabled, password), phone, null);
9217 return attemptsRemaining;
9218
9219 } catch (Exception e) {
9220 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9221 } finally {
9222 Binder.restoreCallingIdentity(identity);
9223 }
9224 return 0;
9225 }
9226
9227 /**
9228 * Change the ICC password used in ICC pin lock.
9229 *
9230 * @return an integer representing the status of IccLock changed in the following three cases:
9231 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9232 * - Positive number and zero for remaining password attempts.
9233 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
9234 *
9235 */
9236 @Override
9237 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9238 enforceModifyPermission();
9239
9240 Phone phone = getPhone(subId);
9241 if (phone == null) {
9242 return 0;
9243 }
9244 // Now that all security checks passes, perform the operation as ourselves.
9245 final long identity = Binder.clearCallingIdentity();
9246 try {
9247 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9248 new Pair<String, String>(oldPassword, newPassword), phone, null);
9249 return attemptsRemaining;
9250
9251 } catch (Exception e) {
9252 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9253 } finally {
9254 Binder.restoreCallingIdentity(identity);
9255 }
9256 return 0;
9257 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08009258
9259 /**
9260 * Request for receiving user activity notification
9261 */
9262 @Override
9263 public void requestUserActivityNotification() {
9264 if (!mNotifyUserActivity.get()
9265 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9266 mNotifyUserActivity.set(true);
9267 }
9268 }
9269
9270 /**
9271 * Called when userActivity is signalled in the power manager.
9272 * This is safe to call from any thread, with any window manager locks held or not.
9273 */
9274 @Override
9275 public void userActivity() {
9276 // ***************************************
9277 // * Inherited from PhoneWindowManager *
9278 // ***************************************
9279 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9280 // WITH ITS LOCKS HELD.
9281 //
9282 // This code must be VERY careful about the locks
9283 // it acquires.
9284 // In fact, the current code acquires way too many,
9285 // and probably has lurking deadlocks.
9286
9287 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9288 throw new SecurityException("Only the OS may call notifyUserActivity()");
9289 }
9290
9291 if (mNotifyUserActivity.getAndSet(false)) {
9292 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9293 USER_ACTIVITY_NOTIFICATION_DELAY);
9294 }
9295 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009296
9297 @Override
9298 public boolean canConnectTo5GInDsdsMode() {
9299 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9300 }
Jack Yud10cdd42020-09-28 20:28:01 -07009301
9302 @Override
9303 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9304 String callingFeatureId) {
9305 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9306 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9307 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9308 }
9309
9310 Phone phone = getPhone(subId);
9311 if (phone == null) {
9312 throw new RuntimeException("phone is not available");
9313 }
9314 // Now that all security checks passes, perform the operation as ourselves.
9315 final long identity = Binder.clearCallingIdentity();
9316 try {
9317 return phone.getEquivalentHomePlmns();
9318 } finally {
9319 Binder.restoreCallingIdentity(identity);
9320 }
9321 }
Daniel Bright59e67312020-11-13 11:49:37 -08009322
9323 @Override
9324 public boolean isRadioInterfaceCapabilitySupported(
9325 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9326 RadioInterfaceCapabilities radioInterfaceCapabilities =
9327 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9328 if (radioInterfaceCapabilities == null) {
9329 throw new RuntimeException("radio interface capabilities are not available");
9330 } else {
9331 return radioInterfaceCapabilities.isSupported(capability);
9332 }
9333 }
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009334
Hui Wang641e81c2020-10-12 12:14:23 -07009335 @Override
9336 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9337 UaSecurityProtocolIdentifier securityProtocol,
9338 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9339 throws RemoteException {
9340 enforceModifyPermission();
9341 if (DBG) {
9342 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9343 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9344 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9345 }
9346
9347 if (!SubscriptionManager.isValidSubscriptionId(subId)
9348 || appType < TelephonyManager.APPTYPE_UNKNOWN
9349 || appType > TelephonyManager.APPTYPE_ISIM
9350 || nafUrl == null || securityProtocol == null || callback == null) {
9351 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9352 if (callback != null) {
9353 try {
9354 callback.onAuthenticationFailure(
9355 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9356 } catch (RemoteException exception) {
9357 log("Fail to notify onAuthenticationFailure due to " + exception);
9358 }
9359 return;
9360 }
9361 }
9362
9363 final long token = Binder.clearCallingIdentity();
9364 try {
9365 getGbaManager(subId).bootstrapAuthenticationRequest(
9366 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9367 forceBootStrapping, callback));
9368 } finally {
9369 Binder.restoreCallingIdentity(token);
9370 }
9371 }
9372
Jack Nudelmanb0b87642020-11-12 15:04:39 -08009373 /**
9374 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9375 * requested radio power state will actually be set. See {@link
9376 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9377 *
9378 * @param subId the subscription ID of the phone requesting to set the radio power state.
9379 * @param enable {@code true} if trying to turn radio on.
9380 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9381 * false}.
9382 */
9383 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9384 Phone phone = getPhone(subId);
9385 if (phone != null) {
9386 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9387 return true;
9388 }
9389 return false;
9390 }
9391
9392 private int handleDataThrottlingRequest(int subId,
9393 DataThrottlingRequest dataThrottlingRequest) {
9394 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9395 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9396 if (!setRadioPowerForThermal(subId, true)) {
9397 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9398 }
9399
9400 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9401
9402 int thermalMitigationResult =
9403 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9404 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9405 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9406 }
9407 return thermalMitigationResult;
9408 }
9409
9410 /**
9411 * Thermal mitigation request to control functionalities at modem.
9412 *
9413 * @param subId the id of the subscription.
9414 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9415 *
9416 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9417 */
9418 @Override
9419 @ThermalMitigationResult
9420 public int sendThermalMitigationRequest(
9421 int subId,
9422 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9423 enforceModifyPermission();
9424
9425 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9426 final long identity = Binder.clearCallingIdentity();
9427
9428 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9429 try {
9430 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9431 switch (thermalMitigationAction) {
9432 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9433 thermalMitigationResult =
9434 handleDataThrottlingRequest(subId,
9435 thermalMitigationRequest.getDataThrottlingRequest());
9436 break;
9437 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9438 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9439 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9440 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9441 }
9442
9443 // Ensure that radio is on. If not able to power on due to phone being
9444 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9445 if (!setRadioPowerForThermal(subId, true)) {
9446 thermalMitigationResult =
9447 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9448 break;
9449 }
9450
9451 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9452 false);
9453 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9454 break;
9455 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9456 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9457 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9458 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9459 }
9460
9461 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9462 if (registry != null) {
9463 TelephonyConnectionService service =
9464 registry.getTelephonyConnectionService();
9465 Phone phone = getPhone(subId);
9466 if (phone == null) {
9467 thermalMitigationResult =
9468 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9469 break;
9470 }
9471
9472 if (PhoneConstantConversions.convertCallState(phone.getState())
9473 != TelephonyManager.CALL_STATE_IDLE
9474 || phone.isInEmergencySmsMode() || phone.isInEcm()
9475 || (service != null && service.isEmergencyCallPending())) {
9476 String errorMessage = "Phone state is not valid. call state = "
9477 + PhoneConstantConversions.convertCallState(phone.getState())
9478 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9479 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9480 errorMessage += service == null
9481 ? " TelephonyConnectionService is null"
9482 : " isEmergencyCallPending = "
9483 + service.isEmergencyCallPending();
9484 Log.e(LOG_TAG, errorMessage);
9485 thermalMitigationResult =
9486 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9487 break;
9488 }
9489 } else {
9490 thermalMitigationResult =
9491 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9492 break;
9493 }
9494
9495 // Turn radio off. If not able to power off due to phone being unavailable,
9496 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9497 if (!setRadioPowerForThermal(subId, false)) {
9498 thermalMitigationResult =
9499 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9500 break;
9501 }
9502 thermalMitigationResult =
9503 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9504 break;
9505 default:
9506 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9507 + "not exist. Requested action: " + thermalMitigationAction);
9508 }
9509 } catch (IllegalArgumentException e) {
9510 throw e;
9511 } catch (Exception e) {
9512 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9513 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9514 } finally {
9515 Binder.restoreCallingIdentity(identity);
9516 }
9517
9518 if (DBG) {
9519 log("thermalMitigationRequest returning with thermalMitigationResult: "
9520 + thermalMitigationResult);
9521 }
9522
9523 return thermalMitigationResult;
9524 }
Hui Wang641e81c2020-10-12 12:14:23 -07009525
9526 /**
9527 * Set the GbaService Package Name that Telephony will bind to.
9528 *
9529 * @param subId The sim that the GbaService is associated with.
9530 * @param packageName The name of the package to be replaced with.
9531 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9532 */
9533 @Override
9534 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9535 enforceModifyPermission();
9536
9537 final long identity = Binder.clearCallingIdentity();
9538 try {
9539 return getGbaManager(subId).overrideServicePackage(packageName);
9540 } finally {
9541 Binder.restoreCallingIdentity(identity);
9542 }
9543 }
9544
9545 /**
9546 * Return the package name of the currently bound GbaService.
9547 *
9548 * @param subId The sim that the GbaService is associated with.
9549 * @return the package name of the GbaService configuration, null if GBA is not supported.
9550 */
9551 @Override
9552 public String getBoundGbaService(int subId) {
9553 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9554
9555 final long identity = Binder.clearCallingIdentity();
9556 try {
9557 return getGbaManager(subId).getServicePackage();
9558 } finally {
9559 Binder.restoreCallingIdentity(identity);
9560 }
9561 }
9562
9563 /**
9564 * Set the release time for telephony to unbind GbaService.
9565 *
9566 * @param subId The sim that the GbaService is associated with.
9567 * @param interval The release time to unbind GbaService by millisecond.
9568 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9569 */
9570 @Override
9571 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9572 enforceModifyPermission();
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 return getGbaManager(subId).overrideReleaseTime(interval);
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
9580 }
9581
9582 /**
9583 * Return the release time for telephony to unbind GbaService.
9584 *
9585 * @param subId The sim that the GbaService is associated with.
9586 * @return The release time to unbind GbaService by millisecond.
9587 */
9588 @Override
9589 public int getGbaReleaseTime(int subId) {
9590 enforceReadPrivilegedPermission("getGbaReleaseTime");
9591
9592 final long identity = Binder.clearCallingIdentity();
9593 try {
9594 return getGbaManager(subId).getReleaseTime();
9595 } finally {
9596 Binder.restoreCallingIdentity(identity);
9597 }
9598 }
9599
9600 private GbaManager getGbaManager(int subId) {
9601 GbaManager instance = GbaManager.getInstance(subId);
9602 if (instance == null) {
9603 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9604 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9605 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9606 }
9607 return instance;
9608 }
Hui Wang761a6682020-10-31 05:12:53 +00009609
9610 /**
9611 * indicate whether the device and the carrier can support
9612 * RCS VoLTE single registration.
9613 */
9614 @Override
9615 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9616 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9617
9618 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9619 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9620 }
9621
9622 final long identity = Binder.clearCallingIdentity();
9623 try {
9624 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9625 if (rpm != null) {
9626 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9627 }
9628 return false;
9629 } finally {
9630 Binder.restoreCallingIdentity(identity);
9631 }
9632 }
9633
9634 /**
9635 * Register RCS provisioning callback.
9636 */
9637 @Override
9638 public void registerRcsProvisioningChangedCallback(int subId,
9639 IRcsConfigCallback callback) {
9640 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9641
9642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9643 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9644 }
9645 if (!isImsAvailableOnDevice()) {
9646 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9647 "IMS not available on device.");
9648 }
9649
9650 final long identity = Binder.clearCallingIdentity();
9651 try {
9652 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9653 .addRcsProvisioningCallbackForSubscription(callback, subId);
9654 } catch (ImsException e) {
9655 throw new ServiceSpecificException(e.getCode());
9656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
9660
9661 /**
9662 * Unregister RCS provisioning callback.
9663 */
9664 @Override
9665 public void unregisterRcsProvisioningChangedCallback(int subId,
9666 IRcsConfigCallback callback) {
9667 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9668
9669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9670 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9671 }
9672 if (!isImsAvailableOnDevice()) {
9673 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9674 "IMS not available on device.");
9675 }
9676
9677 final long identity = Binder.clearCallingIdentity();
9678 try {
9679 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9680 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9681 } catch (ImsException e) {
9682 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9683 + "is inactive, ignoring unregister.");
9684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
9687 }
9688
9689 /**
9690 * trigger RCS reconfiguration.
9691 */
9692 public void triggerRcsReconfiguration(int subId) {
9693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9694 mApp, subId, "triggerRcsReconfiguration");
9695
9696 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9697 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9698 }
9699 if (!isImsAvailableOnDevice()) {
9700 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9701 "IMS not available on device.");
9702 }
9703
9704 final long identity = Binder.clearCallingIdentity();
9705 try {
9706 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9707 } finally {
9708 Binder.restoreCallingIdentity(identity);
9709 }
9710 }
9711
9712 /**
9713 * Provide the client configuration parameters of the RCS application.
9714 */
9715 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9716 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9717 mApp, subId, "setRcsClientConfiguration");
9718
9719 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9720 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9721 }
9722 if (!isImsAvailableOnDevice()) {
9723 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9724 "IMS not available on device.");
9725 }
9726
9727 final long identity = Binder.clearCallingIdentity();
9728
9729 try {
9730 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9731 if (configBinder == null) {
9732 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9733 } else {
9734 configBinder.setRcsClientConfiguration(rcc);
9735 }
9736 } catch (RemoteException e) {
9737 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9738 } finally {
9739 Binder.restoreCallingIdentity(identity);
9740 }
9741 }
9742
9743 /**
9744 * Overrides the config of RCS VoLTE single registration enabled for the device.
9745 */
9746 @Override
9747 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9748 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9749 "setDeviceSingleRegistrationEnabledOverride");
9750 enforceModifyPermission();
9751
9752 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9753 : Boolean.parseBoolean(enabledStr);
9754 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9755 }
9756
9757 /**
9758 * Gets the config of RCS VoLTE single registration enabled for the device.
9759 */
9760 @Override
9761 public boolean getDeviceSingleRegistrationEnabled() {
9762 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9763 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9764 }
9765
9766 /**
9767 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9768 */
9769 @Override
9770 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9771 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9772 "setCarrierSingleRegistrationEnabledOverride");
9773 enforceModifyPermission();
9774
9775 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9776 : Boolean.parseBoolean(enabledStr);
9777 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9778 subId, enabled);
9779 }
9780
9781 /**
9782 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9783 */
9784 @Override
9785 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9786 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9787 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9788 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009789
9790 /**
9791 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9792 * their mobile plan.
9793 */
9794 @Override
9795 public String getMobileProvisioningUrl() {
9796 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9797 final long identity = Binder.clearCallingIdentity();
9798 try {
9799 return getDefaultPhone().getMobileProvisioningUrl();
9800 } finally {
9801 Binder.restoreCallingIdentity(identity);
9802 }
9803 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009804}