blob: 796efd068975d9a6460501c7e06d6eefa78f6dfb [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080067import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
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 Nudelman24d51a52020-11-24 12:08:04 -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 Wang0866fcc2020-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 Wang068ab862020-10-31 05:12:53 +0000110import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-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 Wang068ab862020-10-31 05:12:53 +0000117import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-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 Liuaa4283b2020-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;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -0800138import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-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 Liud0d1dc92020-01-20 13:42:00 -0800142import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900172import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-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 chen84e2b212019-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 Liua1acea22020-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 Nudelman24d51a52020-11-24 12:08:04 -0800191import com.android.services.telephony.TelecomAccountRegistry;
192import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-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 Liud0d1dc92020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 chenf95ca592019-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 Liud0d1dc92020-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;
sqian80370722020-01-29 15:02:51 -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 Sasindranb4a99602020-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 Chin49f22af2020-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 Chincc055732020-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 Nudelman24d51a52020-11-24 12:08:04 -0800312 private static final int CMD_SET_DATA_THROTTLING = 99;
313 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-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 Ebinger05f52c22019-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 Davidson0103e8c2020-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 Nudelman24d51a52020-11-24 12:08:04 -0800358 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
359
Derek Tan89e89d42014-07-08 17:00:10 -0700360 /**
Naina Nalluri8ff344d2019-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 Sasindranb4a99602020-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 Liua1acea22020-09-18 19:04:59 -0700944 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-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);
sqian80370722020-01-29 15:02:51 -0800952 break;
Hall Liua1acea22020-09-18 19:04:59 -0700953 }
954 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800955 ar = (AsyncResult) msg.obj;
956 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700957 TelephonyManager.CallForwardingInfoCallback callback =
958 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
959 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800960 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700961 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -0700968 callForwardingInfo = new CallForwardingInfo(true,
969 callForwardInfo.reason,
970 callForwardInfo.number,
971 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800972 break;
973 }
974 }
975 // Didn't find a call forward info for voice call.
976 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700977 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
978 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800979 }
Hall Liua1acea22020-09-18 19:04:59 -0700980 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -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 Liuae527aa2020-09-29 17:10:18 -0700988 int errorCode = TelephonyManager
989 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700994 errorCode = TelephonyManager
995 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800996 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700997 errorCode = TelephonyManager
998 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800999 }
1000 }
Hall Liua1acea22020-09-18 19:04:59 -07001001 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001002 }
sqian80370722020-01-29 15:02:51 -08001003 break;
Hall Liua1acea22020-09-18 19:04:59 -07001004 }
sqian80370722020-01-29 15:02:51 -08001005
Hall Liua1acea22020-09-18 19:04:59 -07001006 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001007 request = (MainThreadRequest) msg.obj;
1008 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001009 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001010 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-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,
sqian80370722020-01-29 15:02:51 -08001017 callForwardingInfoToSet.getReason(),
1018 callForwardingInfoToSet.getNumber(),
1019 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1020 break;
Hall Liua1acea22020-09-18 19:04:59 -07001021 }
sqian80370722020-01-29 15:02:51 -08001022
Hall Liua1acea22020-09-18 19:04:59 -07001023 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001024 ar = (AsyncResult) msg.obj;
1025 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001026 Consumer<Integer> callback =
1027 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1028 request.argument).second;
1029 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001030 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001031 int errorCode = TelephonyManager.CallForwardingInfoCallback
1032 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-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 Liuae527aa2020-09-29 17:10:18 -07001037 errorCode = TelephonyManager.CallForwardingInfoCallback
1038 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001039 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001040 errorCode = TelephonyManager.CallForwardingInfoCallback
1041 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001042 }
1043 }
1044 callback.accept(errorCode);
1045 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001046 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001047 }
sqian80370722020-01-29 15:02:51 -08001048 break;
Hall Liua1acea22020-09-18 19:04:59 -07001049 }
sqian80370722020-01-29 15:02:51 -08001050
Hall Liua1acea22020-09-18 19:04:59 -07001051 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001052 request = (MainThreadRequest) msg.obj;
1053 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1054 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1055 break;
Hall Liua1acea22020-09-18 19:04:59 -07001056 }
sqian80370722020-01-29 15:02:51 -08001057
Hall Liua1acea22020-09-18 19:04:59 -07001058 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001059 ar = (AsyncResult) msg.obj;
1060 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001061 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -07001069 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001070 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001071 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1072 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001073 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001074 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -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 Liua1acea22020-09-18 19:04:59 -07001092 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001093 break;
Hall Liua1acea22020-09-18 19:04:59 -07001094 }
sqian80370722020-01-29 15:02:51 -08001095
Hall Liua1acea22020-09-18 19:04:59 -07001096 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001097 request = (MainThreadRequest) msg.obj;
1098 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001099 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1100 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001101 break;
Hall Liua1acea22020-09-18 19:04:59 -07001102 }
sqian80370722020-01-29 15:02:51 -08001103
Hall Liua1acea22020-09-18 19:04:59 -07001104 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001105 ar = (AsyncResult) msg.obj;
1106 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-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) {
sqian80370722020-01-29 15:02:51 -08001111 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-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);
sqian80370722020-01-29 15:02:51 -08001126 }
sqian80370722020-01-29 15:02:51 -08001127 break;
Hall Liua1acea22020-09-18 19:04:59 -07001128 }
sqian80370722020-01-29 15:02:51 -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);
sqian1a1be542020-03-05 11:37:28 -08001189 } else {
1190 ResultReceiver result = (ResultReceiver) request.argument;
1191 Bundle bundle = new Bundle();
1192 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1193 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1194 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001195 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001196 break;
1197
1198 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1199 ar = (AsyncResult) msg.obj;
1200 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001201 ResultReceiver result = (ResultReceiver) request.argument;
1202
1203 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001204 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001205 // Update the last modem activity info and the result of the request.
1206 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1207 if (isModemActivityInfoValid(info)) {
1208 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1209 int[] txTimeMs = info.getTransmitTimeMillis();
1210 int[] lastModemTxTimeMs = mLastModemActivityInfo
1211 .getTransmitTimeMillis();
1212 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1213 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1214 }
1215 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1216 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1217 + mLastModemActivityInfo.getSleepTimeMillis());
1218 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1219 + mLastModemActivityInfo.getIdleTimeMillis());
1220 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1221 mLastModemActivityInfo.setReceiveTimeMillis(
1222 info.getReceiveTimeMillis()
1223 + mLastModemActivityInfo.getReceiveTimeMillis());
1224 }
1225 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1226 mLastModemActivityInfo.getSleepTimeMillis(),
1227 mLastModemActivityInfo.getIdleTimeMillis(),
1228 mLastModemActivityInfo.getTransmitTimeMillis(),
1229 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001230 } else {
1231 if (ar.result == null) {
1232 loge("queryModemActivityInfo: Empty response");
1233 } else if (ar.exception instanceof CommandException) {
1234 loge("queryModemActivityInfo: CommandException: " +
1235 ar.exception);
1236 } else {
1237 loge("queryModemActivityInfo: Unknown exception");
1238 }
1239 }
sqian1a1be542020-03-05 11:37:28 -08001240 Bundle bundle = new Bundle();
1241 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1242 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001243 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001244 break;
1245
Meng Wang1a7c35a2016-05-05 20:56:15 -07001246 case CMD_SET_ALLOWED_CARRIERS:
1247 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001248 CarrierRestrictionRules argument =
1249 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001250 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001251 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001252 break;
1253
1254 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1255 ar = (AsyncResult) msg.obj;
1256 request = (MainThreadRequest) ar.userObj;
1257 if (ar.exception == null && ar.result != null) {
1258 request.result = ar.result;
1259 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001260 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1261 if (ar.exception instanceof CommandException) {
1262 loge("setAllowedCarriers: CommandException: " + ar.exception);
1263 CommandException.Error error =
1264 ((CommandException) (ar.exception)).getCommandError();
1265 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1266 request.result =
1267 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1268 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 } else {
1270 loge("setAllowedCarriers: Unknown exception");
1271 }
1272 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001273 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001274 break;
1275
1276 case CMD_GET_ALLOWED_CARRIERS:
1277 request = (MainThreadRequest) msg.obj;
1278 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001279 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 break;
1281
1282 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1283 ar = (AsyncResult) msg.obj;
1284 request = (MainThreadRequest) ar.userObj;
1285 if (ar.exception == null && ar.result != null) {
1286 request.result = ar.result;
1287 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001288 request.result = new IllegalStateException(
1289 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001290 if (ar.result == null) {
1291 loge("getAllowedCarriers: Empty response");
1292 } else if (ar.exception instanceof CommandException) {
1293 loge("getAllowedCarriers: CommandException: " +
1294 ar.exception);
1295 } else {
1296 loge("getAllowedCarriers: Unknown exception");
1297 }
1298 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001299 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001300 break;
1301
Nathan Haroldb3014052017-01-25 15:57:32 -08001302 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1303 ar = (AsyncResult) msg.obj;
1304 request = (MainThreadRequest) ar.userObj;
1305 if (ar.exception == null && ar.result != null) {
1306 request.result = ar.result;
1307 } else {
1308 request.result = new IllegalArgumentException(
1309 "Failed to retrieve Forbidden Plmns");
1310 if (ar.result == null) {
1311 loge("getForbiddenPlmns: Empty response");
1312 } else {
1313 loge("getForbiddenPlmns: Unknown exception");
1314 }
1315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001317 break;
1318
1319 case CMD_GET_FORBIDDEN_PLMNS:
1320 request = (MainThreadRequest) msg.obj;
1321 uiccCard = getUiccCardFromRequest(request);
1322 if (uiccCard == null) {
1323 loge("getForbiddenPlmns() UiccCard is null");
1324 request.result = new IllegalArgumentException(
1325 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001326 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001327 break;
1328 }
1329 Integer appType = (Integer) request.argument;
1330 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1331 if (uiccApp == null) {
1332 loge("getForbiddenPlmns() no app with specified type -- "
1333 + appType);
1334 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001335 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001336 break;
1337 } else {
1338 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1339 + " specified type -- " + appType);
1340 }
1341 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1342 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1343 onCompleted);
1344 break;
1345
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001346 case CMD_SWITCH_SLOTS:
1347 request = (MainThreadRequest) msg.obj;
1348 int[] physicalSlots = (int[]) request.argument;
1349 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1350 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1351 break;
1352
1353 case EVENT_SWITCH_SLOTS_DONE:
1354 ar = (AsyncResult) msg.obj;
1355 request = (MainThreadRequest) ar.userObj;
1356 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001357 notifyRequester(request);
1358 break;
1359 case CMD_GET_NETWORK_SELECTION_MODE:
1360 request = (MainThreadRequest) msg.obj;
1361 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1362 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1363 break;
1364
1365 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1366 ar = (AsyncResult) msg.obj;
1367 request = (MainThreadRequest) ar.userObj;
1368 if (ar.exception != null) {
1369 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1370 } else {
1371 int mode = ((int[]) ar.result)[0];
1372 if (mode == 0) {
1373 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1374 } else {
1375 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1376 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001377 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001378 notifyRequester(request);
1379 break;
1380 case CMD_GET_CDMA_ROAMING_MODE:
1381 request = (MainThreadRequest) msg.obj;
1382 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1383 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1384 break;
1385 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1386 ar = (AsyncResult) msg.obj;
1387 request = (MainThreadRequest) ar.userObj;
1388 if (ar.exception != null) {
1389 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1390 } else {
1391 request.result = ((int[]) ar.result)[0];
1392 }
1393 notifyRequester(request);
1394 break;
1395 case CMD_SET_CDMA_ROAMING_MODE:
1396 request = (MainThreadRequest) msg.obj;
1397 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1398 int mode = (int) request.argument;
1399 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1400 break;
1401 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 request.result = ar.exception == null;
1405 notifyRequester(request);
1406 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001407 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1408 request = (MainThreadRequest) msg.obj;
1409 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1410 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1411 break;
1412 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 if (ar.exception != null) {
1416 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1417 } else {
1418 request.result = ((int[]) ar.result)[0];
1419 }
1420 notifyRequester(request);
1421 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001422 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1423 request = (MainThreadRequest) msg.obj;
1424 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1425 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001426 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1427 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001428 break;
1429 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 request.result = ar.exception == null;
1433 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001434 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001435 case CMD_GET_ALL_CELL_INFO:
1436 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001437 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001438 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001439 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001440 case EVENT_GET_ALL_CELL_INFO_DONE:
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001443 // If a timeout occurs, the response will be null
1444 request.result = (ar.exception == null && ar.result != null)
1445 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 synchronized (request) {
1447 request.notifyAll();
1448 }
1449 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001450 case CMD_REQUEST_CELL_INFO_UPDATE:
1451 request = (MainThreadRequest) msg.obj;
1452 request.phone.requestCellInfoUpdate(request.workSource,
1453 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1454 break;
1455 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1459 try {
1460 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001462 cb.onError(
1463 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1464 ar.exception.getClass().getName(),
1465 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001466 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001467 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001468 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001469 } else {
1470 // use the result as returned
1471 cb.onCellInfo((List<CellInfo>) ar.result);
1472 }
1473 } catch (RemoteException re) {
1474 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1475 }
1476 break;
Sarah Chincc055732020-11-18 13:39:35 -08001477 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001478 request = (MainThreadRequest) msg.obj;
1479 WorkSource ws = (WorkSource) request.argument;
1480 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001481 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001482 break;
Sarah Chincc055732020-11-18 13:39:35 -08001483 }
1484 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001485 ar = (AsyncResult) msg.obj;
1486 request = (MainThreadRequest) ar.userObj;
1487 if (ar.exception == null) {
1488 request.result = ar.result;
1489 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001490 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001491 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001492 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 }
1494
1495 synchronized (request) {
1496 request.notifyAll();
1497 }
1498 break;
Sarah Chincc055732020-11-18 13:39:35 -08001499 }
chen xu6dac5ab2018-10-26 17:39:23 -07001500 case CMD_MODEM_REBOOT:
1501 request = (MainThreadRequest) msg.obj;
1502 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001503 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001504 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001505 case EVENT_CMD_MODEM_REBOOT_DONE:
1506 handleNullReturnEvent(msg, "rebootModem");
1507 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001508 case CMD_REQUEST_ENABLE_MODEM:
1509 request = (MainThreadRequest) msg.obj;
1510 boolean enable = (boolean) request.argument;
1511 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001512 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001513 PhoneConfigurationManager.getInstance()
1514 .enablePhone(request.phone, enable, onCompleted);
1515 break;
1516 case EVENT_ENABLE_MODEM_DONE:
1517 ar = (AsyncResult) msg.obj;
1518 request = (MainThreadRequest) ar.userObj;
1519 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001520 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001521 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001522 if ((boolean) request.result) {
1523 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1524 updateModemStateMetrics();
1525 } else {
1526 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1527 + ar.exception);
1528 }
1529 notifyRequester(request);
1530 break;
1531 case CMD_GET_MODEM_STATUS:
1532 request = (MainThreadRequest) msg.obj;
1533 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1534 PhoneConfigurationManager.getInstance()
1535 .getPhoneStatusFromModem(request.phone, onCompleted);
1536 break;
1537 case EVENT_GET_MODEM_STATUS_DONE:
1538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 int id = request.phone.getPhoneId();
1541 if (ar.exception == null && ar.result != null) {
1542 request.result = ar.result;
1543 //update the cache as modem status has changed
1544 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1545 (boolean) request.result);
1546 } else {
1547 // Return true if modem status cannot be retrieved. For most cases,
1548 // modem status is on. And for older version modems, GET_MODEM_STATUS
1549 // and disable modem are not supported. Modem is always on.
1550 // TODO: this should be fixed in R to support a third
1551 // status UNKNOWN b/131631629
1552 request.result = true;
1553 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1554 + ar.exception);
1555 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001556 notifyRequester(request);
1557 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001558 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1559 request = (MainThreadRequest) msg.obj;
1560 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1561 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1562 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1563 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1564 break;
1565 }
1566 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1567 ar = (AsyncResult) msg.obj;
1568 request = (MainThreadRequest) ar.userObj;
1569 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1570 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1571 args.second.accept(ar.exception == null);
1572 notifyRequester(request);
1573 break;
1574 }
Sarah Chincc055732020-11-18 13:39:35 -08001575 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1578 Phone phone = getPhoneFromRequest(request);
1579 if (phone != null) {
1580 phone.getSystemSelectionChannels(onCompleted);
1581 } else {
1582 loge("getSystemSelectionChannels: No phone object");
1583 request.result = new ArrayList<RadioAccessSpecifier>();
1584 notifyRequester(request);
1585 }
1586 break;
1587 }
1588 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 if (ar.exception == null && ar.result != null) {
1592 request.result = ar.result;
1593 } else {
1594 request.result = new IllegalArgumentException(
1595 "Failed to retrieve system selection channels");
1596 if (ar.result == null) {
1597 loge("getSystemSelectionChannels: Empty response");
1598 } else {
1599 loge("getSystemSelectionChannels: Unknown exception");
1600 }
1601 }
1602 notifyRequester(request);
1603 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001604 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1605 ar = (AsyncResult) msg.obj;
1606 request = (MainThreadRequest) ar.userObj;
1607 if (ar.exception == null && ar.result != null) {
1608 request.result = ar.result;
1609 } else {
1610 request.result = -1;
1611 loge("Failed to set Forbidden Plmns");
1612 if (ar.result == null) {
1613 loge("setForbidenPlmns: Empty response");
1614 } else if (ar.exception != null) {
1615 loge("setForbiddenPlmns: Exception: " + ar.exception);
1616 request.result = -1;
1617 } else {
1618 loge("setForbiddenPlmns: Unknown exception");
1619 }
1620 }
1621 notifyRequester(request);
1622 break;
1623 case CMD_SET_FORBIDDEN_PLMNS:
1624 request = (MainThreadRequest) msg.obj;
1625 uiccCard = getUiccCardFromRequest(request);
1626 if (uiccCard == null) {
1627 loge("setForbiddenPlmns: UiccCard is null");
1628 request.result = -1;
1629 notifyRequester(request);
1630 break;
1631 }
1632 Pair<Integer, List<String>> setFplmnsArgs =
1633 (Pair<Integer, List<String>>) request.argument;
1634 appType = setFplmnsArgs.first;
1635 List<String> fplmns = setFplmnsArgs.second;
1636 uiccApp = uiccCard.getApplicationByType(appType);
1637 if (uiccApp == null) {
1638 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1639 request.result = -1;
1640 loge("Failed to get UICC App");
1641 notifyRequester(request);
1642 } else {
1643 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1644 ((SIMRecords) uiccApp.getIccRecords())
1645 .setForbiddenPlmns(onCompleted, fplmns);
1646 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001647 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001648 case CMD_ERASE_MODEM_CONFIG:
1649 request = (MainThreadRequest) msg.obj;
1650 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1651 defaultPhone.eraseModemConfig(onCompleted);
1652 break;
1653 case EVENT_ERASE_MODEM_CONFIG_DONE:
1654 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001655 break;
zoey chenf95ca592019-12-30 16:11:23 +08001656
1657 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1658 request = (MainThreadRequest) msg.obj;
1659 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1660 Pair<String, String> changed = (Pair<String, String>) request.argument;
1661 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1662 changed.first, changed.second, onCompleted);
1663 break;
1664 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1665 ar = (AsyncResult) msg.obj;
1666 request = (MainThreadRequest) ar.userObj;
1667 if (ar.exception == null) {
1668 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1669 } else {
1670 request.result = msg.arg1;
1671 }
1672 notifyRequester(request);
1673 break;
1674
1675 case CMD_SET_ICC_LOCK_ENABLED:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1678 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1679 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1680 enabled.first, enabled.second, onCompleted);
1681 break;
1682 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception == null) {
1686 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1687 } else {
1688 request.result = msg.arg1;
1689 }
1690 notifyRequester(request);
1691 break;
1692
Peter Wangdafb9ac2020-01-15 14:13:38 -08001693 case MSG_NOTIFY_USER_ACTIVITY:
1694 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001695 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001696 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1697 getDefaultPhone().getContext().sendBroadcastAsUser(
1698 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1699 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001700
1701 case CMD_SET_DATA_THROTTLING: {
1702 request = (MainThreadRequest) msg.obj;
1703 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1704 DataThrottlingRequest dataThrottlingRequest =
1705 (DataThrottlingRequest) request.argument;
1706 Phone phone = getPhoneFromRequest(request);
1707 if (phone != null) {
1708 phone.setDataThrottling(onCompleted,
1709 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1710 dataThrottlingRequest.getCompletionDurationMillis());
1711 } else {
1712 loge("setDataThrottling: No phone object");
1713 request.result =
1714 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1715 notifyRequester(request);
1716 }
1717
1718 break;
1719 }
1720 case EVENT_SET_DATA_THROTTLING_DONE:
1721 ar = (AsyncResult) msg.obj;
1722 request = (MainThreadRequest) ar.userObj;
1723
1724 if (ar.exception == null) {
1725 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1726 } else if (ar.exception instanceof CommandException) {
1727 loge("setDataThrottling: CommandException: " + ar.exception);
1728 CommandException.Error error =
1729 ((CommandException) (ar.exception)).getCommandError();
1730
1731 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1732 request.result = TelephonyManager
1733 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1734 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1735 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1736 } else {
1737 request.result =
1738 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1739 }
1740 } else {
1741 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1742 }
1743 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1744 notifyRequester(request);
1745 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001746
1747 case CMD_SET_SIM_POWER: {
1748 request = (MainThreadRequest) msg.obj;
1749 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1750 request = (MainThreadRequest) msg.obj;
1751 int stateToSet =
1752 ((Pair<Integer, IIntegerConsumer>)
1753 request.argument).first;
1754 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1755 break;
1756 }
1757 case EVENT_SET_SIM_POWER_DONE: {
1758 ar = (AsyncResult) msg.obj;
1759 request = (MainThreadRequest) ar.userObj;
1760 IIntegerConsumer callback =
1761 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1762 if (ar.exception != null) {
1763 loge("setSimPower exception: " + ar.exception);
1764 int errorCode = TelephonyManager.CallForwardingInfoCallback
1765 .RESULT_ERROR_UNKNOWN;
1766 if (ar.exception instanceof CommandException) {
1767 CommandException.Error error =
1768 ((CommandException) (ar.exception)).getCommandError();
1769 if (error == CommandException.Error.SIM_ERR) {
1770 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1771 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1772 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1773 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1774 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1775 } else {
1776 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1777 }
1778 }
1779 try {
1780 callback.accept(errorCode);
1781 } catch (RemoteException e) {
1782 // Ignore if the remote process is no longer available to call back.
1783 Log.w(LOG_TAG, "setSimPower: callback not available.");
1784 }
1785 } else {
1786 try {
1787 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1788 } catch (RemoteException e) {
1789 // Ignore if the remote process is no longer available to call back.
1790 Log.w(LOG_TAG, "setSimPower: callback not available.");
1791 }
1792 }
1793 break;
1794 }
1795
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001796 default:
1797 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1798 break;
1799 }
1800 }
Jake Hambye994d462014-02-03 13:10:13 -08001801
Pengquan Menga1bb6272018-09-06 09:59:22 -07001802 private void notifyRequester(MainThreadRequest request) {
1803 synchronized (request) {
1804 request.notifyAll();
1805 }
1806 }
1807
Jake Hambye994d462014-02-03 13:10:13 -08001808 private void handleNullReturnEvent(Message msg, String command) {
1809 AsyncResult ar = (AsyncResult) msg.obj;
1810 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1811 if (ar.exception == null) {
1812 request.result = true;
1813 } else {
1814 request.result = false;
1815 if (ar.exception instanceof CommandException) {
1816 loge(command + ": CommandException: " + ar.exception);
1817 } else {
1818 loge(command + ": Unknown exception");
1819 }
1820 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001821 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001822 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001823 }
1824
1825 /**
1826 * Posts the specified command to be executed on the main thread,
1827 * waits for the request to complete, and returns the result.
1828 * @see #sendRequestAsync
1829 */
1830 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001831 return sendRequest(
1832 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001833 }
1834
1835 /**
1836 * Posts the specified command to be executed on the main thread,
1837 * waits for the request to complete, and returns the result.
1838 * @see #sendRequestAsync
1839 */
1840 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1841 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001842 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001843 }
1844
1845 /**
1846 * Posts the specified command to be executed on the main thread,
1847 * waits for the request to complete, and returns the result.
1848 * @see #sendRequestAsync
1849 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001850 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001851 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001852 }
1853
1854 /**
1855 * Posts the specified command to be executed on the main thread,
1856 * waits for the request to complete, and returns the result.
1857 * @see #sendRequestAsync
1858 */
Nathan Harold92bed182018-10-12 18:16:49 -07001859 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1860 return sendRequest(command, argument, subId, null, workSource);
1861 }
1862
1863 /**
1864 * Posts the specified command to be executed on the main thread,
1865 * waits for the request to complete, and returns the result.
1866 * @see #sendRequestAsync
1867 */
1868 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1869 return sendRequest(
1870 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1871 }
1872
1873 /**
1874 * Posts the specified command to be executed on the main thread,
1875 * waits for the request to complete, and returns the result.
1876 * @see #sendRequestAsync
1877 */
1878 private Object sendRequest(
1879 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001880 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1881 throw new RuntimeException("This method will deadlock if called from the main thread.");
1882 }
1883
Nathan Harold92bed182018-10-12 18:16:49 -07001884 MainThreadRequest request = null;
1885 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1886 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1887 } else if (phone != null) {
1888 request = new MainThreadRequest(argument, phone, workSource);
1889 } else {
1890 request = new MainThreadRequest(argument, subId, workSource);
1891 }
1892
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 Message msg = mMainThreadHandler.obtainMessage(command, request);
1894 msg.sendToTarget();
1895
1896 // Wait for the request to complete
1897 synchronized (request) {
1898 while (request.result == null) {
1899 try {
1900 request.wait();
1901 } catch (InterruptedException e) {
1902 // Do nothing, go back and wait until the request is complete
1903 }
1904 }
1905 }
1906 return request.result;
1907 }
1908
1909 /**
1910 * Asynchronous ("fire and forget") version of sendRequest():
1911 * Posts the specified command to be executed on the main thread, and
1912 * returns immediately.
1913 * @see #sendRequest
1914 */
1915 private void sendRequestAsync(int command) {
1916 mMainThreadHandler.sendEmptyMessage(command);
1917 }
1918
1919 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001920 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001921 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001922 */
1923 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001924 sendRequestAsync(command, argument, null, null);
1925 }
1926
1927 /**
1928 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1929 * @see {@link #sendRequest(int,Object)}
1930 */
1931 private void sendRequestAsync(
1932 int command, Object argument, Phone phone, WorkSource workSource) {
1933 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001934 Message msg = mMainThreadHandler.obtainMessage(command, request);
1935 msg.sendToTarget();
1936 }
1937
1938 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 * Initialize the singleton PhoneInterfaceManager instance.
1940 * This is only done once, at startup, from PhoneApp.onCreate().
1941 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001942 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 synchronized (PhoneInterfaceManager.class) {
1944 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001945 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001946 } else {
1947 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1948 }
1949 return sInstance;
1950 }
1951 }
1952
1953 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001954 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001957 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001958 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001959 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1960 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001961 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001962 mTelephonySharedPreferences =
1963 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001964 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001965 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001966 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001967
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 publish();
1969 }
1970
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001971 private Phone getDefaultPhone() {
1972 Phone thePhone = getPhone(getDefaultSubscription());
1973 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1974 }
1975
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001976 private void publish() {
1977 if (DBG) log("publish: " + this);
1978
Peter Wangc035ce42020-01-08 21:00:22 -08001979 TelephonyFrameworkInitializer
1980 .getTelephonyServiceManager()
1981 .getTelephonyServiceRegisterer()
1982 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001983 }
1984
Stuart Scott584921c2015-01-15 17:10:34 -08001985 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001986 if (request.phone != null) {
1987 return request.phone;
1988 } else {
1989 return getPhoneFromSubId(request.subId);
1990 }
1991 }
1992
1993 private Phone getPhoneFromSubId(int subId) {
1994 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1995 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001996 }
1997
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001998 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1999 Phone phone = getPhoneFromRequest(request);
2000 return phone == null ? null :
2001 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2002 }
2003
Wink Saville36469e72014-06-11 15:17:00 -07002004 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002005 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002006 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002007 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002008
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002009 private void sendEraseModemConfig(Phone phone) {
2010 if (phone != null) {
2011 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2012 mApp, phone.getSubId(), "eraseModemConfig");
2013 final long identity = Binder.clearCallingIdentity();
2014 try {
2015 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2016 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2017 } finally {
2018 Binder.restoreCallingIdentity(identity);
2019 }
2020 }
2021 }
2022
Peter Wang050bb052020-01-13 23:33:09 -08002023 private boolean isImsAvailableOnDevice() {
2024 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2025 if (pm == null) {
2026 // For some reason package manger is not available.. This will fail internally anyway,
2027 // so do not throw error and allow.
2028 return true;
2029 }
2030 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2031 }
2032
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002034 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
Wink Savilleb564aae2014-10-23 10:18:09 -07002037 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 if (DBG) log("dial: " + number);
2039 // No permission check needed here: This is just a wrapper around the
2040 // ACTION_DIAL intent, which is available to any app since it puts up
2041 // the UI before it does anything.
2042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002043 final long identity = Binder.clearCallingIdentity();
2044 try {
2045 String url = createTelUrl(number);
2046 if (url == null) {
2047 return;
2048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002050 // PENDING: should we just silently fail if phone is offhook or ringing?
2051 PhoneConstants.State state = mCM.getState(subId);
2052 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2053 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2054 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2055 mApp.startActivity(intent);
2056 }
2057 } finally {
2058 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002059 }
2060 }
2061
2062 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002063 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002064 }
2065
Wink Savilleb564aae2014-10-23 10:18:09 -07002066 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 if (DBG) log("call: " + number);
2068
2069 // This is just a wrapper around the ACTION_CALL intent, but we still
2070 // need to do a permission check since we're calling startActivity()
2071 // from the context of the phone app.
2072 enforceCallPermission();
2073
Jordan Liu1617b712019-07-10 15:06:26 -07002074 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 != AppOpsManager.MODE_ALLOWED) {
2076 return;
2077 }
2078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002079 final long identity = Binder.clearCallingIdentity();
2080 try {
2081 String url = createTelUrl(number);
2082 if (url == null) {
2083 return;
2084 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002086 boolean isValid = false;
2087 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2088 if (slist != null) {
2089 for (SubscriptionInfo subInfoRecord : slist) {
2090 if (subInfoRecord.getSubscriptionId() == subId) {
2091 isValid = true;
2092 break;
2093 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002094 }
Wink Saville08874612014-08-31 19:19:58 -07002095 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096 if (!isValid) {
2097 return;
2098 }
Wink Saville08874612014-08-31 19:19:58 -07002099
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002100 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2101 intent.putExtra(SUBSCRIPTION_KEY, subId);
2102 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2103 mApp.startActivity(intent);
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
2106 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002107 }
2108
Wink Savilleb564aae2014-10-23 10:18:09 -07002109 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002110 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002111 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2112 }
2113
Wink Savilleb564aae2014-10-23 10:18:09 -07002114 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002115 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002116 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2117 }
2118
Wink Savilleb564aae2014-10-23 10:18:09 -07002119 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002120 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002121
2122 final long identity = Binder.clearCallingIdentity();
2123 try {
2124 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2125 checkSimPin.start();
2126 return checkSimPin.unlockSim(null, pin);
2127 } finally {
2128 Binder.restoreCallingIdentity(identity);
2129 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 }
2131
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 public int[] supplyPukReportResultForSubscriber(int subId, String puk, 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 checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2138 checkSimPuk.start();
2139 return checkSimPuk.unlockSim(puk, pin);
2140 } finally {
2141 Binder.restoreCallingIdentity(identity);
2142 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002143 }
2144
2145 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002146 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002147 * a synchronous one.
2148 */
2149 private static class UnlockSim extends Thread {
2150
2151 private final IccCard mSimCard;
2152
2153 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002154 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2155 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156
2157 // For replies from SimCard interface
2158 private Handler mHandler;
2159
2160 // For async handler to identify request type
2161 private static final int SUPPLY_PIN_COMPLETE = 100;
2162
2163 public UnlockSim(IccCard simCard) {
2164 mSimCard = simCard;
2165 }
2166
2167 @Override
2168 public void run() {
2169 Looper.prepare();
2170 synchronized (UnlockSim.this) {
2171 mHandler = new Handler() {
2172 @Override
2173 public void handleMessage(Message msg) {
2174 AsyncResult ar = (AsyncResult) msg.obj;
2175 switch (msg.what) {
2176 case SUPPLY_PIN_COMPLETE:
2177 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2178 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002179 mRetryCount = msg.arg1;
2180 if (ar.exception != null) {
2181 if (ar.exception instanceof CommandException &&
2182 ((CommandException)(ar.exception)).getCommandError()
2183 == CommandException.Error.PASSWORD_INCORRECT) {
2184 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002185 } //When UiccCardApp dispose,handle message and return exception
2186 else if (ar.exception instanceof CommandException &&
2187 ((CommandException) (ar.exception)).getCommandError()
2188 == CommandException.Error.ABORTED) {
2189 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002190 } else {
2191 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2192 }
2193 } else {
2194 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2195 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002196 mDone = true;
2197 UnlockSim.this.notifyAll();
2198 }
2199 break;
2200 }
2201 }
2202 };
2203 UnlockSim.this.notifyAll();
2204 }
2205 Looper.loop();
2206 }
2207
2208 /*
2209 * Use PIN or PUK to unlock SIM card
2210 *
2211 * If PUK is null, unlock SIM card with PIN
2212 *
2213 * If PUK is not null, unlock SIM card with PUK and set PIN code
2214 */
Wink Saville9de0f752013-10-22 19:04:03 -07002215 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002216
2217 while (mHandler == null) {
2218 try {
2219 wait();
2220 } catch (InterruptedException e) {
2221 Thread.currentThread().interrupt();
2222 }
2223 }
2224 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2225
2226 if (puk == null) {
2227 mSimCard.supplyPin(pin, callback);
2228 } else {
2229 mSimCard.supplyPuk(puk, pin, callback);
2230 }
2231
2232 while (!mDone) {
2233 try {
2234 Log.d(LOG_TAG, "wait for done");
2235 wait();
2236 } catch (InterruptedException e) {
2237 // Restore the interrupted status
2238 Thread.currentThread().interrupt();
2239 }
2240 }
2241 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002242 int[] resultArray = new int[2];
2243 resultArray[0] = mResult;
2244 resultArray[1] = mRetryCount;
2245 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002246 }
2247 }
2248
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002249 /**
2250 * This method has been removed due to privacy and stability concerns.
2251 */
2252 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002254 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2255 return;
Wink Saville36469e72014-06-11 15:17:00 -07002256 }
2257
Nathan Harold1f889d82020-06-04 17:05:26 -07002258 @Override
2259 public void updateServiceLocationWithPackageName(String callingPackage) {
2260 mApp.getSystemService(AppOpsManager.class)
2261 .checkPackage(Binder.getCallingUid(), callingPackage);
2262
2263 final int targetSdk = getTargetSdk(callingPackage);
2264 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2265 // Callers targeting S have no business invoking this method.
2266 return;
2267 }
2268
2269 LocationAccessPolicy.LocationPermissionResult locationResult =
2270 LocationAccessPolicy.checkLocationPermission(mApp,
2271 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2272 .setCallingPackage(callingPackage)
2273 .setCallingFeatureId(null)
2274 .setCallingPid(Binder.getCallingPid())
2275 .setCallingUid(Binder.getCallingUid())
2276 .setMethod("updateServiceLocation")
2277 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2278 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2279 .build());
2280 // Apps that lack location permission have no business calling this method;
2281 // however, because no permission was declared in the public API, denials must
2282 // all be "soft".
2283 switch (locationResult) {
2284 case DENIED_HARD: /* fall through */
2285 case DENIED_SOFT:
2286 return;
2287 }
2288
2289 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002290 final long identity = Binder.clearCallingIdentity();
2291 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002292 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002293 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002294 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002295 }
2296 } finally {
2297 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002298 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002299 }
2300
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002301 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002302 @Override
2303 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002304 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002305 }
2306
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002307
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002308 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002309 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2310 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2311 callingFeatureId);
2312 }
2313
2314 @Deprecated
2315 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002316 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002317 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2318 }
2319
2320 @Override
2321 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2322 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002323 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002324 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002325 return false;
2326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327
2328 final long identity = Binder.clearCallingIdentity();
2329 try {
2330 return isRadioOnForSubscriber(subId);
2331 } finally {
2332 Binder.restoreCallingIdentity(identity);
2333 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002334 }
2335
2336 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002337 final long identity = Binder.clearCallingIdentity();
2338 try {
2339 final Phone phone = getPhone(subId);
2340 if (phone != null) {
2341 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2342 } else {
2343 return false;
2344 }
2345 } finally {
2346 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002347 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 }
2349
2350 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002351 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352 }
Wink Saville36469e72014-06-11 15:17:00 -07002353
Wink Savilleb564aae2014-10-23 10:18:09 -07002354 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002355 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002356
2357 final long identity = Binder.clearCallingIdentity();
2358 try {
2359 final Phone phone = getPhone(subId);
2360 if (phone != null) {
2361 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2362 }
2363 } finally {
2364 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002365 }
Wink Saville36469e72014-06-11 15:17:00 -07002366 }
2367
2368 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002369 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002370 }
2371
Wink Savilleb564aae2014-10-23 10:18:09 -07002372 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002373 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002374
2375 final long identity = Binder.clearCallingIdentity();
2376 try {
2377 final Phone phone = getPhone(subId);
2378 if (phone == null) {
2379 return false;
2380 }
2381 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2382 toggleRadioOnOffForSubscriber(subId);
2383 }
2384 return true;
2385 } finally {
2386 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002387 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002388 }
Wink Saville36469e72014-06-11 15:17:00 -07002389
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002390 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002391 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002392 /*
2393 * If any of the Radios are available, it will need to be
2394 * shutdown. So return true if any Radio is available.
2395 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002396 final long identity = Binder.clearCallingIdentity();
2397 try {
2398 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2399 Phone phone = PhoneFactory.getPhone(i);
2400 if (phone != null && phone.isRadioAvailable()) return true;
2401 }
2402 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2403 return false;
2404 } finally {
2405 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002406 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002407 }
2408
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002409 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002410 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002411 enforceModifyPermission();
2412
2413 final long identity = Binder.clearCallingIdentity();
2414 try {
2415 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2416 logv("Shutting down Phone " + i);
2417 shutdownRadioUsingPhoneId(i);
2418 }
2419 } finally {
2420 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002421 }
2422 }
2423
2424 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002425 Phone phone = PhoneFactory.getPhone(phoneId);
2426 if (phone != null && phone.isRadioAvailable()) {
2427 phone.shutdownRadio();
2428 }
2429 }
2430
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002433
2434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2437 if (defaultPhone != null) {
2438 defaultPhone.setRadioPower(turnOn);
2439 return true;
2440 } else {
2441 loge("There's no default phone.");
2442 return false;
2443 }
2444 } finally {
2445 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002446 }
Wink Saville36469e72014-06-11 15:17:00 -07002447 }
2448
Wink Savilleb564aae2014-10-23 10:18:09 -07002449 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002450 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002451
2452 final long identity = Binder.clearCallingIdentity();
2453 try {
2454 final Phone phone = getPhone(subId);
2455 if (phone != null) {
2456 phone.setRadioPower(turnOn);
2457 return true;
2458 } else {
2459 return false;
2460 }
2461 } finally {
2462 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002463 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002464 }
2465
Wink Saville36469e72014-06-11 15:17:00 -07002466 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002467 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002468 public boolean enableDataConnectivity() {
2469 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470
2471 final long identity = Binder.clearCallingIdentity();
2472 try {
2473 int subId = mSubscriptionController.getDefaultDataSubId();
2474 final Phone phone = getPhone(subId);
2475 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002476 phone.getDataEnabledSettings().setDataEnabled(
2477 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 return true;
2479 } else {
2480 return false;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
Wink Saville36469e72014-06-11 15:17:00 -07002487 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 public boolean disableDataConnectivity() {
2490 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002491
2492 final long identity = Binder.clearCallingIdentity();
2493 try {
2494 int subId = mSubscriptionController.getDefaultDataSubId();
2495 final Phone phone = getPhone(subId);
2496 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002497 phone.getDataEnabledSettings().setDataEnabled(
2498 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002499 return true;
2500 } else {
2501 return false;
2502 }
2503 } finally {
2504 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002505 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002506 }
2507
Sanket Padawe356d7632015-06-22 14:03:32 -07002508 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002509 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 final Phone phone = getPhone(subId);
2513 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002514 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515 } else {
2516 return false;
2517 }
2518 } finally {
2519 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002520 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002521 }
2522
2523 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002524 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002525 }
2526
pkanwarae03a6b2016-11-06 20:37:09 -08002527 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002528 enforceCallPermission();
2529
2530 final long identity = Binder.clearCallingIdentity();
2531 try {
2532 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2533 return;
2534 }
2535 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2536 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2537 } finally {
2538 Binder.restoreCallingIdentity(identity);
2539 }
pkanwar32d516d2016-10-14 19:37:38 -07002540 };
2541
Wink Savilleb564aae2014-10-23 10:18:09 -07002542 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002543 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002544
2545 final long identity = Binder.clearCallingIdentity();
2546 try {
2547 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2548 return false;
2549 }
2550 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2551 } finally {
2552 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002557 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002558 }
2559
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002560 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561 final long identity = Binder.clearCallingIdentity();
2562 try {
2563 Phone phone = PhoneFactory.getPhone(slotIndex);
2564 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2565 PhoneConstantConversions.convertCallState(phone.getState());
2566 } finally {
2567 Binder.restoreCallingIdentity(identity);
2568 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002569 }
2570
Sanket Padawe356d7632015-06-22 14:03:32 -07002571 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002572 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002573 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2574 }
2575
2576 @Override
2577 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002578 final long identity = Binder.clearCallingIdentity();
2579 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002580 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581 if (phone != null) {
2582 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2583 } else {
2584 return PhoneConstantConversions.convertDataState(
2585 PhoneConstants.DataState.DISCONNECTED);
2586 }
2587 } finally {
2588 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002589 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002590 }
2591
Sanket Padawe356d7632015-06-22 14:03:32 -07002592 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002593 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002594 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2595 }
2596
2597 @Override
2598 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599 final long identity = Binder.clearCallingIdentity();
2600 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002601 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002602 if (phone != null) {
2603 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2604 } else {
2605 return TelephonyManager.DATA_ACTIVITY_NONE;
2606 }
2607 } finally {
2608 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002609 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002610 }
2611
2612 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002613 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002614 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002615 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002616
2617 LocationAccessPolicy.LocationPermissionResult locationResult =
2618 LocationAccessPolicy.checkLocationPermission(mApp,
2619 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2620 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002621 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002622 .setCallingPid(Binder.getCallingPid())
2623 .setCallingUid(Binder.getCallingUid())
2624 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002625 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002626 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2627 .build());
2628 switch (locationResult) {
2629 case DENIED_HARD:
2630 throw new SecurityException("Not allowed to access cell location");
2631 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002632 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2633 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002634 }
2635
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002636 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002640 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002641 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 } finally {
2643 Binder.restoreCallingIdentity(identity);
2644 }
Svetoslav64fad262015-04-14 14:35:21 -07002645 }
2646
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 @Override
Jack Yu01425032020-02-22 19:38:58 -08002648 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002649 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2650 // registered cell info, so return a NULL country instead.
2651 final long identity = Binder.clearCallingIdentity();
2652 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002653 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2654 // Get default phone in this case.
2655 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2656 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002657 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002659 if (phone == null) return "";
2660 ServiceStateTracker sst = phone.getServiceStateTracker();
2661 if (sst == null) return "";
2662 LocaleTracker lt = sst.getLocaleTracker();
2663 if (lt == null) return "";
2664 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2665 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2666 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002667 } finally {
2668 Binder.restoreCallingIdentity(identity);
2669 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002670 }
2671
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002672 /**
2673 * This method was removed due to potential issues caused by performing partial
2674 * updates of service state, and lack of a credible use case.
2675 *
2676 * This has the ability to break the telephony implementation by disabling notification of
2677 * changes in device connectivity. DO NOT USE THIS!
2678 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002679 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 public void enableLocationUpdates() {
2681 mApp.enforceCallingOrSelfPermission(
2682 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -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 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 @Override
2693 public void disableLocationUpdates() {
2694 mApp.enforceCallingOrSelfPermission(
2695 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 }
2697
Nathan Harold31d7ff32018-10-15 20:20:30 -07002698 /**
2699 * Returns the target SDK version number for a given package name.
2700 *
Nathan Haroldec184742019-07-10 17:04:16 -07002701 * This call MUST be invoked before clearing the calling UID.
2702 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002703 * @return target SDK if the package is found or INT_MAX.
2704 */
2705 private int getTargetSdk(String packageName) {
2706 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002707 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002708 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002709 if (ai != null) return ai.targetSdkVersion;
2710 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002711 loge("Failed to get package info for pkg="
2712 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002713 }
2714 return Integer.MAX_VALUE;
2715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 @Override
2718 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002719 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2720 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002721 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002722 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2723 throw new SecurityException(
2724 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2725 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002726
Jordan Liu1617b712019-07-10 15:06:26 -07002727 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002728 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2729 return null;
2730 }
Svetoslav64fad262015-04-14 14:35:21 -07002731
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002732 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002734 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002735 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736
Nathan Haroldf180aac2018-06-01 18:43:55 -07002737 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2738 for (CellInfo ci : info) {
2739 if (ci instanceof CellInfoGsm) {
2740 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2741 } else if (ci instanceof CellInfoWcdma) {
2742 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002745 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002748 private List<CellInfo> getCachedCellInfo() {
2749 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2750 for (Phone phone : PhoneFactory.getPhones()) {
2751 List<CellInfo> info = phone.getAllCellInfo();
2752 if (info != null) cellInfos.addAll(info);
2753 }
2754 return cellInfos;
2755 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756
2757 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002759 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002760 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002761
2762 LocationAccessPolicy.LocationPermissionResult locationResult =
2763 LocationAccessPolicy.checkLocationPermission(mApp,
2764 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2765 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002766 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002767 .setCallingPid(Binder.getCallingPid())
2768 .setCallingUid(Binder.getCallingUid())
2769 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002770 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002771 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2772 .build());
2773 switch (locationResult) {
2774 case DENIED_HARD:
2775 throw new SecurityException("Not allowed to access cell info");
2776 case DENIED_SOFT:
2777 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002780 final int targetSdk = getTargetSdk(callingPackage);
2781 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2782 return getCachedCellInfo();
2783 }
2784
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002785 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002786 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002787 final long identity = Binder.clearCallingIdentity();
2788 try {
2789 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2790 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002791 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002792 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002793 if (info != null) cellInfos.addAll(info);
2794 }
2795 return cellInfos;
2796 } finally {
2797 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002798 }
2799 }
2800
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002801 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002802 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2803 String callingFeatureId) {
2804 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2805 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002806 }
2807
2808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002809 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2810 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002811 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002813 }
2814
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002815 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2816 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002817 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002818 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002819
2820 LocationAccessPolicy.LocationPermissionResult locationResult =
2821 LocationAccessPolicy.checkLocationPermission(mApp,
2822 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2823 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002824 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002825 .setCallingPid(Binder.getCallingPid())
2826 .setCallingUid(Binder.getCallingUid())
2827 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002828 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2829 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002830 .build());
2831 switch (locationResult) {
2832 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002833 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2834 // Safetynet logging for b/154934934
2835 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2836 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002837 throw new SecurityException("Not allowed to access cell info");
2838 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002839 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2840 // Safetynet logging for b/154934934
2841 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2842 }
Nathan Harold5320c422019-05-09 10:26:08 -07002843 try {
2844 cb.onCellInfo(new ArrayList<CellInfo>());
2845 } catch (RemoteException re) {
2846 // Drop without consequences
2847 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002848 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002849 }
2850
Nathan Harolda939a962019-05-09 10:13:47 -07002851
2852 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002853 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2854
2855 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2856 }
2857
2858 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002860 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002861 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002862
2863 final long identity = Binder.clearCallingIdentity();
2864 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002865 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866 } finally {
2867 Binder.restoreCallingIdentity(identity);
2868 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002869 }
2870
Shishir Agrawala9f32182016-04-12 12:00:16 -07002871 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002872 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002873 Phone phone = PhoneFactory.getPhone(slotIndex);
2874 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 return null;
2876 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002877 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002878 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002879 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002880 return null;
2881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002882
2883 final long identity = Binder.clearCallingIdentity();
2884 try {
2885 return phone.getImei();
2886 } finally {
2887 Binder.restoreCallingIdentity(identity);
2888 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002889 }
2890
2891 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002892 public String getTypeAllocationCodeForSlot(int slotIndex) {
2893 Phone phone = PhoneFactory.getPhone(slotIndex);
2894 String tac = null;
2895 if (phone != null) {
2896 String imei = phone.getImei();
2897 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2898 }
2899 return tac;
2900 }
2901
2902 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002903 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002904 Phone phone = PhoneFactory.getPhone(slotIndex);
2905 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002906 return null;
2907 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908
Jeff Davidson913390f2018-02-23 17:11:49 -08002909 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002910 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002911 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002912 return null;
2913 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002914
2915 final long identity = Binder.clearCallingIdentity();
2916 try {
2917 return phone.getMeid();
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
2920 }
Jack Yu2af8d712017-03-15 17:14:14 -07002921 }
2922
2923 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002924 public String getManufacturerCodeForSlot(int slotIndex) {
2925 Phone phone = PhoneFactory.getPhone(slotIndex);
2926 String manufacturerCode = null;
2927 if (phone != null) {
2928 String meid = phone.getMeid();
2929 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2930 }
2931 return manufacturerCode;
2932 }
2933
2934 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002935 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2936 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002937 Phone phone = PhoneFactory.getPhone(slotIndex);
2938 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002939 return null;
2940 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002941 int subId = phone.getSubId();
2942 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002943 mApp, subId, callingPackage, callingFeatureId,
2944 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002945 return null;
2946 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002947
2948 final long identity = Binder.clearCallingIdentity();
2949 try {
2950 return phone.getDeviceSvn();
2951 } finally {
2952 Binder.restoreCallingIdentity(identity);
2953 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002954 }
2955
fionaxu43304da2017-11-27 22:51:16 -08002956 @Override
2957 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002958 final long identity = Binder.clearCallingIdentity();
2959 try {
2960 final Phone phone = getPhone(subId);
2961 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2962 } finally {
2963 Binder.restoreCallingIdentity(identity);
2964 }
fionaxu43304da2017-11-27 22:51:16 -08002965 }
2966
2967 @Override
2968 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002969 final long identity = Binder.clearCallingIdentity();
2970 try {
2971 final Phone phone = getPhone(subId);
2972 return phone == null ? null : phone.getCarrierName();
2973 } finally {
2974 Binder.restoreCallingIdentity(identity);
2975 }
fionaxu43304da2017-11-27 22:51:16 -08002976 }
2977
calvinpanffe225e2018-11-01 19:43:06 +08002978 @Override
chen xu0026ca62019-03-06 15:28:50 -08002979 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 final Phone phone = getPhone(subId);
2983 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002984 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
2988 }
2989
2990 @Override
chen xu0026ca62019-03-06 15:28:50 -08002991 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002995 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002996 } finally {
2997 Binder.restoreCallingIdentity(identity);
2998 }
2999 }
3000
chen xu651eec72018-11-11 19:03:44 -08003001 @Override
chen xu864e11c2018-12-06 22:10:03 -08003002 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3003 if (!isSubscriptionMccMnc) {
3004 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3005 }
chen xu651eec72018-11-11 19:03:44 -08003006 final Phone phone = PhoneFactory.getPhone(slotIndex);
3007 if (phone == null) {
3008 return TelephonyManager.UNKNOWN_CARRIER_ID;
3009 }
3010 final long identity = Binder.clearCallingIdentity();
3011 try {
3012 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
3016 }
3017
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003018 //
3019 // Internal helper methods.
3020 //
3021
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003022 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003023 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3024 *
3025 * @throws SecurityException if the caller does not have the required permission
3026 */
3027 private void enforceModifyPermission() {
3028 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3029 }
3030
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003031 /**
3032 * Make sure the caller is system.
3033 *
3034 * @throws SecurityException if the caller is not system.
3035 */
3036 private void enforceSystemCaller() {
3037 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3038 throw new SecurityException("Caller must be system");
3039 }
3040 }
3041
Shuo Qianf2b2df42019-11-13 17:43:31 -08003042 private void enforceActiveEmergencySessionPermission() {
3043 mApp.enforceCallingOrSelfPermission(
3044 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3045 }
3046
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003047 /**
3048 * Make sure the caller has the CALL_PHONE permission.
3049 *
3050 * @throws SecurityException if the caller does not have the required permission
3051 */
3052 private void enforceCallPermission() {
3053 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3054 }
3055
paulhu423b5f22019-08-23 19:17:33 +08003056 private void enforceSettingsPermission() {
3057 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003058 }
3059
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003060 private String createTelUrl(String number) {
3061 if (TextUtils.isEmpty(number)) {
3062 return null;
3063 }
3064
Jake Hambye994d462014-02-03 13:10:13 -08003065 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003066 }
3067
Ihab Awadf9e92732013-12-05 18:02:52 -08003068 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003069 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3070 }
3071
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003072 private static void logv(String msg) {
3073 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3074 }
3075
Ihab Awadf9e92732013-12-05 18:02:52 -08003076 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003077 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3078 }
3079
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003080 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003081 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003082 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003083 }
3084
Sanket Padawe356d7632015-06-22 14:03:32 -07003085 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003086 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final Phone phone = PhoneFactory.getPhone(slotIndex);
3090 if (phone == null) {
3091 return PhoneConstants.PHONE_TYPE_NONE;
3092 } else {
3093 return phone.getPhoneType();
3094 }
3095 } finally {
3096 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003097 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 }
3099
3100 /**
3101 * Returns the CDMA ERI icon index to display
3102 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003103 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003104 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3105 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3106 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003107 }
3108
Sanket Padawe356d7632015-06-22 14:03:32 -07003109 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003110 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3111 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003113 mApp, subId, callingPackage, callingFeatureId,
3114 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003115 return -1;
3116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003117
3118 final long identity = Binder.clearCallingIdentity();
3119 try {
3120 final Phone phone = getPhone(subId);
3121 if (phone != null) {
3122 return phone.getCdmaEriIconIndex();
3123 } else {
3124 return -1;
3125 }
3126 } finally {
3127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003129 }
3130
3131 /**
3132 * Returns the CDMA ERI icon mode,
3133 * 0 - ON
3134 * 1 - FLASHING
3135 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003136 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003137 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3138 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3139 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003140 }
3141
Sanket Padawe356d7632015-06-22 14:03:32 -07003142 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003143 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3144 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003146 mApp, subId, callingPackage, callingFeatureId,
3147 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003148 return -1;
3149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150
3151 final long identity = Binder.clearCallingIdentity();
3152 try {
3153 final Phone phone = getPhone(subId);
3154 if (phone != null) {
3155 return phone.getCdmaEriIconMode();
3156 } else {
3157 return -1;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003162 }
3163
3164 /**
3165 * Returns the CDMA ERI text,
3166 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003167 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003168 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3169 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3170 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003171 }
3172
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003174 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3175 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003176 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003177 mApp, subId, callingPackage, callingFeatureId,
3178 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003179 return null;
3180 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003181
3182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 final Phone phone = getPhone(subId);
3185 if (phone != null) {
3186 return phone.getCdmaEriText();
3187 } else {
3188 return null;
3189 }
3190 } finally {
3191 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003192 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 }
3194
3195 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003196 * Returns the CDMA MDN.
3197 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003198 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003199 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3201 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003202
3203 final long identity = Binder.clearCallingIdentity();
3204 try {
3205 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003206 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003207 return phone.getLine1Number();
3208 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 return null;
3211 }
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003214 }
3215 }
3216
3217 /**
3218 * Returns the CDMA MIN.
3219 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003221 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003222 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3223 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003224
3225 final long identity = Binder.clearCallingIdentity();
3226 try {
3227 final Phone phone = getPhone(subId);
3228 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3229 return phone.getCdmaMin();
3230 } else {
3231 return null;
3232 }
3233 } finally {
3234 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003235 }
3236 }
3237
Hall Liud892bec2018-11-30 14:51:45 -08003238 @Override
3239 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3240 INumberVerificationCallback callback, String callingPackage) {
3241 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3242 != PERMISSION_GRANTED) {
3243 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3244 }
3245 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3246
3247 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3248 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3249 throw new SecurityException("Calling package must be configured in the device config");
3250 }
3251
3252 if (range == null) {
3253 throw new NullPointerException("Range must be non-null");
3254 }
3255
3256 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003257 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003258
3259 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3260 }
3261
Junda Liuca05d5d2014-08-14 22:36:34 -07003262 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003263 * Returns true if CDMA provisioning needs to run.
3264 */
3265 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003266 final long identity = Binder.clearCallingIdentity();
3267 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003268 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003272 }
3273
3274 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003275 * Sets the voice mail number of a given subId.
3276 */
3277 @Override
3278 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003279 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3280 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003281
3282 final long identity = Binder.clearCallingIdentity();
3283 try {
3284 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3285 new Pair<String, String>(alphaTag, number), new Integer(subId));
3286 return success;
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
3289 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003290 }
3291
Ta-wei Yen87c49842016-05-13 21:19:52 -07003292 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003293 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3294 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003295 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3296 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003297 if (!TextUtils.equals(callingPackage, systemDialer)) {
3298 throw new SecurityException("caller must be system dialer");
3299 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003300
3301 final long identity = Binder.clearCallingIdentity();
3302 try {
3303 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3304 if (phoneAccountHandle == null) {
3305 return null;
3306 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003310 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003311 }
3312
3313 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003314 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3315 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003317 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003318 mApp, subId, callingPackage, callingFeatureId,
3319 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003320 return null;
3321 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003323 final long identity = Binder.clearCallingIdentity();
3324 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003325 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003326 } finally {
3327 Binder.restoreCallingIdentity(identity);
3328 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003329 }
3330
3331 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003332 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3333 VisualVoicemailSmsFilterSettings settings) {
3334 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335
3336 final long identity = Binder.clearCallingIdentity();
3337 try {
3338 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003339 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003340 } finally {
3341 Binder.restoreCallingIdentity(identity);
3342 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003343 }
3344
3345 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003346 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3347 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003352 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003353 } finally {
3354 Binder.restoreCallingIdentity(identity);
3355 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003356 }
3357
3358 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003359 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3360 String callingPackage, int subId) {
3361 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362
3363 final long identity = Binder.clearCallingIdentity();
3364 try {
3365 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003366 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003367 } finally {
3368 Binder.restoreCallingIdentity(identity);
3369 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003370 }
3371
3372 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003373 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003374 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003375
3376 final long identity = Binder.clearCallingIdentity();
3377 try {
3378 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003379 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003380 } finally {
3381 Binder.restoreCallingIdentity(identity);
3382 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003383 }
3384
3385 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003386 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3387 String callingAttributionTag, int subId, String number, int port, String text,
3388 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003389 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003390 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003391 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003392 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003393 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3394 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003395 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003396
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003397 /**
fionaxu0152e512016-11-14 13:36:14 -08003398 * Sets the voice activation state of a given subId.
3399 */
3400 @Override
3401 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003402 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3403 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404
3405 final long identity = Binder.clearCallingIdentity();
3406 try {
3407 final Phone phone = getPhone(subId);
3408 if (phone != null) {
3409 phone.setVoiceActivationState(activationState);
3410 } else {
3411 loge("setVoiceActivationState fails with invalid subId: " + subId);
3412 }
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003415 }
3416 }
3417
3418 /**
3419 * Sets the data activation state of a given subId.
3420 */
3421 @Override
3422 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003423 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3424 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 final Phone phone = getPhone(subId);
3429 if (phone != null) {
3430 phone.setDataActivationState(activationState);
3431 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003432 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433 }
3434 } finally {
3435 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003436 }
3437 }
3438
3439 /**
3440 * Returns the voice activation state of a given subId.
3441 */
3442 @Override
3443 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003445
fionaxu0152e512016-11-14 13:36:14 -08003446 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447 final long identity = Binder.clearCallingIdentity();
3448 try {
3449 if (phone != null) {
3450 return phone.getVoiceActivationState();
3451 } else {
3452 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3453 }
3454 } finally {
3455 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003456 }
3457 }
3458
3459 /**
3460 * Returns the data activation state of a given subId.
3461 */
3462 @Override
3463 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465
fionaxu0152e512016-11-14 13:36:14 -08003466 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003467 final long identity = Binder.clearCallingIdentity();
3468 try {
3469 if (phone != null) {
3470 return phone.getDataActivationState();
3471 } else {
3472 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3473 }
3474 } finally {
3475 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003476 }
3477 }
3478
3479 /**
Wink Saville36469e72014-06-11 15:17:00 -07003480 * Returns the unread count of voicemails for a subId
3481 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003483 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3484 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003485 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003486 mApp, subId, callingPackage, callingFeatureId,
3487 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003488 return 0;
3489 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003490 final long identity = Binder.clearCallingIdentity();
3491 try {
3492 final Phone phone = getPhone(subId);
3493 if (phone != null) {
3494 return phone.getVoiceMessageCount();
3495 } else {
3496 return 0;
3497 }
3498 } finally {
3499 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003500 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003501 }
3502
3503 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003504 * returns true, if the device is in a state where both voice and data
3505 * are supported simultaneously. This can change based on location or network condition.
3506 */
3507 @Override
3508 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003509 final long identity = Binder.clearCallingIdentity();
3510 try {
3511 final Phone phone = getPhone(subId);
3512 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3513 } finally {
3514 Binder.restoreCallingIdentity(identity);
3515 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003516 }
3517
3518 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003519 * Send the dialer code if called from the current default dialer or the caller has
3520 * carrier privilege.
3521 * @param inputCode The dialer code to send
3522 */
3523 @Override
3524 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003526 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003527 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3528 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003529 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003530 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003531 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003532 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003533
3534 final long identity = Binder.clearCallingIdentity();
3535 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003536 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003537 } finally {
3538 Binder.restoreCallingIdentity(identity);
3539 }
fionaxu235cc5e2017-03-06 22:25:57 -08003540 }
3541
Pengquan Menga1bb6272018-09-06 09:59:22 -07003542 @Override
3543 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003544 TelephonyPermissions
3545 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3546 mApp, subId, "getNetworkSelectionMode");
3547 final long identity = Binder.clearCallingIdentity();
3548 try {
3549 if (!isActiveSubscription(subId)) {
3550 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3551 }
3552 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3553 } finally {
3554 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003555 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003556 }
3557
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003559 public boolean isInEmergencySmsMode() {
3560 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3561 final long identity = Binder.clearCallingIdentity();
3562 try {
3563 for (Phone phone : PhoneFactory.getPhones()) {
3564 if (phone.isInEmergencySmsMode()) {
3565 return true;
3566 }
3567 }
3568 } finally {
3569 Binder.restoreCallingIdentity(identity);
3570 }
3571 return false;
3572 }
3573
shilu366312e2019-12-17 09:28:10 -08003574 /**
3575 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3576 * @param subId The subscription to use to check the configuration.
3577 * @param c The callback that will be used to send the result.
3578 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003579 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003580 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3581 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003582 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3583 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003584
Brad Ebinger77b832e2019-10-17 17:03:22 -07003585 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3586 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3587 "IMS not available on device.");
3588 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 final long token = Binder.clearCallingIdentity();
3590 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003591 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003592 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003594 } catch (ImsException e) {
3595 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 } finally {
3597 Binder.restoreCallingIdentity(token);
3598 }
3599 }
3600
shilu366312e2019-12-17 09:28:10 -08003601 /**
3602 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3603 * @param subId The subscription to use to check the configuration.
3604 * @param c The callback that will be used to send the result.
3605 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003607 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003608 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3609 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003610 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3611 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3612 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003613 final long token = Binder.clearCallingIdentity();
3614 try {
3615 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3616 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3617 .removeRegistrationCallbackForSubscription(c, subId);
3618 } catch (ImsException e) {
3619 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3620 + "is inactive, ignoring unregister.");
3621 // If the subscription is no longer active, just return, since the callback
3622 // will already have been removed internally.
3623 } finally {
3624 Binder.restoreCallingIdentity(token);
3625 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003626 }
3627
Brad Ebinger774ba362019-10-22 17:36:18 -07003628 /**
3629 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3630 */
3631 @Override
3632 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3633 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3634 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3635 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3636 "IMS not available on device.");
3637 }
3638 final long token = Binder.clearCallingIdentity();
3639 try {
3640 Phone phone = getPhone(subId);
3641 if (phone == null) {
3642 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3643 + subId + "'");
3644 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3645 }
3646 phone.getImsRegistrationState(regState -> {
3647 try {
3648 consumer.accept((regState == null)
3649 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3650 } catch (RemoteException e) {
3651 // Ignore if the remote process is no longer available to call back.
3652 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3653 }
3654 });
3655 } finally {
3656 Binder.restoreCallingIdentity(token);
3657 }
3658 }
3659
3660 /**
3661 * Get the transport type for the IMS service registration state.
3662 */
3663 @Override
3664 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003665 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3666 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003667 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3669 "IMS not available on device.");
3670 }
3671 final long token = Binder.clearCallingIdentity();
3672 try {
3673 Phone phone = getPhone(subId);
3674 if (phone == null) {
3675 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3676 + subId + "'");
3677 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3678 }
3679 phone.getImsRegistrationTech(regTech -> {
3680 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3681 int regTechConverted = (regTech == null)
3682 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3683 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3684 regTechConverted);
3685 try {
3686 consumer.accept(regTechConverted);
3687 } catch (RemoteException e) {
3688 // Ignore if the remote process is no longer available to call back.
3689 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3690 }
3691 });
3692 } finally {
3693 Binder.restoreCallingIdentity(token);
3694 }
3695 }
3696
shilu366312e2019-12-17 09:28:10 -08003697 /**
3698 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3699 * @param subId The subscription to use to check the configuration.
3700 * @param c The callback that will be used to send the result.
3701 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003702 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003703 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3704 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003705 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3706 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003707 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3708 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3709 "IMS not available on device.");
3710 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3712 final long token = Binder.clearCallingIdentity();
3713 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003714 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003716 } catch (ImsException e) {
3717 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 } finally {
3719 Binder.restoreCallingIdentity(token);
3720 }
3721 }
3722
shilu366312e2019-12-17 09:28:10 -08003723 /**
3724 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3725 * @param subId The subscription to use to check the configuration.
3726 * @param c The callback that will be used to send the result.
3727 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003728 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003729 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003730 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3731 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003732 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3733 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3734 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003735
3736 final long token = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003740 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003741 } catch (ImsException e) {
3742 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3743 + "is inactive, ignoring unregister.");
3744 // If the subscription is no longer active, just return, since the callback
3745 // will already have been removed internally.
3746 } finally {
3747 Binder.restoreCallingIdentity(token);
3748 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 }
3750
3751 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003752 public boolean isCapable(int subId, int capability, int regTech) {
3753 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3755 final long token = Binder.clearCallingIdentity();
3756 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003757 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003759 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003760 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3761 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003763 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3764 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 } finally {
3766 Binder.restoreCallingIdentity(token);
3767 }
3768 }
3769
3770 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003771 public boolean isAvailable(int subId, int capability, int regTech) {
3772 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 final long token = Binder.clearCallingIdentity();
3774 try {
3775 Phone phone = getPhone(subId);
3776 if (phone == null) return false;
3777 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003778 } catch (com.android.ims.ImsException e) {
3779 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3780 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003781 } finally {
3782 Binder.restoreCallingIdentity(token);
3783 }
3784 }
3785
Brad Ebinger77b832e2019-10-17 17:03:22 -07003786 /**
3787 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3788 * subscription.
3789 * @param subId The subscription to use to check the configuration.
3790 * @param callback The callback that will be used to send the result.
3791 * @param capability The MmTelFeature capability that will be used to send the result.
3792 * @param transportType The transport type of the MmTelFeature capability.
3793 */
3794 @Override
3795 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3796 int transportType) {
3797 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3798 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3799 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3800 "IMS not available on device.");
3801 }
3802 final long token = Binder.clearCallingIdentity();
3803 try {
3804 int slotId = getSlotIndex(subId);
3805 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3806 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3807 + subId + "'");
3808 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3809 }
3810 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3811 transportType, aBoolean -> {
3812 try {
3813 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3814 } catch (RemoteException e) {
3815 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3816 + "running. Ignore");
3817 }
3818 });
3819 } finally {
3820 Binder.restoreCallingIdentity(token);
3821 }
3822 }
3823
shilu366312e2019-12-17 09:28:10 -08003824 /**
3825 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3826 * @param subId The subscription to use to check the configuration.
3827 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 @Override
3829 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003830 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3831 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003832
Brad Ebinger35c841c2018-10-01 10:40:55 -07003833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3834 final long token = Binder.clearCallingIdentity();
3835 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003836 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003838 } catch (ImsException e) {
3839 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 } finally {
3841 Binder.restoreCallingIdentity(token);
3842 }
3843 }
3844
3845 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003846 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003848 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003849 final long identity = Binder.clearCallingIdentity();
3850 try {
3851 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003852 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 } catch (ImsException e) {
3855 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003856 } finally {
3857 Binder.restoreCallingIdentity(identity);
3858 }
3859 }
3860
shilu366312e2019-12-17 09:28:10 -08003861 /**
3862 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3863 * @param subId The subscription to use to check the configuration.
3864 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003865 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003866 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003867 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3868 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003872 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3873 } catch (ImsException e) {
3874 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 } finally {
3876 Binder.restoreCallingIdentity(identity);
3877 }
3878 }
3879
3880 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003881 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003883 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 final long identity = Binder.clearCallingIdentity();
3885 try {
3886 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003888 } catch (ImsException e) {
3889 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 } finally {
3891 Binder.restoreCallingIdentity(identity);
3892 }
3893 }
3894
shilu366312e2019-12-17 09:28:10 -08003895 /**
3896 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3897 * @param subId The subscription to use to check the configuration.
3898 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 @Override
3900 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003901 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3902 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 final long identity = Binder.clearCallingIdentity();
3904 try {
3905 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003906 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003908 } catch (ImsException e) {
3909 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 } finally {
3911 Binder.restoreCallingIdentity(identity);
3912 }
3913 }
3914
3915 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003916 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003918 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 final long identity = Binder.clearCallingIdentity();
3920 try {
3921 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003922 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003923 } catch (ImsException e) {
3924 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003925 } finally {
3926 Binder.restoreCallingIdentity(identity);
3927 }
3928 }
3929
shilu366312e2019-12-17 09:28:10 -08003930 /**
3931 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3932 * @param subId The subscription to use to check the configuration.
3933 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 @Override
3935 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003936 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3937 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 final long identity = Binder.clearCallingIdentity();
3939 try {
3940 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003941 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003942 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003943 } catch (ImsException e) {
3944 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003945 } finally {
3946 Binder.restoreCallingIdentity(identity);
3947 }
3948 }
3949
3950 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003951 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003953 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 final long identity = Binder.clearCallingIdentity();
3955 try {
3956 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003957 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003959 } catch (ImsException e) {
3960 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
3964 }
3965
3966 @Override
3967 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3969 "setVoWiFiNonPersistent");
3970 final long identity = Binder.clearCallingIdentity();
3971 try {
3972 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003973 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003974 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003975 } catch (ImsException e) {
3976 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 } finally {
3978 Binder.restoreCallingIdentity(identity);
3979 }
3980 }
3981
shilu366312e2019-12-17 09:28:10 -08003982 /**
3983 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3984 * @param subId The subscription to use to check the configuration.
3985 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 @Override
3987 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003988 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3989 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 final long identity = Binder.clearCallingIdentity();
3991 try {
3992 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003993 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003995 } catch (ImsException e) {
3996 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003997 } finally {
3998 Binder.restoreCallingIdentity(identity);
3999 }
4000 }
4001
4002 @Override
4003 public void setVoWiFiModeSetting(int subId, int mode) {
4004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4005 "setVoWiFiModeSetting");
4006 final long identity = Binder.clearCallingIdentity();
4007 try {
4008 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004009 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004011 } catch (ImsException e) {
4012 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004013 } finally {
4014 Binder.restoreCallingIdentity(identity);
4015 }
4016 }
4017
4018 @Override
4019 public int getVoWiFiRoamingModeSetting(int subId) {
4020 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4021 final long identity = Binder.clearCallingIdentity();
4022 try {
4023 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004024 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004026 } catch (ImsException e) {
4027 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 } finally {
4029 Binder.restoreCallingIdentity(identity);
4030 }
4031 }
4032
4033 @Override
4034 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4035 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4036 "setVoWiFiRoamingModeSetting");
4037 final long identity = Binder.clearCallingIdentity();
4038 try {
4039 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004040 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004042 } catch (ImsException e) {
4043 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 } finally {
4045 Binder.restoreCallingIdentity(identity);
4046 }
4047 }
4048
4049 @Override
4050 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4051 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4052 "setRttCapabilityEnabled");
4053 final long identity = Binder.clearCallingIdentity();
4054 try {
4055 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004056 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4057 } catch (ImsException e) {
4058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
4062 }
4063
shilu366312e2019-12-17 09:28:10 -08004064 /**
4065 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4066 * @param subId The subscription to use to check the configuration.
4067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 @Override
4069 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004070 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4071 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004077 } catch (ImsException e) {
4078 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
4082 }
4083
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004084 @Override
4085 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4086 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4087 final long identity = Binder.clearCallingIdentity();
4088 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004089 if (!isImsAvailableOnDevice()) {
4090 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4091 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004092 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004095 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
4097 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004098 } finally {
4099 Binder.restoreCallingIdentity(identity);
4100 }
4101 }
4102
4103 @Override
4104 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4105 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4106 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004107 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4108 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4109 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004110 try {
4111 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004112 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004113 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004114 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004115 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4116 + "is inactive, ignoring unregister.");
4117 // If the subscription is no longer active, just return, since the callback will already
4118 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004119 } finally {
4120 Binder.restoreCallingIdentity(identity);
4121 }
4122 }
4123
allenwtsu99c623b2020-01-03 18:24:23 +08004124
4125 private void checkModifyPhoneStatePermission(int subId, String message) {
4126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4127 message);
4128 }
4129
4130 private boolean isImsProvisioningRequired(int subId, int capability,
4131 boolean isMmtelCapability) {
4132 Phone phone = getPhone(subId);
4133 if (phone == null) {
4134 loge("phone instance null for subid " + subId);
4135 return false;
4136 }
4137 if (isMmtelCapability) {
4138 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4139 return false;
4140 }
4141 } else {
4142 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4143 return false;
4144 }
4145 }
4146 return true;
4147 }
4148
4149 @Override
4150 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4151 boolean isProvisioned) {
4152 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4153
4154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4157 if (!isImsProvisioningRequired(subId, capability, false)) {
4158 return;
4159 }
4160
4161 // this capability requires provisioning, route to the correct API.
4162 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4163 switch (capability) {
4164 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4165 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4166 ims.setEabProvisioned(isProvisioned);
4167 break;
4168 default: {
4169 throw new IllegalArgumentException("Tried to set provisioning for "
4170 + "rcs capability '" + capability + "', which does not require "
4171 + "provisioning.");
4172 }
4173 }
4174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177
4178 }
4179
4180
4181 @Override
4182 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4183 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4184 final long identity = Binder.clearCallingIdentity();
4185 try {
4186 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4187 if (!isImsProvisioningRequired(subId, capability, false)) {
4188 return true;
4189 }
4190
4191 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4192 switch (capability) {
4193 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4194 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4195 return ims.isEabProvisionedOnDevice();
4196
4197 default: {
4198 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4199 + "capability '" + capability + "', which does not require "
4200 + "provisioning.");
4201 }
4202 }
4203
4204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004210 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4211 boolean isProvisioned) {
4212 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4213 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4214 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4215 }
allenwtsu99c623b2020-01-03 18:24:23 +08004216 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004217 final long identity = Binder.clearCallingIdentity();
4218 try {
4219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004220 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004221 return;
4222 }
4223
4224 // this capability requires provisioning, route to the correct API.
4225 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4226 switch (capability) {
4227 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4228 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4229 ims.setVolteProvisioned(isProvisioned);
4230 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4231 ims.setWfcProvisioned(isProvisioned);
4232 }
4233 break;
4234 }
4235 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4236 // There is currently no difference in VT provisioning type.
4237 ims.setVtProvisioned(isProvisioned);
4238 break;
4239 }
4240 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4241 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4242 // change the capability of the feature instead if needed.
4243 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4244 == isProvisioned) {
4245 // No change in provisioning.
4246 return;
4247 }
4248 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4249 try {
4250 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004251 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004252 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4253 + ", Exception" + e.getMessage());
4254 }
4255 break;
4256 }
4257 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004258 throw new IllegalArgumentException("Tried to set provisioning for "
4259 + "MmTel capability '" + capability + "', which does not require "
4260 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004261 }
4262 }
4263
4264 } finally {
4265 Binder.restoreCallingIdentity(identity);
4266 }
4267 }
4268
4269 @Override
4270 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4271 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4272 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4273 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4274 }
4275 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4276 final long identity = Binder.clearCallingIdentity();
4277 try {
4278 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004279 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004280 return true;
4281 }
4282
4283 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4284 switch (capability) {
4285 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4286 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4287 return ims.isVolteProvisionedOnDevice();
4288 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4289 return ims.isWfcProvisionedOnDevice();
4290 }
4291 // This should never happen, since we are checking tech above to make sure it
4292 // is either LTE or IWLAN.
4293 throw new IllegalArgumentException("Invalid radio technology for voice "
4294 + "capability.");
4295 }
4296 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4297 // There is currently no difference in VT provisioning type.
4298 return ims.isVtProvisionedOnDevice();
4299 }
4300 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4301 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4302 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4303 }
4304 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004305 throw new IllegalArgumentException(
4306 "Tried to get provisioning for MmTel capability '" + capability
4307 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004308 }
4309 }
4310
4311 } finally {
4312 Binder.restoreCallingIdentity(identity);
4313 }
4314 }
4315
4316 @Override
4317 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4318 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4319 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4320 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4321 }
4322 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4323 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4324 return (provisionedBits & capability) > 0;
4325 }
4326
4327 @Override
4328 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4329 boolean isProvisioned) {
4330 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4331 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4332 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4333 }
4334 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4335 "setProvisioningStatusForCapability");
4336 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4337 // If the current provisioning status for capability already matches isProvisioned,
4338 // do nothing.
4339 if (((provisionedBits & capability) > 0) == isProvisioned) {
4340 return;
4341 }
4342 if (isProvisioned) {
4343 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4344 } else {
4345 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4346 }
4347 }
4348
4349 /**
4350 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4351 * technology. The bitfield should mirror the bitfield defined by
4352 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4353 */
4354 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4355 String key = getMmTelProvisioningKey(subId, tech);
4356 // Default is no capabilities are provisioned.
4357 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4358 }
4359
4360 /**
4361 * Sets the MmTel capability provisioning bitfield (defined by
4362 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4363 * technology specified.
4364 *
4365 * Note: This is a synchronous command and should not be called on UI thread.
4366 */
4367 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4368 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4369 String key = getMmTelProvisioningKey(subId, tech);
4370 editor.putInt(key, newField);
4371 editor.commit();
4372 }
4373
4374 private static String getMmTelProvisioningKey(int subId, int tech) {
4375 // resulting key is provision_ims_mmtel_{subId}_{tech}
4376 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4377 }
4378
4379 /**
4380 * Query CarrierConfig to see if the specified capability requires provisioning for the
4381 * carrier associated with the subscription id.
4382 */
4383 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4384 int capability) {
4385 CarrierConfigManager configManager = new CarrierConfigManager(context);
4386 PersistableBundle c = configManager.getConfigForSubId(subId);
4387 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004388 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004389 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4390 false);
4391 boolean requireVoiceVtProvisioning = c.getBoolean(
4392 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4393
4394 // First check to make sure that the capability requires provisioning.
4395 switch (capability) {
4396 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4397 // intentional fallthrough
4398 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4399 if (requireVoiceVtProvisioning) {
4400 // Voice and Video requires provisioning
4401 return true;
4402 }
4403 break;
4404 }
4405 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4406 if (requireUtProvisioning) {
4407 // UT requires provisioning
4408 return true;
4409 }
4410 break;
4411 }
4412 }
4413 return false;
4414 }
4415
allenwtsu99c623b2020-01-03 18:24:23 +08004416 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4417 int capability) {
4418 CarrierConfigManager configManager = new CarrierConfigManager(context);
4419 PersistableBundle c = configManager.getConfigForSubId(subId);
4420
4421 boolean requireRcsProvisioning = c.getBoolean(
4422 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4423
4424 // First check to make sure that the capability requires provisioning.
4425 switch (capability) {
4426 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4427 // intentional fallthrough
4428 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4429 if (requireRcsProvisioning) {
4430 // OPTION or PRESENCE requires provisioning
4431 return true;
4432 }
4433 break;
4434 }
4435 }
4436 return false;
4437 }
4438
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004439 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004440 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004441 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4442 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4443 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004444 enforceReadPrivilegedPermission("getImsProvisioningInt");
4445 final long identity = Binder.clearCallingIdentity();
4446 try {
4447 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004448 int slotId = getSlotIndex(subId);
4449 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4450 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4451 + subId + "' for key:" + key);
4452 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4453 }
4454 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004455 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004456 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4457 + subId + "' for key:" + key);
4458 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004459 } finally {
4460 Binder.restoreCallingIdentity(identity);
4461 }
4462 }
4463
4464 @Override
4465 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004466 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4467 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4468 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004469 enforceReadPrivilegedPermission("getImsProvisioningString");
4470 final long identity = Binder.clearCallingIdentity();
4471 try {
4472 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004473 int slotId = getSlotIndex(subId);
4474 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4475 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4476 + subId + "' for key:" + key);
4477 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4478 }
4479 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004480 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004481 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4482 + subId + "' for key:" + key);
4483 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004484 } finally {
4485 Binder.restoreCallingIdentity(identity);
4486 }
4487 }
4488
4489 @Override
4490 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004491 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4492 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4493 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004494 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4495 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004496 final long identity = Binder.clearCallingIdentity();
4497 try {
4498 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004499 int slotId = getSlotIndex(subId);
4500 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4501 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4502 + subId + "' for key:" + key);
4503 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4504 }
4505 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004506 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004507 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4508 + "' for key:" + key);
4509 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004510 } finally {
4511 Binder.restoreCallingIdentity(identity);
4512 }
4513 }
4514
4515 @Override
4516 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004517 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4518 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4519 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4521 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004522 final long identity = Binder.clearCallingIdentity();
4523 try {
4524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004525 int slotId = getSlotIndex(subId);
4526 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4527 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4528 + subId + "' for key:" + key);
4529 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4530 }
4531 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004532 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004533 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4534 + "' for key:" + key);
4535 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004536 } finally {
4537 Binder.restoreCallingIdentity(identity);
4538 }
4539 }
4540
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004541 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004542 int slotId = SubscriptionManager.getSlotIndex(subId);
4543 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004544 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4545 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004546 }
4547 return slotId;
4548 }
4549
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004550 private int getSlotIndex(int subId) {
4551 int slotId = SubscriptionManager.getSlotIndex(subId);
4552 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4553 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4554 }
4555 return slotId;
4556 }
4557
Wink Saville36469e72014-06-11 15:17:00 -07004558 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004559 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004560 */
4561 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004562 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4563 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004564 final int targetSdk = getTargetSdk(callingPackage);
4565 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004566 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004567 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004568 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004569 mApp, subId, callingPackage, callingFeatureId,
4570 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004571 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4572 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004573
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004574 final long identity = Binder.clearCallingIdentity();
4575 try {
4576 final Phone phone = getPhone(subId);
4577 if (phone != null) {
4578 return phone.getServiceState().getDataNetworkType();
4579 } else {
4580 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4581 }
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004584 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004585 }
4586
4587 /**
4588 * Returns the data network type
4589 */
4590 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004591 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4592 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4593 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004594 }
4595
4596 /**
4597 * Returns the data network type for a subId
4598 */
4599 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004600 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4601 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004602 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004603 mApp, subId, callingPackage, callingFeatureId,
4604 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004605 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4606 }
4607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004608 final long identity = Binder.clearCallingIdentity();
4609 try {
4610 final Phone phone = getPhone(subId);
4611 if (phone != null) {
4612 return phone.getServiceState().getDataNetworkType();
4613 } else {
4614 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4615 }
4616 } finally {
4617 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004618 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004619 }
4620
4621 /**
Wink Saville36469e72014-06-11 15:17:00 -07004622 * Returns the Voice network type for a subId
4623 */
4624 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004625 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4626 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004628 mApp, subId, callingPackage, callingFeatureId,
4629 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004630 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4631 }
4632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 final long identity = Binder.clearCallingIdentity();
4634 try {
4635 final Phone phone = getPhone(subId);
4636 if (phone != null) {
4637 return phone.getServiceState().getVoiceNetworkType();
4638 } else {
4639 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4640 }
4641 } finally {
4642 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004643 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004644 }
4645
4646 /**
4647 * @return true if a ICC card is present
4648 */
4649 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004650 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004651 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4652 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004653 }
4654
4655 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004656 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004657 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004658 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004659 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004660 final long identity = Binder.clearCallingIdentity();
4661 try {
4662 final Phone phone = PhoneFactory.getPhone(slotIndex);
4663 if (phone != null) {
4664 return phone.getIccCard().hasIccCard();
4665 } else {
4666 return false;
4667 }
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004670 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004671 }
4672
4673 /**
4674 * Return if the current radio is LTE on CDMA. This
4675 * is a tri-state return value as for a period of time
4676 * the mode may be unknown.
4677 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004678 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004679 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004680 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004681 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004682 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004683 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4684 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4685 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004686 }
4687
Sanket Padawe356d7632015-06-22 14:03:32 -07004688 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004689 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4690 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004691 try {
4692 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4693 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004694 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4695 }
4696
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697 final long identity = Binder.clearCallingIdentity();
4698 try {
4699 final Phone phone = getPhone(subId);
4700 if (phone == null) {
4701 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4702 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004703 return TelephonyProperties.lte_on_cdma_device()
4704 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004705 }
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004708 }
Wink Saville36469e72014-06-11 15:17:00 -07004709 }
4710
Wink Saville36469e72014-06-11 15:17:00 -07004711 /**
4712 * {@hide}
4713 * Returns Default subId, 0 in the case of single standby.
4714 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004715 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004716 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004717 }
4718
Shishir Agrawala9f32182016-04-12 12:00:16 -07004719 private int getSlotForDefaultSubscription() {
4720 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4721 }
4722
Wink Savilleb564aae2014-10-23 10:18:09 -07004723 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004724 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004725 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004726
Pengquan Menge92a50d2018-09-21 15:54:48 -07004727 private boolean isActiveSubscription(int subId) {
4728 return mSubscriptionController.isActiveSubId(subId);
4729 }
4730
Ihab Awadf2177b72013-11-25 13:33:23 -08004731 /**
4732 * @see android.telephony.TelephonyManager.WifiCallingChoices
4733 */
4734 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 final long identity = Binder.clearCallingIdentity();
4736 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004737 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4739 getWhenToMakeWifiCallsDefaultPreference());
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
4742 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004743 }
4744
4745 /**
4746 * @see android.telephony.TelephonyManager.WifiCallingChoices
4747 */
4748 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004749 final long identity = Binder.clearCallingIdentity();
4750 try {
4751 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004752 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004753 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4754 } finally {
4755 Binder.restoreCallingIdentity(identity);
4756 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004757 }
4758
Sailesh Nepald1e68152013-12-12 19:08:02 -08004759 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004760 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004761 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004762 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004763
Jordan Liu4c733742019-02-28 12:03:40 -08004764 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4765 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4766 if (phoneId == -1) {
4767 throw new IllegalArgumentException("Given slot index: " + slotIndex
4768 + " does not correspond to an active phone");
4769 }
4770 return PhoneFactory.getPhone(phoneId);
4771 }
4772
Shishir Agrawal566b7612013-10-28 14:41:00 -07004773 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004774 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4775 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4777 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004778 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004779 if (DBG) {
4780 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4781 }
4782 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4783 p2);
4784 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004785
Jordan Liu4c733742019-02-28 12:03:40 -08004786
4787 @Override
4788 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4789 int slotIndex, String callingPackage, String aid, int p2) {
4790 enforceModifyPermission();
4791 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4792 if (DBG) {
4793 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4794 }
4795 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4796 callingPackage, aid, p2);
4797 }
4798
4799 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4800 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 final long identity = Binder.clearCallingIdentity();
4802 try {
4803 if (TextUtils.equals(ISDR_AID, aid)) {
4804 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004805 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4806 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004807 if (bestComponent == null
4808 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4809 loge("The calling package is not allowed to access ISD-R.");
4810 throw new SecurityException(
4811 "The calling package is not allowed to access ISD-R.");
4812 }
Derek Tan740e1672017-06-27 14:56:27 -07004813 }
Derek Tan740e1672017-06-27 14:56:27 -07004814
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004815 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004816 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4817 null /* workSource */);
4818 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819 return response;
4820 } finally {
4821 Binder.restoreCallingIdentity(identity);
4822 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004823 }
4824
4825 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004826 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4828 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004829 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4830 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4831 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004832
Jordan Liu4c733742019-02-28 12:03:40 -08004833 @Override
4834 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4835 enforceModifyPermission();
4836 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4837 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4838 channel);
4839 }
4840
4841 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004842 final long identity = Binder.clearCallingIdentity();
4843 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004844 if (channel < 0) {
4845 return false;
4846 }
Jordan Liu4c733742019-02-28 12:03:40 -08004847 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4848 null /* workSource */);
4849 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004850 return success;
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004853 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004854 }
4855
4856 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004857 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004858 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004859 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4860 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004861 if (DBG) {
4862 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4863 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4864 + p3 + " data=" + data);
4865 }
4866 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4867 command, p1, p2, p3, data);
4868 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004869
Jordan Liu4c733742019-02-28 12:03:40 -08004870 @Override
4871 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4872 int command, int p1, int p2, int p3, String data) {
4873 enforceModifyPermission();
4874 if (DBG) {
4875 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4876 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4877 + p3 + " data=" + data);
4878 }
4879 return iccTransmitApduLogicalChannelWithPermission(
4880 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4881 data);
4882 }
4883
4884 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4885 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004886 final long identity = Binder.clearCallingIdentity();
4887 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004888 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 return "";
4890 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004891
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004892 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004893 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4894 null /* workSource */);
4895 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 // Append the returned status code to the end of the response payload.
4898 String s = Integer.toHexString(
4899 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4900 if (response.payload != null) {
4901 s = IccUtils.bytesToHexString(response.payload) + s;
4902 }
4903 return s;
4904 } finally {
4905 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004906 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004907 }
Jake Hambye994d462014-02-03 13:10:13 -08004908
Evan Charltonc66da362014-05-16 14:06:40 -07004909 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004910 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4911 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004912 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4913 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004915 if (DBG) {
4916 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4917 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4918 }
4919 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4920 cla, command, p1, p2, p3, data);
4921 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004922
Jordan Liu4c733742019-02-28 12:03:40 -08004923 @Override
4924 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4925 int command, int p1, int p2, int p3, String data) {
4926 enforceModifyPermission();
4927 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4928 if (DBG) {
4929 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4930 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4931 + " data=" + data);
4932 }
4933
4934 return iccTransmitApduBasicChannelWithPermission(
4935 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4936 p2, p3, data);
4937 }
4938
4939 // open APDU basic channel assuming the caller has sufficient permissions
4940 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4941 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4945 && TextUtils.equals(ISDR_AID, data)) {
4946 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004947 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4948 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 if (bestComponent == null
4950 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4951 loge("The calling package is not allowed to select ISD-R.");
4952 throw new SecurityException(
4953 "The calling package is not allowed to select ISD-R.");
4954 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004955 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004956
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004957 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004958 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4959 null /* workSource */);
4960 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 // Append the returned status code to the end of the response payload.
4963 String s = Integer.toHexString(
4964 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4965 if (response.payload != null) {
4966 s = IccUtils.bytesToHexString(response.payload) + s;
4967 }
4968 return s;
4969 } finally {
4970 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004971 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004972 }
4973
4974 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004975 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004976 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4978 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004979
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 final long identity = Binder.clearCallingIdentity();
4981 try {
4982 if (DBG) {
4983 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4984 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4985 }
4986
4987 IccIoResult response =
4988 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4989 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4990 subId);
4991
4992 if (DBG) {
4993 log("Exchange SIM_IO [R]" + response);
4994 }
4995
4996 byte[] result = null;
4997 int length = 2;
4998 if (response.payload != null) {
4999 length = 2 + response.payload.length;
5000 result = new byte[length];
5001 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5002 } else {
5003 result = new byte[length];
5004 }
5005
5006 result[length - 1] = (byte) response.sw2;
5007 result[length - 2] = (byte) response.sw1;
5008 return result;
5009 } finally {
5010 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005011 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005012 }
5013
Nathan Haroldb3014052017-01-25 15:57:32 -08005014 /**
5015 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5016 * on a particular subscription
5017 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005018 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5019 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005020 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005021 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005022 return null;
5023 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024
5025 final long identity = Binder.clearCallingIdentity();
5026 try {
5027 if (appType != TelephonyManager.APPTYPE_USIM
5028 && appType != TelephonyManager.APPTYPE_SIM) {
5029 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5030 return null;
5031 }
5032 Object response = sendRequest(
5033 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5034 if (response instanceof String[]) {
5035 return (String[]) response;
5036 }
yincheng zhaod698b842019-09-06 17:06:54 -07005037 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005039 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 } finally {
5041 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005042 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005043 }
5044
yincheng zhaod698b842019-09-06 17:06:54 -07005045 /**
5046 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5047 * subscription.
5048 *
5049 * @param subId the id of the subscription.
5050 * @param appType the uicc app type, must be USIM or SIM.
5051 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5052 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005053 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005054 * @return number of fplmns that is successfully written to the SIM.
5055 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005056 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5057 String callingFeatureId) {
5058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5059 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005060 if (DBG) logv("no permissions for setForbiddenplmns");
5061 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5062 }
5063 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5064 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5065 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5066 }
5067 if (fplmns == null) {
5068 throw new IllegalArgumentException("Fplmn List provided is null");
5069 }
5070 for (String fplmn : fplmns) {
5071 if (!CellIdentity.isValidPlmn(fplmn)) {
5072 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5073 }
5074 }
5075 final long identity = Binder.clearCallingIdentity();
5076 try {
5077 Object response = sendRequest(
5078 CMD_SET_FORBIDDEN_PLMNS,
5079 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5080 subId);
5081 return (int) response;
5082 } finally {
5083 Binder.restoreCallingIdentity(identity);
5084 }
5085 }
5086
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005087 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005088 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5090 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 final long identity = Binder.clearCallingIdentity();
5093 try {
5094 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5095 if (response.payload == null) {
5096 return "";
5097 }
Evan Charltonc66da362014-05-16 14:06:40 -07005098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005099 // Append the returned status code to the end of the response payload.
5100 String s = Integer.toHexString(
5101 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5102 s = IccUtils.bytesToHexString(response.payload) + s;
5103 return s;
5104 } finally {
5105 Binder.restoreCallingIdentity(identity);
5106 }
Evan Charltonc66da362014-05-16 14:06:40 -07005107 }
5108
Jake Hambye994d462014-02-03 13:10:13 -08005109 /**
5110 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5111 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5112 *
5113 * @param itemID the ID of the item to read
5114 * @return the NV item as a String, or null on error.
5115 */
5116 @Override
5117 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005118 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5120 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121
5122 final long identity = Binder.clearCallingIdentity();
5123 try {
5124 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005125 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005126 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5127 return value;
5128 } finally {
5129 Binder.restoreCallingIdentity(identity);
5130 }
Jake Hambye994d462014-02-03 13:10:13 -08005131 }
5132
5133 /**
5134 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5135 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5136 *
5137 * @param itemID the ID of the item to read
5138 * @param itemValue the value to write, as a String
5139 * @return true on success; false on any failure
5140 */
5141 @Override
5142 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005143 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005144 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5145 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146
5147 final long identity = Binder.clearCallingIdentity();
5148 try {
5149 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5150 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005151 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5153 return success;
5154 } finally {
5155 Binder.restoreCallingIdentity(identity);
5156 }
Jake Hambye994d462014-02-03 13:10:13 -08005157 }
5158
5159 /**
5160 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5161 * Used for device configuration by some CDMA operators.
5162 *
5163 * @param preferredRoamingList byte array containing the new PRL
5164 * @return true on success; false on any failure
5165 */
5166 @Override
5167 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005168 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5169 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170
5171 final long identity = Binder.clearCallingIdentity();
5172 try {
5173 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5174 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5175 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5176 return success;
5177 } finally {
5178 Binder.restoreCallingIdentity(identity);
5179 }
Jake Hambye994d462014-02-03 13:10:13 -08005180 }
5181
5182 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005183 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005184 * Used for device configuration by some CDMA operators.
5185 *
chen xu6dac5ab2018-10-26 17:39:23 -07005186 * @param slotIndex - device slot.
5187 *
Jake Hambye994d462014-02-03 13:10:13 -08005188 * @return true on success; false on any failure
5189 */
5190 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005191 public boolean resetModemConfig(int slotIndex) {
5192 Phone phone = PhoneFactory.getPhone(slotIndex);
5193 if (phone != null) {
5194 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5195 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196
chen xu6dac5ab2018-10-26 17:39:23 -07005197 final long identity = Binder.clearCallingIdentity();
5198 try {
5199 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5200 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5201 return success;
5202 } finally {
5203 Binder.restoreCallingIdentity(identity);
5204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 }
chen xu6dac5ab2018-10-26 17:39:23 -07005206 return false;
5207 }
5208
5209 /**
5210 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5211 *
5212 * @param slotIndex - device slot.
5213 *
5214 * @return true on success; false on any failure
5215 */
5216 @Override
5217 public boolean rebootModem(int slotIndex) {
5218 Phone phone = PhoneFactory.getPhone(slotIndex);
5219 if (phone != null) {
5220 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5221 mApp, phone.getSubId(), "rebootModem");
5222
5223 final long identity = Binder.clearCallingIdentity();
5224 try {
5225 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5226 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5227 return success;
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
5231 }
5232 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005233 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005234
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005235 public String[] getPcscfAddress(String apnType, String callingPackage,
5236 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005237 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005238 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5239 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005240 return new String[0];
5241 }
5242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005245 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 } finally {
5247 Binder.restoreCallingIdentity(identity);
5248 }
Wink Saville36469e72014-06-11 15:17:00 -07005249 }
5250
Brad Ebinger51f743a2017-01-23 13:50:20 -08005251 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005252 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5253 * {@link #disableIms(int)}.
5254 * @param slotIndex device slot.
5255 */
5256 public void resetIms(int slotIndex) {
5257 enforceModifyPermission();
5258
5259 final long identity = Binder.clearCallingIdentity();
5260 try {
5261 if (mImsResolver == null) {
5262 // may happen if the does not support IMS.
5263 return;
5264 }
5265 mImsResolver.disableIms(slotIndex);
5266 mImsResolver.enableIms(slotIndex);
5267 } finally {
5268 Binder.restoreCallingIdentity(identity);
5269 }
5270 }
5271
5272 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005273 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5274 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005275 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005276 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005277 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
5279 final long identity = Binder.clearCallingIdentity();
5280 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005281 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005282 // may happen if the device does not support IMS.
5283 return;
5284 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005285 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 } finally {
5287 Binder.restoreCallingIdentity(identity);
5288 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005289 }
5290
5291 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005292 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5293 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005294 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005295 public void disableIms(int slotId) {
5296 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005297
5298 final long identity = Binder.clearCallingIdentity();
5299 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005300 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005301 // may happen if the device does not support IMS.
5302 return;
5303 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005304 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005305 } finally {
5306 Binder.restoreCallingIdentity(identity);
5307 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005308 }
5309
5310 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005311 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5312 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005313 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005314 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005315 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005316 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005317
5318 final long identity = Binder.clearCallingIdentity();
5319 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005320 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005321 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5322 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005323 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005324 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005328 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005329 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005330 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5331 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005332 @Override
5333 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005334 enforceModifyPermission();
5335
5336 final long identity = Binder.clearCallingIdentity();
5337 try {
5338 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005339 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
5343 }
5344
5345 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005346 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005347 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005348 */
5349 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5350 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005351
5352 final long identity = Binder.clearCallingIdentity();
5353 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005354 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005355 // may happen if the device does not support IMS.
5356 return null;
5357 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005358 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005359 } finally {
5360 Binder.restoreCallingIdentity(identity);
5361 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005362 }
5363
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005364 /**
5365 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005366 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005367 */
5368 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5369 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370
5371 final long identity = Binder.clearCallingIdentity();
5372 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005373 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005374 // may happen if the device does not support IMS.
5375 return null;
5376 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005377 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005378 } finally {
5379 Binder.restoreCallingIdentity(identity);
5380 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005381 }
5382
Brad Ebinger884c07b2018-02-15 16:17:40 -08005383 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005384 * Sets the ImsService Package Name that Telephony will bind to.
5385 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005386 * @param slotIndex the slot ID that the ImsService should bind for.
5387 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005388 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005389 * @param featureTypes An integer array of feature types associated with a packageName.
5390 * @param packageName The name of the package that the current configuration will be replaced
5391 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005392 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005393 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005394 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5395 int[] featureTypes, String packageName) {
5396 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5399 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005400 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005401
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402 final long identity = Binder.clearCallingIdentity();
5403 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005404 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005405 // may happen if the device does not support IMS.
5406 return false;
5407 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005408 Map<Integer, String> featureConfig = new HashMap<>();
5409 for (int featureType : featureTypes) {
5410 featureConfig.put(featureType, packageName);
5411 }
5412 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5413 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005414 } finally {
5415 Binder.restoreCallingIdentity(identity);
5416 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005417 }
5418
5419 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005420 * Clears any carrier ImsService overrides for the slot index specified that were previously
5421 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5422 *
5423 * This should only be used for testing.
5424 *
5425 * @param slotIndex the slot ID that the ImsService should bind for.
5426 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5427 */
5428 @Override
5429 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5430 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5431 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5432 "clearCarrierImsServiceOverride");
5433 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5434 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5435 "clearCarrierImsServiceOverride");
5436
5437 final long identity = Binder.clearCallingIdentity();
5438 try {
5439 if (mImsResolver == null) {
5440 // may happen if the device does not support IMS.
5441 return false;
5442 }
5443 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5444 } finally {
5445 Binder.restoreCallingIdentity(identity);
5446 }
5447 }
5448
5449 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005450 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005451 *
5452 * @param slotId The slot that the ImsService is associated with.
5453 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5454 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005456 * @return the package name of the ImsService configuration.
5457 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005458 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5459 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005460 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005461 TelephonyPermissions
5462 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5463 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5464 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005465
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005466 final long identity = Binder.clearCallingIdentity();
5467 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005468 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005469 // may happen if the device does not support IMS.
5470 return "";
5471 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005472 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005473 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5474 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475 } finally {
5476 Binder.restoreCallingIdentity(identity);
5477 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005478 }
5479
Brad Ebinger77b832e2019-10-17 17:03:22 -07005480 /**
5481 * Get the MmTelFeature state associated with the requested subscription id.
5482 * @param subId The subscription that the MmTelFeature is associated with.
5483 * @param callback A callback with an integer containing the
5484 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5485 */
5486 @Override
5487 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5488 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5489 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5490 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5491 "IMS not available on device.");
5492 }
5493 final long token = Binder.clearCallingIdentity();
5494 try {
5495 int slotId = getSlotIndex(subId);
5496 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5497 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5498 + subId + "'");
5499 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5500 }
5501 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5502 try {
5503 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5504 } catch (RemoteException e) {
5505 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5506 + "Ignore");
5507 }
5508 });
5509 } finally {
5510 Binder.restoreCallingIdentity(token);
5511 }
5512 }
5513
Wink Saville36469e72014-06-11 15:17:00 -07005514 public void setImsRegistrationState(boolean registered) {
5515 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005516
5517 final long identity = Binder.clearCallingIdentity();
5518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005519 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 } finally {
5521 Binder.restoreCallingIdentity(identity);
5522 }
Wink Saville36469e72014-06-11 15:17:00 -07005523 }
5524
5525 /**
Stuart Scott54788802015-03-30 13:18:01 -07005526 * Set the network selection mode to automatic.
5527 *
5528 */
5529 @Override
5530 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005531 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5532 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
shilufc958392020-01-20 11:36:01 -08005536 if (!isActiveSubscription(subId)) {
5537 return;
5538 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5540 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Stuart Scott54788802015-03-30 13:18:01 -07005544 }
5545
Jack Yud10cdd42020-09-28 20:28:01 -07005546 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005547 * Ask the radio to connect to the input network and change selection mode to manual.
5548 *
5549 * @param subId the id of the subscription.
5550 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5551 * the operator to attach to.
5552 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5553 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5554 * normal network selection next time.
5555 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005556 */
5557 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005558 public boolean setNetworkSelectionModeManual(
5559 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005560 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5561 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005562
5563 if (!isActiveSubscription(subId)) {
5564 return false;
5565 }
5566
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005567 final long identity = Binder.clearCallingIdentity();
5568 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005569 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005570 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005571 if (DBG) {
5572 log("setNetworkSelectionModeManual: subId: " + subId
5573 + " operator: " + operatorInfo);
5574 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005575 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005579 }
shilu84f6e8b2019-12-19 13:58:01 -08005580 /**
5581 * Get the manual network selection
5582 *
5583 * @param subId the id of the subscription.
5584 *
5585 * @return the previously saved user selected PLMN
5586 */
5587 @Override
5588 public String getManualNetworkSelectionPlmn(int subId) {
5589 TelephonyPermissions
5590 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5591 mApp, subId, "getManualNetworkSelectionPlmn");
5592
5593 final long identity = Binder.clearCallingIdentity();
5594 try {
5595 if (!isActiveSubscription(subId)) {
5596 return "";
5597 }
5598
5599 final Phone phone = getPhone(subId);
5600 if (phone == null) {
5601 return "";
5602 }
5603 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5604 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5605 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5606 } finally {
5607 Binder.restoreCallingIdentity(identity);
5608 }
5609 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005610
5611 /**
5612 * Scans for available networks.
5613 */
5614 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005615 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5616 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005617 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5618 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005619 LocationAccessPolicy.LocationPermissionResult locationResult =
5620 LocationAccessPolicy.checkLocationPermission(mApp,
5621 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5622 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005623 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005624 .setCallingPid(Binder.getCallingPid())
5625 .setCallingUid(Binder.getCallingUid())
5626 .setMethod("getCellNetworkScanResults")
5627 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5628 .build());
5629 switch (locationResult) {
5630 case DENIED_HARD:
5631 throw new SecurityException("Not allowed to access scan results -- location");
5632 case DENIED_SOFT:
5633 return null;
5634 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005635
Pengquan Menga1bb6272018-09-06 09:59:22 -07005636 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005637 try {
5638 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005639 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005640 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005641 } finally {
5642 Binder.restoreCallingIdentity(identity);
5643 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005644 }
5645
5646 /**
sqian80370722020-01-29 15:02:51 -08005647 * Get the call forwarding info, given the call forwarding reason.
5648 */
5649 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005650 public void getCallForwarding(int subId, int callForwardingReason,
5651 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005652 enforceReadPrivilegedPermission("getCallForwarding");
5653 long identity = Binder.clearCallingIdentity();
5654 try {
5655 if (DBG) {
5656 log("getCallForwarding: subId " + subId
5657 + " callForwardingReason" + callForwardingReason);
5658 }
Hall Liua1acea22020-09-18 19:04:59 -07005659
5660 Phone phone = getPhone(subId);
5661 if (phone == null) {
5662 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005663 callback.onError(
5664 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005665 } catch (RemoteException e) {
5666 // ignore
5667 }
5668 return;
5669 }
5670
5671 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5672 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5673 @Override
5674 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5675 try {
5676 callback.onCallForwardingInfoAvailable(info);
5677 } catch (RemoteException e) {
5678 // ignore
5679 }
5680 }
5681
5682 @Override
5683 public void onError(int error) {
5684 try {
5685 callback.onError(error);
5686 } catch (RemoteException e) {
5687 // ignore
5688 }
5689 }
5690 });
5691 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005692 } finally {
5693 Binder.restoreCallingIdentity(identity);
5694 }
5695 }
5696
5697 /**
5698 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5699 * reason, the number to forward, and the timeout before the forwarding is attempted.
5700 */
5701 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005702 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5703 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005704 enforceModifyPermission();
5705 long identity = Binder.clearCallingIdentity();
5706 try {
5707 if (DBG) {
5708 log("setCallForwarding: subId " + subId
5709 + " callForwardingInfo" + callForwardingInfo);
5710 }
Hall Liua1acea22020-09-18 19:04:59 -07005711
5712 Phone phone = getPhone(subId);
5713 if (phone == null) {
5714 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005715 callback.accept(
5716 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005717 } catch (RemoteException e) {
5718 // ignore
5719 }
5720 return;
5721 }
5722
5723 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5724 FunctionalUtils.ignoreRemoteException(callback::accept));
5725
5726 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005727 } finally {
5728 Binder.restoreCallingIdentity(identity);
5729 }
5730 }
5731
5732 /**
Hall Liua1acea22020-09-18 19:04:59 -07005733 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005734 */
5735 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005736 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005737 enforceReadPrivilegedPermission("getCallForwarding");
5738 long identity = Binder.clearCallingIdentity();
5739 try {
Hall Liua1acea22020-09-18 19:04:59 -07005740
5741 Phone phone = getPhone(subId);
5742 if (phone == null) {
5743 try {
5744 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5745 } catch (RemoteException e) {
5746 // ignore
5747 }
5748 return;
5749 }
5750
5751 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5752
sqian80370722020-01-29 15:02:51 -08005753 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005754 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
5758 }
5759
5760 /**
Hall Liua1acea22020-09-18 19:04:59 -07005761 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005762 */
5763 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005764 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005765 enforceModifyPermission();
5766 long identity = Binder.clearCallingIdentity();
5767 try {
Hall Liua1acea22020-09-18 19:04:59 -07005768 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5769
5770 Phone phone = getPhone(subId);
5771 if (phone == null) {
5772 try {
5773 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5774 } catch (RemoteException e) {
5775 // ignore
5776 }
5777 return;
5778 }
5779
5780 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5781 FunctionalUtils.ignoreRemoteException(callback::accept));
5782
5783 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005784 } finally {
5785 Binder.restoreCallingIdentity(identity);
5786 }
5787 }
5788
5789 /**
yinxub1bed742017-04-17 11:45:04 -07005790 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005791 *
yinxub1bed742017-04-17 11:45:04 -07005792 * @param subId id of the subscription
5793 * @param request contains the radio access networks with bands/channels to scan
5794 * @param messenger callback messenger for scan results or errors
5795 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005796 * @return the id of the requested scan which can be used to stop the scan.
5797 */
5798 @Override
5799 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005800 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005801 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5802 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005803 LocationAccessPolicy.LocationPermissionResult locationResult =
5804 LocationAccessPolicy.checkLocationPermission(mApp,
5805 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5806 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005807 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005808 .setCallingPid(Binder.getCallingPid())
5809 .setCallingUid(Binder.getCallingUid())
5810 .setMethod("requestNetworkScan")
5811 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5812 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005813 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005814 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5815 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005816 if (e != null) {
5817 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5818 throw e;
5819 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005820 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005821 return TelephonyScanManager.INVALID_SCAN_ID;
5822 }
5823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005824 }
Hall Liu912dfd32019-04-25 14:02:26 -07005825 int callingUid = Binder.getCallingUid();
5826 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005827 final long identity = Binder.clearCallingIdentity();
5828 try {
5829 return mNetworkScanRequestTracker.startNetworkScan(
5830 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005831 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005832 } finally {
5833 Binder.restoreCallingIdentity(identity);
5834 }
yinxu504e1392017-04-12 16:03:22 -07005835 }
5836
Hall Liub2ac8ef2019-02-28 15:56:23 -08005837 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005838 NetworkScanRequest request, int subId, String callingPackage) {
5839 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005840 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5841 boolean hasNetworkScanPermission =
5842 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5843 == PERMISSION_GRANTED;
5844
5845 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5846 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5847 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005848 }
5849
5850 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5851 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005852 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5853 return new SecurityException("Specific channels must not be"
5854 + " scanned without location access.");
5855 }
5856 }
5857 }
5858
Hall Liub2ac8ef2019-02-28 15:56:23 -08005859 return null;
5860 }
5861
yinxu504e1392017-04-12 16:03:22 -07005862 /**
5863 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005864 *
5865 * @param subId id of the subscription
5866 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005867 */
5868 @Override
5869 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5871 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005872
Hall Liu912dfd32019-04-25 14:02:26 -07005873 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005874 final long identity = Binder.clearCallingIdentity();
5875 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005876 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005877 } finally {
5878 Binder.restoreCallingIdentity(identity);
5879 }
yinxu504e1392017-04-12 16:03:22 -07005880 }
5881
5882 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005883 * Get the calculated preferred network type.
5884 * Used for debugging incorrect network type.
5885 *
5886 * @return the preferred network type, defined in RILConstants.java.
5887 */
5888 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005889 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005890 final Phone defaultPhone = getDefaultPhone();
5891 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005892 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005893 return RILConstants.PREFERRED_NETWORK_MODE;
5894 }
5895
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005896 final long identity = Binder.clearCallingIdentity();
5897 try {
5898 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005899 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005900 } finally {
5901 Binder.restoreCallingIdentity(identity);
5902 }
Junda Liu84d15a22014-07-02 11:21:04 -07005903 }
5904
5905 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005906 * Get the preferred network type.
5907 * Used for device configuration by some CDMA operators.
5908 *
5909 * @return the preferred network type, defined in RILConstants.java.
5910 */
5911 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005912 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005913 TelephonyPermissions
5914 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5915 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005916
5917 final long identity = Binder.clearCallingIdentity();
5918 try {
5919 if (DBG) log("getPreferredNetworkType");
5920 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5921 int networkType = (result != null ? result[0] : -1);
5922 if (DBG) log("getPreferredNetworkType: " + networkType);
5923 return networkType;
5924 } finally {
5925 Binder.restoreCallingIdentity(identity);
5926 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005927 }
5928
5929 /**
5930 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005931 *
5932 * @param networkType the preferred network type, defined in RILConstants.java.
5933 * @return true on success; false on any failure.
5934 */
5935 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005936 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5938 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005939
5940 final long identity = Binder.clearCallingIdentity();
5941 try {
calvinpan089c2a62020-03-12 14:17:55 +08005942 Boolean success = (Boolean) sendRequest(
5943 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005944
5945 if (success) {
5946 Settings.Global.putInt(mApp.getContentResolver(),
5947 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5948 }
calvinpan089c2a62020-03-12 14:17:55 +08005949 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5950 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005951 } finally {
5952 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005953 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005954 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005955
5956 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005957 * Get the allowed network types that store in the telephony provider.
5958 *
5959 * @param subId the id of the subscription.
5960 * @return allowedNetworkTypes the allowed network types.
5961 */
5962 @Override
5963 public long getAllowedNetworkTypes(int subId) {
5964 TelephonyPermissions
5965 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5966 mApp, subId, "getAllowedNetworkTypes");
5967
5968 final long identity = Binder.clearCallingIdentity();
5969 try {
5970 return SubscriptionManager.getLongSubscriptionProperty(
5971 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5972 } finally {
5973 Binder.restoreCallingIdentity(identity);
5974 }
5975 }
5976
5977 /**
5978 * Set the allowed network types.
5979 *
5980 * @param subId the id of the subscription.
5981 * @param allowedNetworkTypes the allowed network types.
5982 * @return true on success; false on any failure.
5983 */
5984 @Override
5985 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5987 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005988
calvinpan089c2a62020-03-12 14:17:55 +08005989 SubscriptionManager.setSubscriptionProperty(subId,
5990 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5991 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005992
calvinpan089c2a62020-03-12 14:17:55 +08005993 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5994 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5995 RILConstants.PREFERRED_NETWORK_MODE);
5996 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005997 }
5998
5999 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006000 * Get the allowed network types for certain reason.
6001 *
6002 * @param subId the id of the subscription.
6003 * @param reason the reason the allowed network type change is taking place
6004 * @return the allowed network types.
6005 */
6006 @Override
6007 public long getAllowedNetworkTypesForReason(int subId,
6008 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6009 TelephonyPermissions
6010 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6011 mApp, subId, "getAllowedNetworkTypesForReason");
6012 final long identity = Binder.clearCallingIdentity();
6013 try {
6014 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
6018 }
6019
6020 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006021 * Enable/Disable E-UTRA-NR Dual Connectivity
6022 * @param subId subscription id of the sim card
6023 * @param nrDualConnectivityState expected NR dual connectivity state
6024 * This can be passed following states
6025 * <ol>
6026 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6027 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6028 * <li>Disable NR dual connectivity and force secondary cell to be released
6029 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6030 * </ol>
6031 * @return operation result.
6032 */
6033 @Override
6034 public int setNrDualConnectivityState(int subId,
6035 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6037 mApp, subId, "enableNRDualConnectivity");
6038 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6039 final long identity = Binder.clearCallingIdentity();
6040 try {
6041 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6042 nrDualConnectivityState, subId,
6043 workSource);
6044 if (DBG) log("enableNRDualConnectivity result: " + result);
6045 return result;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
6048 }
6049 }
6050
6051 /**
6052 * Is E-UTRA-NR Dual Connectivity enabled
6053 * @return true if dual connectivity is enabled else false
6054 */
6055 @Override
6056 public boolean isNrDualConnectivityEnabled(int subId) {
6057 TelephonyPermissions
6058 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6059 mApp, subId, "isNRDualConnectivityEnabled");
6060 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6064 null, subId, workSource);
6065 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6066 return isEnabled;
6067 } finally {
6068 Binder.restoreCallingIdentity(identity);
6069 }
6070 }
6071
6072 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006073 * get carrier bandwidth per primary and secondary carrier
6074 * @param subId subscription id of the sim card
6075 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6076 */
6077 @Override
6078 public CarrierBandwidth getCarrierBandwidth(int subId) {
6079 TelephonyPermissions
6080 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6081 mApp, subId, "isNRDualConnectivityEnabled");
6082 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6083 final long identity = Binder.clearCallingIdentity();
6084 try {
6085 CarrierBandwidth carrierBandwidth =
6086 getPhoneFromSubId(subId).getCarrierBandwidth();
6087 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6088 return carrierBandwidth;
6089 } finally {
6090 Binder.restoreCallingIdentity(identity);
6091 }
6092 }
6093
6094 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006095 * Get the effective allowed network types on the device.
6096 * This API will return an intersection of allowed network types for all reasons,
6097 * including the configuration done through setAllowedNetworkTypes
6098 *
6099 * @param subId the id of the subscription.
6100 * @return the allowed network types
6101 */
6102 @Override
6103 public long getEffectiveAllowedNetworkTypes(int subId) {
6104 TelephonyPermissions
6105 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6106 mApp, subId, "getEffectiveAllowedNetworkTypes");
6107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6110 } finally {
6111 Binder.restoreCallingIdentity(identity);
6112 }
6113 }
6114
6115 /**
6116 * Set the allowed network types of the device and
6117 * provide the reason triggering the allowed network change.
6118 *
6119 * @param subId the id of the subscription.
6120 * @param reason the reason the allowed network type change is taking place
6121 * @param allowedNetworkTypes the allowed network types.
6122 * @return true on success; false on any failure.
6123 */
6124 @Override
6125 public boolean setAllowedNetworkTypesForReason(int subId,
6126 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6128 mApp, subId, "setAllowedNetworkTypesForReason");
6129 final long identity = Binder.clearCallingIdentity();
6130 try {
6131 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6132 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6133 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6134 RILConstants.PREFERRED_NETWORK_MODE);
6135 return setPreferredNetworkType(subId, preferredNetworkMode);
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
6138 }
6139 }
6140
6141 /**
Miaoa84611c2019-03-15 09:21:10 +08006142 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006143 *
Miaoa84611c2019-03-15 09:21:10 +08006144 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006145 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006146 * @hide
6147 */
6148 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006149 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006150 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006151 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006152 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006153 try {
Miaoa84611c2019-03-15 09:21:10 +08006154 if (phone != null) {
6155 return phone.hasMatchedTetherApnSetting();
6156 } else {
6157 return false;
6158 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006159 } finally {
6160 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006161 }
Junda Liu475951f2014-11-07 16:45:03 -08006162 }
6163
6164 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006165 * Enable or disable always reporting signal strength changes from radio.
6166 *
6167 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6168 */
6169 @Override
6170 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6171 enforceModifyPermission();
6172 enforceSystemCaller();
6173
6174 final long identity = Binder.clearCallingIdentity();
6175 final Phone phone = getPhone(subId);
6176 try {
6177 if (phone != null) {
6178 if (DBG) {
6179 log("setAlwaysReportSignalStrength: subId=" + subId
6180 + " isEnable=" + isEnable);
6181 }
6182 phone.setAlwaysReportSignalStrength(isEnable);
6183 } else {
6184 loge("setAlwaysReportSignalStrength: no phone found for subId="
6185 + subId);
6186 }
6187 } finally {
6188 Binder.restoreCallingIdentity(identity);
6189 }
6190 }
6191
6192 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006193 * Get the user enabled state of Mobile Data.
6194 *
6195 * TODO: remove and use isUserDataEnabled.
6196 * This can't be removed now because some vendor codes
6197 * calls through ITelephony directly while they should
6198 * use TelephonyManager.
6199 *
6200 * @return true on enabled
6201 */
6202 @Override
6203 public boolean getDataEnabled(int subId) {
6204 return isUserDataEnabled(subId);
6205 }
6206
6207 /**
6208 * Get whether mobile data is enabled per user setting.
6209 *
6210 * There are other factors deciding whether mobile data is actually enabled, but they are
6211 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006212 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006213 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006214 *
6215 * @return {@code true} if data is enabled else {@code false}
6216 */
6217 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006218 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006219 try {
6220 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6221 null);
6222 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6224 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006225 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006226
6227 final long identity = Binder.clearCallingIdentity();
6228 try {
6229 int phoneId = mSubscriptionController.getPhoneId(subId);
6230 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6231 Phone phone = PhoneFactory.getPhone(phoneId);
6232 if (phone != null) {
6233 boolean retVal = phone.isUserDataEnabled();
6234 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6235 return retVal;
6236 } else {
6237 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6238 return false;
6239 }
6240 } finally {
6241 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006242 }
6243 }
6244
6245 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006246 * Checks if the device is capable of mobile data by considering whether whether the
6247 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6248 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006249 *
Shuo Qian985d1232020-01-08 14:30:06 -08006250 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006251 */
6252 @Override
6253 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006254 try {
6255 try {
6256 mApp.enforceCallingOrSelfPermission(
6257 android.Manifest.permission.ACCESS_NETWORK_STATE,
6258 null);
6259 } catch (Exception e) {
6260 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6261 "isDataEnabled");
6262 }
6263 } catch (Exception e) {
6264 enforceReadPrivilegedPermission("isDataEnabled");
6265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 int phoneId = mSubscriptionController.getPhoneId(subId);
6270 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6271 Phone phone = PhoneFactory.getPhone(phoneId);
6272 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006273 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6275 return retVal;
6276 } else {
6277 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6278 return false;
6279 }
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006282 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006283 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006284
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006285 /**
6286 * Check if data is enabled for a specific reason
6287 * @param subId Subscription index
6288 * @param reason the reason the data enable change is taking place
6289 * @return {@code true} if the overall data is enabled; {@code false} if not.
6290 */
6291 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006292 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006293 @TelephonyManager.DataEnabledReason int reason) {
6294 try {
6295 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6296 null);
6297 } catch (Exception e) {
6298 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006299 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006300 }
6301
6302
6303 final long identity = Binder.clearCallingIdentity();
6304 try {
6305 int phoneId = mSubscriptionController.getPhoneId(subId);
6306 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006307 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006308 + " reason=" + reason);
6309 }
6310 Phone phone = PhoneFactory.getPhone(phoneId);
6311 if (phone != null) {
6312 boolean retVal;
6313 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6314 retVal = phone.isUserDataEnabled();
6315 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006316 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006317 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006318 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006319 return retVal;
6320 } else {
6321 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006322 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006323 + subId + " retVal=false");
6324 }
6325 return false;
6326 }
6327 } finally {
6328 Binder.restoreCallingIdentity(identity);
6329 }
6330 }
6331
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006332 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006333 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006334 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6335 // Skip the check if it's one of these special uids
6336 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6337 }
6338
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006339 //load access rules from carrier configs, and check those as well: b/139133814
6340 SubscriptionController subController = SubscriptionController.getInstance();
6341 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6342 || subController == null) return privilegeFromSim;
6343
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006344 PackageManager pkgMgr = phone.getContext().getPackageManager();
6345 String[] packages = pkgMgr.getPackagesForUid(uid);
6346
6347 final long identity = Binder.clearCallingIdentity();
6348 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006349 int subId = phone.getSubId();
6350 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6351 // A test override is in place for the privileges for this subId, so don't try to
6352 // read the subscription privileges.
6353 return privilegeFromSim;
6354 }
6355 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006356 SubscriptionManager subManager = (SubscriptionManager)
6357 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6358 for (String pkg : packages) {
6359 if (subManager.canManageSubscription(subInfo, pkg)) {
6360 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6361 }
6362 }
6363 return privilegeFromSim;
6364 } finally {
6365 Binder.restoreCallingIdentity(identity);
6366 }
6367 }
6368
6369 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6370 String pkgName) {
6371 //load access rules from carrier configs, and check those as well: b/139133814
6372 SubscriptionController subController = SubscriptionController.getInstance();
6373 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6374 || subController == null) return privilegeFromSim;
6375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006378 int subId = phone.getSubId();
6379 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6380 // A test override is in place for the privileges for this subId, so don't try to
6381 // read the subscription privileges.
6382 return privilegeFromSim;
6383 }
6384 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006385 SubscriptionManager subManager = (SubscriptionManager)
6386 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6387 return subManager.canManageSubscription(subInfo, pkgName)
6388 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6389 } finally {
6390 Binder.restoreCallingIdentity(identity);
6391 }
6392 }
6393
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006394 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006395 public int getCarrierPrivilegeStatus(int subId) {
6396 final Phone phone = getPhone(subId);
6397 if (phone == null) {
6398 loge("getCarrierPrivilegeStatus: Invalid subId");
6399 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6400 }
6401 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006402 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006403 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006404 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6405 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006406
6407 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6408 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006409 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006410 }
Junda Liu29340342014-07-10 15:23:27 -07006411
6412 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006413 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006414 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006415 final Phone phone = getPhone(subId);
6416 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006417 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006418 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6419 }
6420 UiccProfile profile =
6421 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6422 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006423 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006424 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6425 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006426 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006427 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006428 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006429 }
6430
6431 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006432 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6433 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006435 }
6436
6437 int phoneId = SubscriptionManager.getPhoneId(subId);
6438 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006439 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006440 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006441 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6442 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006443 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6444 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6445 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006446 }
6447
6448 @Override
6449 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006450 if (TextUtils.isEmpty(pkgName))
6451 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006452 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6453 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6454 UiccCard card = UiccController.getInstance().getUiccCard(i);
6455 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006456 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006457 continue;
6458 }
6459
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006460 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6461 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6462 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006463 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6464 break;
6465 }
6466 }
6467
6468 return result;
Junda Liu29340342014-07-10 15:23:27 -07006469 }
Derek Tan89e89d42014-07-08 17:00:10 -07006470
6471 @Override
Junda Liue64de782015-04-16 17:19:16 -07006472 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6473 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6474 loge("phoneId " + phoneId + " is not valid.");
6475 return null;
6476 }
6477 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006478 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006479 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006480 return null ;
6481 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006482 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006483 }
6484
Amith Yamasani6e118872016-02-19 12:53:51 -08006485 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006486 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006487 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006488 List<String> privilegedPackages = new ArrayList<>();
6489 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006490 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6491 // has UICC in that slot.
6492 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006493 if (card.hasCarrierPrivilegeRules()) {
6494 if (packages == null) {
6495 // Only check packages in user 0 for now
6496 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006497 PackageManager.MATCH_DISABLED_COMPONENTS
6498 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006499 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006500 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006501 }
6502 for (int p = packages.size() - 1; p >= 0; p--) {
6503 PackageInfo pkgInfo = packages.get(p);
6504 if (pkgInfo != null && pkgInfo.packageName != null
6505 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006506 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006507 privilegedPackages.add(pkgInfo.packageName);
6508 }
6509 }
6510 }
6511 }
6512 return privilegedPackages;
6513 }
6514
chen xuf7e9fe82019-05-09 19:31:02 -07006515 @Override
6516 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006517 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6518
6519 final long identity = Binder.clearCallingIdentity();
6520
chen xuf7e9fe82019-05-09 19:31:02 -07006521 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006522 try {
6523 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6524 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6525 }
6526 } finally {
6527 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006528 }
6529 return privilegedPackages;
6530 }
6531
Wink Savilleb564aae2014-10-23 10:18:09 -07006532 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006533 final Phone phone = getPhone(subId);
6534 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006535 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006536 return null;
6537 }
6538 String iccId = card.getIccId();
6539 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006540 return null;
6541 }
6542 return iccId;
6543 }
6544
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006545 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006546 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6547 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006548 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006549 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006550
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006551 final long identity = Binder.clearCallingIdentity();
6552 try {
6553 final String iccId = getIccId(subId);
6554 final Phone phone = getPhone(subId);
6555 if (phone == null) {
6556 return false;
6557 }
6558 final String subscriberId = phone.getSubscriberId();
6559
6560 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006561 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006562 + subscriberId + " to " + number);
6563 }
6564
6565 if (TextUtils.isEmpty(iccId)) {
6566 return false;
6567 }
6568
6569 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6570
6571 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6572 if (alphaTag == null) {
6573 editor.remove(alphaTagPrefKey);
6574 } else {
6575 editor.putString(alphaTagPrefKey, alphaTag);
6576 }
6577
6578 // Record both the line number and IMSI for this ICCID, since we need to
6579 // track all merged IMSIs based on line number
6580 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6581 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6582 if (number == null) {
6583 editor.remove(numberPrefKey);
6584 editor.remove(subscriberPrefKey);
6585 } else {
6586 editor.putString(numberPrefKey, number);
6587 editor.putString(subscriberPrefKey, subscriberId);
6588 }
6589
6590 editor.commit();
6591 return true;
6592 } finally {
6593 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006594 }
Derek Tan7226c842014-07-02 17:42:23 -07006595 }
6596
6597 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006598 public String getLine1NumberForDisplay(int subId, String callingPackage,
6599 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006600 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006601 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006602 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006603 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006604 return null;
6605 }
Derek Tan97ebb422014-09-05 16:55:38 -07006606
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 String iccId = getIccId(subId);
6610 if (iccId != null) {
6611 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6612 if (DBG_MERGE) {
6613 log("getLine1NumberForDisplay returning "
6614 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6615 }
6616 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006617 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006618 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6619 return null;
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006622 }
Derek Tan7226c842014-07-02 17:42:23 -07006623 }
6624
6625 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006626 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6627 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006628 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006630 return null;
6631 }
Derek Tan97ebb422014-09-05 16:55:38 -07006632
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 String iccId = getIccId(subId);
6636 if (iccId != null) {
6637 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6638 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6639 }
6640 return null;
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006643 }
Derek Tan7226c842014-07-02 17:42:23 -07006644 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006645
6646 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006647 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6648 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006649 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6650 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006651 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006652 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006653 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006654 return null;
6655 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006656
Jordan Liub49b04b2019-05-06 14:45:15 -07006657 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6658 // the process, where TelephonyManager was instantiated.
6659 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006660 final long identity = Binder.clearCallingIdentity();
6661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006662 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006663 final TelephonyManager tele = TelephonyManager.from(context);
6664 final SubscriptionManager sub = SubscriptionManager.from(context);
6665
6666 // Figure out what subscribers are currently active
6667 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668
Jordan Liub49b04b2019-05-06 14:45:15 -07006669 // Only consider subs which match the current subId
6670 // This logic can be simplified. See b/131189269 for progress.
6671 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006672 activeSubscriberIds.add(tele.getSubscriberId(subId));
6673 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674
6675 // First pass, find a number override for an active subscriber
6676 String mergeNumber = null;
6677 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6678 for (String key : prefs.keySet()) {
6679 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6680 final String subscriberId = (String) prefs.get(key);
6681 if (activeSubscriberIds.contains(subscriberId)) {
6682 final String iccId = key.substring(
6683 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6684 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6685 mergeNumber = (String) prefs.get(numberKey);
6686 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006687 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 + " for active subscriber " + subscriberId);
6689 }
6690 if (!TextUtils.isEmpty(mergeNumber)) {
6691 break;
6692 }
6693 }
6694 }
6695 }
6696
6697 // Shortcut when no active merged subscribers
6698 if (TextUtils.isEmpty(mergeNumber)) {
6699 return null;
6700 }
6701
6702 // Second pass, find all subscribers under that line override
6703 final ArraySet<String> result = new ArraySet<>();
6704 for (String key : prefs.keySet()) {
6705 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6706 final String number = (String) prefs.get(key);
6707 if (mergeNumber.equals(number)) {
6708 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6709 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6710 final String subscriberId = (String) prefs.get(subscriberKey);
6711 if (!TextUtils.isEmpty(subscriberId)) {
6712 result.add(subscriberId);
6713 }
6714 }
6715 }
6716 }
6717
6718 final String[] resultArray = result.toArray(new String[result.size()]);
6719 Arrays.sort(resultArray);
6720 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006721 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6723 }
6724 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006725 } finally {
6726 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006727 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006728 }
6729
6730 @Override
zoey chen38003472019-12-13 17:16:31 +08006731 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6732 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006733
6734 final long identity = Binder.clearCallingIdentity();
6735 try {
6736 final TelephonyManager telephonyManager = mApp.getSystemService(
6737 TelephonyManager.class);
6738 String subscriberId = telephonyManager.getSubscriberId(subId);
6739 if (subscriberId == null) {
6740 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006741 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006742 + subId);
6743 }
6744 return null;
6745 }
6746
6747 final SubscriptionInfo info = SubscriptionController.getInstance()
6748 .getSubscriptionInfo(subId);
6749 final ParcelUuid groupUuid = info.getGroupUuid();
6750 // If it doesn't belong to any group, return just subscriberId of itself.
6751 if (groupUuid == null) {
6752 return new String[]{subscriberId};
6753 }
6754
6755 // Get all subscriberIds from the group.
6756 final List<String> mergedSubscriberIds = new ArrayList<>();
6757 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006758 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006759 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006760 for (SubscriptionInfo subInfo : groupInfos) {
6761 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6762 if (subscriberId != null) {
6763 mergedSubscriberIds.add(subscriberId);
6764 }
6765 }
6766
6767 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6768 } finally {
6769 Binder.restoreCallingIdentity(identity);
6770
6771 }
6772 }
6773
6774 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006775 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006776 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006777 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006778
6779 final long identity = Binder.clearCallingIdentity();
6780 try {
6781 final Phone phone = getPhone(subId);
6782 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6783 } finally {
6784 Binder.restoreCallingIdentity(identity);
6785 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006786 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006787
6788 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006789 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006790 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6791 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006792 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6793 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794
6795 final long identity = Binder.clearCallingIdentity();
6796 try {
6797 final Phone phone = getPhone(subId);
6798 if (phone == null) {
6799 return false;
6800 }
6801 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6802 cdmaNonRoamingList);
6803 } finally {
6804 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006805 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006806 }
6807
6808 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006809 @Deprecated
6810 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6811 enforceModifyPermission();
6812
6813 int returnValue = 0;
6814 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006815 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006816 if(result.exception == null) {
6817 if (result.result != null) {
6818 byte[] responseData = (byte[])(result.result);
6819 if(responseData.length > oemResp.length) {
6820 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6821 responseData.length + "bytes. Buffer Size is " +
6822 oemResp.length + "bytes.");
6823 }
6824 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6825 returnValue = responseData.length;
6826 }
6827 } else {
6828 CommandException ex = (CommandException) result.exception;
6829 returnValue = ex.getCommandError().ordinal();
6830 if(returnValue > 0) returnValue *= -1;
6831 }
6832 } catch (RuntimeException e) {
6833 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6834 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6835 if(returnValue > 0) returnValue *= -1;
6836 }
6837
6838 return returnValue;
6839 }
6840
6841 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006842 public void setRadioCapability(RadioAccessFamily[] rafs) {
6843 try {
6844 ProxyController.getInstance().setRadioCapability(rafs);
6845 } catch (RuntimeException e) {
6846 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6847 }
6848 }
6849
6850 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006851 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006852 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006853 try {
6854 TelephonyPermissions
6855 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6856 mApp, phone.getSubId(), "getRadioAccessFamily");
6857 } catch (SecurityException e) {
6858 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6859 throw e;
6860 }
chen xub97461a2018-10-26 14:17:57 -07006861 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006862 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006863 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006864 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006865 final long identity = Binder.clearCallingIdentity();
6866 try {
chen xub97461a2018-10-26 14:17:57 -07006867 TelephonyPermissions
6868 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6869 mApp, phone.getSubId(), "getRadioAccessFamily");
6870 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
chen xub97461a2018-10-26 14:17:57 -07006874 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006875 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006876
6877 @Override
6878 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006879 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006880 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881
6882 final long identity = Binder.clearCallingIdentity();
6883 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006884 ImsManager.getInstance(defaultPhone.getContext(),
6885 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006889 }
6890
6891 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006892 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006893 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006894 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6895 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006896 return false;
6897 }
Svet Ganovb320e182015-04-16 12:30:10 -07006898
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006899 final long identity = Binder.clearCallingIdentity();
6900 try {
6901 // Check the user preference and the system-level IMS setting. Even if the user has
6902 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6903 // In the long run, we may instead need to check if there exists a connection service
6904 // which can support video calling.
6905 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006906 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006907 return imsManager.isVtEnabledByPlatform()
6908 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6909 && imsManager.isVtEnabledByUser();
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
6912 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006913 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006914
Andrew Leea1239f22015-03-02 17:44:07 -08006915 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006916 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6917 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006918 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006919 mApp, subId, callingPackage, callingFeatureId,
6920 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 return false;
6922 }
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 CarrierConfigManager configManager =
6927 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006928 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
Andrew Leea1239f22015-03-02 17:44:07 -08006933 }
6934
6935 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006936 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006938 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 return false;
6940 }
6941
6942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 CarrierConfigManager configManager =
6945 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006946 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6948 } finally {
6949 Binder.restoreCallingIdentity(identity);
6950 }
Andrew Leea1239f22015-03-02 17:44:07 -08006951 }
6952
Andrew Lee9431b832015-03-09 18:46:45 -07006953 @Override
6954 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006955 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006956 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006957 }
6958
6959 @Override
6960 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006961 final long identity = Binder.clearCallingIdentity();
6962 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006963 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 } finally {
6965 Binder.restoreCallingIdentity(identity);
6966 }
Andrew Lee9431b832015-03-09 18:46:45 -07006967 }
6968
Hall Liuf6668912018-10-31 17:05:23 -07006969 /**
6970 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6971 * support for the feature and device firmware support.
6972 *
6973 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6974 */
6975 @Override
6976 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006978 final Phone phone = getPhone(subscriptionId);
6979 if (phone == null) {
6980 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6981 return false;
6982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006984 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006985 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6986 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006987 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006988 return isCarrierSupported && isDeviceSupported;
6989 } finally {
6990 Binder.restoreCallingIdentity(identity);
6991 }
Hall Liu98187582018-01-22 19:15:32 -08006992 }
6993
Hall Liuf6668912018-10-31 17:05:23 -07006994 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006995 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6996 * RTT setting, will return true if the device and carrier both support RTT.
6997 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006998 */
6999 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 final long identity = Binder.clearCallingIdentity();
7001 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007002 boolean isRttSupported = isRttSupported(subscriptionId);
7003 boolean isUserRttSettingOn = Settings.Secure.getInt(
7004 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7005 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7006 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7007 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 } finally {
7009 Binder.restoreCallingIdentity(identity);
7010 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007011 }
7012
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007013 @Deprecated
7014 @Override
7015 public String getDeviceId(String callingPackage) {
7016 return getDeviceIdWithFeature(callingPackage, null);
7017 }
7018
Sanket Padawe7310cc72015-01-14 09:53:20 -08007019 /**
7020 * Returns the unique device ID of phone, for example, the IMEI for
7021 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7022 *
7023 * <p>Requires Permission:
7024 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7025 */
7026 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007027 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007028 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007029 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007030 return null;
7031 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007032 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007033 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007034 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007035 return null;
7036 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037
7038 final long identity = Binder.clearCallingIdentity();
7039 try {
7040 return phone.getDeviceId();
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
7043 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007044 }
7045
Ping Sunc67b7c22016-03-02 19:16:45 +08007046 /**
7047 * {@hide}
7048 * Returns the IMS Registration Status on a particular subid
7049 *
7050 * @param subId
7051 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007052 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007053 Phone phone = getPhone(subId);
7054 if (phone != null) {
7055 return phone.isImsRegistered();
7056 } else {
7057 return false;
7058 }
7059 }
7060
Santos Cordon7a1885b2015-02-03 11:15:19 -08007061 @Override
7062 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
7065 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7066 } finally {
7067 Binder.restoreCallingIdentity(identity);
7068 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007069 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007070
Tyler Gunnf70ed162019-04-03 15:28:53 -07007071 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007072 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007073 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007075 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007076 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7077 }
7078 final long identity = Binder.clearCallingIdentity();
7079 try {
7080 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
7084 }
7085
7086 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007087 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007088 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7089 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007090 final long identity = Binder.clearCallingIdentity();
7091 try {
7092 Phone phone = getPhone(subscriptionId);
7093 if (phone == null) {
7094 return null;
7095 }
7096 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
7099 }
7100 }
7101
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007102 /**
7103 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007104 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007105 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 final long identity = Binder.clearCallingIdentity();
7107 try {
7108 Phone phone = getPhone(subId);
7109 if (phone != null) {
7110 return phone.isWifiCallingEnabled();
7111 } else {
7112 return false;
7113 }
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007116 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007117 }
7118
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007119 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007120 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007121 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007122 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 Phone phone = getPhone(subId);
7126 if (phone != null) {
7127 return phone.isVideoEnabled();
7128 } else {
7129 return false;
7130 }
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007133 }
7134 }
7135
7136 /**
7137 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7138 * defined in {@link ImsRegistrationImplBase}.
7139 */
7140 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 Phone phone = getPhone(subId);
7144 if (phone != null) {
7145 return phone.getImsRegistrationTech();
7146 } else {
7147 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7148 }
7149 } finally {
7150 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007151 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007152 }
7153
Stuart Scott8eef64f2015-04-08 15:13:54 -07007154 @Override
7155 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007156 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007157 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7158 return;
7159 }
7160
Svet Ganovcc087f82015-05-12 20:35:54 -07007161 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007162
Svet Ganovcc087f82015-05-12 20:35:54 -07007163 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007164 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7165 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007166 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007167 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007168 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007169 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007170 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7171 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007172 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007173 // There has been issues when Sms raw table somehow stores orphan
7174 // fragments. They lead to garbled message when new fragments come
7175 // in and combined with those stale ones. In case this happens again,
7176 // user can reset all network settings which will clean up this table.
7177 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007178 // Clean up IMS settings as well here.
7179 int slotId = getSlotIndex(subId);
7180 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7181 ImsManager.getInstance(mApp, slotId).factoryReset();
7182 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007183
7184 // Erase modem config if erase modem on network setting is enabled.
7185 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7186 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7187 if (configValue != null && Boolean.parseBoolean(configValue)) {
7188 sendEraseModemConfig(getDefaultPhone());
7189 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007190 } finally {
7191 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007192 }
7193 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007194
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007195 private void cleanUpSmsRawTable(Context context) {
7196 ContentResolver resolver = context.getContentResolver();
7197 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7198 resolver.delete(uri, null, null);
7199 }
7200
Narayan Kamath1c496c22015-04-16 14:40:19 +01007201 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007202 public String getSimLocaleForSubscriber(int subId) {
7203 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7204 final Phone phone = getPhone(subId);
7205 if (phone == null) {
7206 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007207 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007208 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007209 final long identity = Binder.clearCallingIdentity();
7210 try {
chen xu5d3637b2019-01-21 23:31:38 -08007211 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007212 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007213 if (info == null) {
7214 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7215 return null;
7216 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 // Try and fetch the locale from the carrier properties or from the SIM language
7218 // preferences (EF-PL and EF-LI)...
7219 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007221 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7222 if (localeFromDefaultSim != null) {
7223 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7224 if (DBG) log("Using locale from subId: " + subId + " locale: "
7225 + localeFromDefaultSim);
7226 return localeFromDefaultSim.toLanguageTag();
7227 } else {
7228 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007229 }
7230 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232 // The SIM language preferences only store a language (e.g. fr = French), not an
7233 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7234 // the SIM and carrier preferences does not include a country we add the country
7235 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007236 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007237 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007238 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007239 return mccLocale.toLanguageTag();
7240 }
7241
7242 if (DBG) log("No locale found - returning null");
7243 return null;
7244 } finally {
7245 Binder.restoreCallingIdentity(identity);
7246 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007247 }
7248
7249 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007250 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007251 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007252 }
7253
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254 /**
7255 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7256 */
7257 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007258 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007259 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007260 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007261
Chenjie Yu1ba97252018-01-11 18:16:20 -08007262 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007263 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007264
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007265 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007266 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7267 * representing the state of the modem.
7268 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007269 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7270 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007271 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007272 */
7273 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007274 public void requestModemActivityInfo(ResultReceiver result) {
7275 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007276 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277
7278 final long identity = Binder.clearCallingIdentity();
7279 try {
sqian1a1be542020-03-05 11:37:28 -08007280 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007281 } finally {
7282 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007283 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007284 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007285
Siddharth Rayb8114062018-06-17 15:02:38 -07007286 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7287 // less than total activity duration.
7288 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7289 if (info == null) {
7290 return false;
7291 }
7292 int activityDurationMs =
7293 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7294 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007295 int[] txTimeMs = info.getTransmitTimeMillis();
7296 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7297 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007298 }
7299 return (info.isValid()
7300 && (info.getSleepTimeMillis() <= activityDurationMs)
7301 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007302 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007303 && (totalTxTimeMs <= activityDurationMs));
7304 }
7305
Jack Yu85bd38a2015-11-09 11:34:32 -08007306 /**
7307 * {@hide}
7308 * Returns the service state information on specified subscription.
7309 */
7310 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007311 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7312 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007313 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007314 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007315 return null;
7316 }
7317
Hall Liuf19c44f2018-11-27 14:38:17 -08007318 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7319 LocationAccessPolicy.checkLocationPermission(mApp,
7320 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7321 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007322 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007323 .setCallingPid(Binder.getCallingPid())
7324 .setCallingUid(Binder.getCallingUid())
7325 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007326 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007327 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7328 .build());
7329
7330 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7331 LocationAccessPolicy.checkLocationPermission(mApp,
7332 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7333 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007334 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007335 .setCallingPid(Binder.getCallingPid())
7336 .setCallingUid(Binder.getCallingUid())
7337 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007338 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007339 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7340 .build());
7341 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7342 boolean hasFinePermission =
7343 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7344 boolean hasCoarsePermission =
7345 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 final long identity = Binder.clearCallingIdentity();
7348 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007349 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7350 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7351 Rlog.d(LOG_TAG,
7352 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7353 return null;
7354 }
7355
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007356 final Phone phone = getPhone(subId);
7357 if (phone == null) {
7358 return null;
7359 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007360
Hall Liuf19c44f2018-11-27 14:38:17 -08007361 ServiceState ss = phone.getServiceState();
7362
7363 // Scrub out the location info in ServiceState depending on what level of access
7364 // the caller has.
7365 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007366 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7367 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007368 } finally {
7369 Binder.restoreCallingIdentity(identity);
7370 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007371 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007372
7373 /**
7374 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7375 *
7376 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7377 * voicemail ringtone.
7378 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7379 * PhoneAccount.
7380 */
7381 @Override
7382 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 final long identity = Binder.clearCallingIdentity();
7384 try {
7385 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7386 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007387 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007389
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007390 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7391 } finally {
7392 Binder.restoreCallingIdentity(identity);
7393 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007394 }
7395
7396 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007397 * Sets the per-account voicemail ringtone.
7398 *
7399 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7400 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7401 *
7402 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7403 * voicemail ringtone.
7404 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7405 * PhoneAccount.
7406 */
7407 @Override
7408 public void setVoicemailRingtoneUri(String callingPackage,
7409 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007410 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007411 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007412 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7413 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007414 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7415 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7416 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007417 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418
7419 final long identity = Binder.clearCallingIdentity();
7420 try {
7421 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7422 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007423 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 }
7425 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7426 } finally {
7427 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007428 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007429 }
7430
7431 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007432 * Returns whether vibration is set for voicemail notification in Phone settings.
7433 *
7434 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7435 * voicemail vibration setting.
7436 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7437 */
7438 @Override
7439 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007440 final long identity = Binder.clearCallingIdentity();
7441 try {
7442 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7443 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007444 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007446
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007447 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7448 } finally {
7449 Binder.restoreCallingIdentity(identity);
7450 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007451 }
7452
Youhan Wange64578a2016-05-02 15:32:42 -07007453 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007454 * Sets the per-account voicemail vibration.
7455 *
7456 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7457 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7458 *
7459 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7460 * voicemail vibration setting.
7461 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7462 * specific PhoneAccount.
7463 */
7464 @Override
7465 public void setVoicemailVibrationEnabled(String callingPackage,
7466 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007467 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007468 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007469 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7470 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007471 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7472 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7473 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007474 }
7475
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007476 final long identity = Binder.clearCallingIdentity();
7477 try {
7478 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7479 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007480 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 }
7482 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7483 } finally {
7484 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007485 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007486 }
7487
7488 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007489 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7490 *
7491 * @throws SecurityException if the caller does not have the required permission
7492 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007493 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007494 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007495 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007496 }
7497
7498 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007499 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7500 * permission.
7501 *
7502 * @throws SecurityException if the caller does not have the required permission
7503 */
7504 private void enforceSendSmsPermission() {
7505 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7506 }
7507
7508 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007509 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007510 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007511 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007512 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007513 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007514 final long identity = Binder.clearCallingIdentity();
7515 try {
7516 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 if (componentName == null) {
7519 throw new SecurityException(
7520 "Caller not current active visual voicemail package[null]");
7521 }
7522 String vvmPackage = componentName.getPackageName();
7523 if (!callingPackage.equals(vvmPackage)) {
7524 throw new SecurityException("Caller not current active visual voicemail package["
7525 + vvmPackage + "]");
7526 }
7527 } finally {
7528 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007529 }
7530 }
7531
7532 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007533 * Return the application ID for the app type.
7534 *
7535 * @param subId the subscription ID that this request applies to.
7536 * @param appType the uicc app type.
7537 * @return Application ID for specificied app type, or null if no uicc.
7538 */
7539 @Override
7540 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007541 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007542 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007543
7544 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007545 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007546 if (phone == null) {
7547 return null;
7548 }
7549 String aid = null;
7550 try {
7551 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7552 .getApplicationByType(appType).getAid();
7553 } catch (Exception e) {
7554 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7555 }
7556 return aid;
7557 } finally {
7558 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007559 }
Youhan Wange64578a2016-05-02 15:32:42 -07007560 }
7561
Youhan Wang4001d252016-05-11 10:29:41 -07007562 /**
7563 * Return the Electronic Serial Number.
7564 *
7565 * @param subId the subscription ID that this request applies to.
7566 * @return ESN or null if error.
7567 */
7568 @Override
7569 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007570 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007571 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007572
7573 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007574 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007575 if (phone == null) {
7576 return null;
7577 }
7578 String esn = null;
7579 try {
7580 esn = phone.getEsn();
7581 } catch (Exception e) {
7582 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7583 }
7584 return esn;
7585 } finally {
7586 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007587 }
Youhan Wang4001d252016-05-11 10:29:41 -07007588 }
7589
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007590 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007591 * Return the Preferred Roaming List Version.
7592 *
7593 * @param subId the subscription ID that this request applies to.
7594 * @return PRLVersion or null if error.
7595 */
7596 @Override
7597 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007598 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007599 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600
7601 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007602 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007603 if (phone == null) {
7604 return null;
7605 }
7606 String cdmaPrlVersion = null;
7607 try {
7608 cdmaPrlVersion = phone.getCdmaPrlVersion();
7609 } catch (Exception e) {
7610 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7611 }
7612 return cdmaPrlVersion;
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007615 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007616 }
7617
7618 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007619 * Get snapshot of Telephony histograms
7620 * @return List of Telephony histograms
7621 * @hide
7622 */
7623 @Override
7624 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7626 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627
7628 final long identity = Binder.clearCallingIdentity();
7629 try {
7630 return RIL.getTelephonyRILTimingHistograms();
7631 } finally {
7632 Binder.restoreCallingIdentity(identity);
7633 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007634 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007635
7636 /**
7637 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007638 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7639 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007640 * Require system privileges. In the future we may add this to carrier APIs.
7641 *
Michele Berionne482f8202018-11-27 18:57:59 -08007642 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007643 */
7644 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007645 @TelephonyManager.SetCarrierRestrictionResult
7646 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007647 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007648 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007649
Michele Berionne482f8202018-11-27 18:57:59 -08007650 if (carrierRestrictionRules == null) {
7651 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007652 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654 final long identity = Binder.clearCallingIdentity();
7655 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007656 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007657 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007658 } finally {
7659 Binder.restoreCallingIdentity(identity);
7660 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007661 }
7662
7663 /**
7664 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007665 * Get the allowed carrier list and the excluded carrier list, including the priority between
7666 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007667 * Require system privileges. In the future we may add this to carrier APIs.
7668 *
Michele Berionne482f8202018-11-27 18:57:59 -08007669 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007670 */
7671 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007672 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007673 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007674 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675
7676 final long identity = Binder.clearCallingIdentity();
7677 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007678 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7679 if (response instanceof CarrierRestrictionRules) {
7680 return (CarrierRestrictionRules) response;
7681 }
7682 // Response is an Exception of some kind,
7683 // which is signalled to the user as a NULL retval
7684 return null;
7685 } catch (Exception e) {
7686 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7687 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007688 } finally {
7689 Binder.restoreCallingIdentity(identity);
7690 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007691 }
7692
fionaxu59545b42016-05-25 15:53:37 -07007693 /**
fionaxu59545b42016-05-25 15:53:37 -07007694 * Action set from carrier signalling broadcast receivers to enable/disable radio
7695 * @param subId the subscription ID that this action applies to.
7696 * @param enabled control enable or disable radio.
7697 * {@hide}
7698 */
7699 @Override
7700 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7701 enforceModifyPermission();
7702 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007703
7704 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007705 if (phone == null) {
7706 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7707 return;
7708 }
7709 try {
7710 phone.carrierActionSetRadioEnabled(enabled);
7711 } catch (Exception e) {
7712 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713 } finally {
7714 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007715 }
7716 }
7717
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007718 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007719 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7720 * network status based on which carrier apps could apply actions accordingly,
7721 * enable/disable default url handler for example.
7722 *
7723 * @param subId the subscription ID that this action applies to.
7724 * @param report control start/stop reporting the default network status.
7725 * {@hide}
7726 */
7727 @Override
7728 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7729 enforceModifyPermission();
7730 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731
7732 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007733 if (phone == null) {
7734 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7735 return;
7736 }
7737 try {
7738 phone.carrierActionReportDefaultNetworkStatus(report);
7739 } catch (Exception e) {
7740 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007741 } finally {
7742 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007743 }
7744 }
7745
7746 /**
fionaxud9622282017-07-17 17:51:30 -07007747 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7748 * @param subId the subscription ID that this action applies to.
7749 * {@hide}
7750 */
7751 @Override
7752 public void carrierActionResetAll(int subId) {
7753 enforceModifyPermission();
7754 final Phone phone = getPhone(subId);
7755 if (phone == null) {
7756 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7757 return;
7758 }
7759 try {
7760 phone.carrierActionResetAll();
7761 } catch (Exception e) {
7762 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7763 }
7764 }
7765
7766 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007767 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7768 * bug report is being generated.
7769 */
7770 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007771 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007772 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7773 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007774 writer.println("Permission Denial: can't dump Phone from pid="
7775 + Binder.getCallingPid()
7776 + ", uid=" + Binder.getCallingUid()
7777 + "without permission "
7778 + android.Manifest.permission.DUMP);
7779 return;
7780 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007781 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007782 }
Jack Yueb89b242016-06-22 13:27:47 -07007783
Brad Ebingerdac2f002018-04-03 15:17:52 -07007784 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007785 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7786 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7787 @NonNull String[] args) {
7788 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7789 this, in.getFileDescriptor(), out.getFileDescriptor(),
7790 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007791 }
7792
Jack Yueb89b242016-06-22 13:27:47 -07007793 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007794 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007795 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007796 * @param reason the reason the data enable change is taking place
7797 * @param enabled True if enabling the data, otherwise disabling.
7798 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007799 */
7800 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007801 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007802 boolean enabled) {
7803 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7804 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7805 try {
7806 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007807 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007808 } catch (SecurityException se) {
7809 enforceModifyPermission();
7810 }
7811 } else {
7812 enforceModifyPermission();
7813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814
7815 final long identity = Binder.clearCallingIdentity();
7816 try {
7817 Phone phone = getPhone(subId);
7818 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007819 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7820 phone.carrierActionSetMeteredApnsEnabled(enabled);
7821 } else {
7822 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7823 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007824 }
7825 } finally {
7826 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007827 }
7828 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007829
7830 /**
7831 * Get Client request stats
7832 * @return List of Client Request Stats
7833 * @hide
7834 */
7835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007836 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7837 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007838 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007839 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007840 return null;
7841 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007842 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007843
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007844 final long identity = Binder.clearCallingIdentity();
7845 try {
7846 if (phone != null) {
7847 return phone.getClientRequestStats();
7848 }
7849
7850 return null;
7851 } finally {
7852 Binder.restoreCallingIdentity(identity);
7853 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007854 }
7855
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007856 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007857 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007858 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007859 }
Jack Yueb4124c2017-02-16 15:32:43 -08007860
7861 /**
Grace Chen70990072017-03-24 17:21:30 -07007862 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007863 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007864 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007865 * @param state State of SIM (power down, power up, pass through)
7866 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7867 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7868 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007869 *
7870 **/
7871 @Override
Grace Chen70990072017-03-24 17:21:30 -07007872 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007873 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007874 Phone phone = PhoneFactory.getPhone(slotIndex);
7875
vagdeviaf9a5b92018-08-15 16:01:53 -07007876 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007881 phone.setSimPowerState(state, null, workSource);
7882 }
7883 } finally {
7884 Binder.restoreCallingIdentity(identity);
7885 }
7886 }
7887
7888 /**
7889 * Set SIM card power state.
7890 *
7891 * @param slotIndex SIM slot id.
7892 * @param state State of SIM (power down, power up, pass through)
7893 * @param callback callback to trigger after success or failure
7894 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7895 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7896 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7897 *
7898 **/
7899 @Override
7900 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7901 IIntegerConsumer callback) {
7902 enforceModifyPermission();
7903 Phone phone = PhoneFactory.getPhone(slotIndex);
7904
7905 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7906
7907 final long identity = Binder.clearCallingIdentity();
7908 try {
7909 if (phone != null) {
7910 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7911 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007912 }
7913 } finally {
7914 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007915 }
7916 }
Shuo Qiandd210312017-04-12 22:11:33 +00007917
Tyler Gunn65d45c22017-06-05 11:22:26 -07007918 private boolean isUssdApiAllowed(int subId) {
7919 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007920 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007921 if (configManager == null) {
7922 return false;
7923 }
7924 PersistableBundle pb = configManager.getConfigForSubId(subId);
7925 if (pb == null) {
7926 return false;
7927 }
7928 return pb.getBoolean(
7929 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7930 }
7931
Shuo Qiandd210312017-04-12 22:11:33 +00007932 /**
7933 * Check if phone is in emergency callback mode
7934 * @return true if phone is in emergency callback mode
7935 * @param subId sub id
7936 */
goneil9c5f4872017-12-05 14:07:56 -08007937 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007938 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007939 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007940 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007941
7942 final long identity = Binder.clearCallingIdentity();
7943 try {
7944 if (phone != null) {
7945 return phone.isInEcm();
7946 } else {
7947 return false;
7948 }
7949 } finally {
7950 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007951 }
7952 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007953
7954 /**
7955 * Get the current signal strength information for the given subscription.
7956 * Because this information is not updated when the device is in a low power state
7957 * it should not be relied-upon to be current.
7958 * @param subId Subscription index
7959 * @return the most recent cached signal strength info from the modem
7960 */
7961 @Override
7962 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 Phone p = getPhone(subId);
7966 if (p == null) {
7967 return null;
7968 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007969
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007970 return p.getSignalStrength();
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007974 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007975
Pengquan Meng77b7f132018-08-22 14:49:57 -07007976 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007977 * Get the current modem radio state for the given slot.
7978 * @param slotIndex slot index.
7979 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007980 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007981 * @return the current radio power state from the modem
7982 */
7983 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007984 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007985 Phone phone = PhoneFactory.getPhone(slotIndex);
7986 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7988 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007989 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7990 }
7991
7992 final long identity = Binder.clearCallingIdentity();
7993 try {
7994 return phone.getRadioPowerState();
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
7997 }
7998 }
7999 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8000 }
8001
8002 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008003 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8004 *
8005 * <p>Requires one of the following permissions:
8006 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8007 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8008 * privileges.
8009 *
8010 * @param subId subscription id
8011 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8012 * {@code false}.
8013 */
8014 @Override
8015 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008016 try {
8017 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8018 null);
8019 } catch (Exception e) {
8020 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8021 mApp, subId, "isDataRoamingEnabled");
8022 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008023
Pengquan Menga1bb6272018-09-06 09:59:22 -07008024 boolean isEnabled = false;
8025 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008026 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008027 Phone phone = getPhone(subId);
8028 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008029 } finally {
8030 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008031 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008032 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008033 }
8034
8035
8036 /**
8037 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8038 *
8039 * <p> Requires permission:
8040 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8041 * privileges.
8042 *
8043 * @param subId subscription id
8044 * @param isEnabled {@code true} means enable, {@code false} means disable.
8045 */
8046 @Override
8047 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8049 mApp, subId, "setDataRoamingEnabled");
8050
Pengquan Menga1bb6272018-09-06 09:59:22 -07008051 final long identity = Binder.clearCallingIdentity();
8052 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008053 Phone phone = getPhone(subId);
8054 if (phone != null) {
8055 phone.setDataRoamingEnabled(isEnabled);
8056 }
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008059 }
8060 }
8061
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008062 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008063 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008064 TelephonyPermissions
8065 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008066 mApp, subId, "isManualNetworkSelectionAllowed");
8067
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008068 boolean isAllowed = true;
8069 final long identity = Binder.clearCallingIdentity();
8070 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008071 Phone phone = getPhone(subId);
8072 if (phone != null) {
8073 isAllowed = phone.isCspPlmnEnabled();
8074 }
8075 } finally {
8076 Binder.restoreCallingIdentity(identity);
8077 }
8078 return isAllowed;
8079 }
8080
8081 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008082 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008083 // Verify that tha callingPackage belongs to the calling UID
8084 mApp.getSystemService(AppOpsManager.class)
8085 .checkPackage(Binder.getCallingUid(), callingPackage);
8086
Jordan Liu1e142fc2019-04-22 15:10:43 -07008087 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008088 try {
8089 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008090 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008091 } catch (SecurityException e) {
8092 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8093 // has carrier privileges on an active UICC
8094 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8095 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008096 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008097 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008098 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008099
8100 final long identity = Binder.clearCallingIdentity();
8101 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008102 UiccController uiccController = UiccController.getInstance();
8103 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008104 if (hasReadPermission) {
8105 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008106 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008107
8108 // Remove private info if the caller doesn't have access
8109 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8110 for (UiccCardInfo cardInfo : cardInfos) {
8111 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8112 // is available
8113 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8114 if (card == null || card.getUiccProfile() == null) {
8115 // assume no access if the card or profile is unavailable
8116 filteredInfos.add(cardInfo.getUnprivileged());
8117 continue;
8118 }
8119 UiccProfile profile = card.getUiccProfile();
8120 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8121 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8122 filteredInfos.add(cardInfo);
8123 } else {
8124 filteredInfos.add(cardInfo.getUnprivileged());
8125 }
8126 }
8127 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
8131 }
8132
8133 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008134 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008135 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008137 final long identity = Binder.clearCallingIdentity();
8138 try {
8139 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8140 if (slots == null) {
8141 Rlog.i(LOG_TAG, "slots is null.");
8142 return null;
8143 }
8144
8145 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8146 for (int i = 0; i < slots.length; i++) {
8147 UiccSlot slot = slots[i];
8148 if (slot == null) {
8149 continue;
8150 }
8151
Jordan Liu7be7e652019-05-06 18:55:02 +00008152 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008153 UiccCard card = slot.getUiccCard();
8154 if (card != null) {
8155 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008156 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008157 cardId = slot.getEid();
8158 if (TextUtils.isEmpty(cardId)) {
8159 cardId = slot.getIccId();
8160 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008161 }
8162
Jordan Liu857451f2019-05-09 16:35:35 -07008163 if (cardId != null) {
8164 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8165 // if cardId is an EID, it's all digits so this is fine
8166 cardId = IccUtils.stripTrailingFs(cardId);
8167 }
8168
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008169 int cardState = 0;
8170 switch (slot.getCardState()) {
8171 case CARDSTATE_ABSENT:
8172 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8173 break;
8174 case CARDSTATE_PRESENT:
8175 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8176 break;
8177 case CARDSTATE_ERROR:
8178 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8179 break;
8180 case CARDSTATE_RESTRICTED:
8181 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8182 break;
8183 default:
8184 break;
8185
8186 }
8187
8188 infos[i] = new UiccSlotInfo(
8189 slot.isActive(),
8190 slot.isEuicc(),
8191 cardId,
8192 cardState,
8193 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008194 slot.isExtendedApduSupported(),
8195 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008196 }
8197 return infos;
8198 } finally {
8199 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008200 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008201 }
8202
8203 @Override
8204 public boolean switchSlots(int[] physicalSlots) {
8205 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008206
8207 final long identity = Binder.clearCallingIdentity();
8208 try {
8209 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008213 }
Jack Yu4c988042018-02-27 15:30:01 -08008214
8215 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008216 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008217 final long identity = Binder.clearCallingIdentity();
8218 try {
8219 return UiccController.getInstance().getCardIdForDefaultEuicc();
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 }
8224
Pengquan Meng85728fb2018-03-12 16:31:21 -07008225 /**
goneil47ffb6e2018-04-06 15:40:58 -07008226 * A test API to reload the UICC profile.
8227 *
8228 * <p>Requires that the calling app has permission
8229 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8230 * @hide
8231 */
8232 @Override
8233 public void refreshUiccProfile(int subId) {
8234 enforceModifyPermission();
8235
8236 final long identity = Binder.clearCallingIdentity();
8237 try {
8238 Phone phone = getPhone(subId);
8239 if (phone == null) {
8240 return;
8241 }
8242 UiccCard uiccCard = phone.getUiccCard();
8243 if (uiccCard == null) {
8244 return;
8245 }
8246 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8247 if (uiccProfile == null) {
8248 return;
8249 }
8250 uiccProfile.refresh();
8251 } finally {
8252 Binder.restoreCallingIdentity(identity);
8253 }
8254 }
8255
8256 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008257 * Returns false if the mobile data is disabled by default, otherwise return true.
8258 */
8259 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008260 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008261 }
8262
8263 /**
8264 * Returns true if the data roaming is enabled by default, i.e the system property
8265 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8266 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8267 */
8268 private boolean getDefaultDataRoamingEnabled(int subId) {
8269 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008270 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008271 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008272 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8273 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8274 return isDataRoamingEnabled;
8275 }
8276
8277 /**
8278 * Returns the default network type for the given {@code subId}, if the default network type is
8279 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8280 */
8281 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008282 List<Integer> list = TelephonyProperties.default_network();
8283 int phoneId = mSubscriptionController.getPhoneId(subId);
8284 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8285 return list.get(phoneId);
8286 }
8287 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008288 }
fionaxua13278b2018-03-21 00:08:13 -07008289
8290 @Override
8291 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008292 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008293 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008294
8295 final long identity = Binder.clearCallingIdentity();
8296 try {
8297 final Phone phone = getPhone(subId);
8298 if (phone == null) {
8299 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8300 return;
8301 }
chen xueaba88a2019-03-15 13:15:10 -07008302 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8303 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008304 if (carrierPrivilegeRules == null) {
8305 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8306 } else {
8307 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008309 } finally {
8310 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008311 }
fionaxua13278b2018-03-21 00:08:13 -07008312 }
8313
8314 @Override
8315 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008316 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008317
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 final Phone phone = getPhone(subId);
8321 if (phone == null) {
8322 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8323 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8324 }
8325 return phone.getCarrierIdListVersion();
8326 } finally {
8327 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008328 }
fionaxua13278b2018-03-21 00:08:13 -07008329 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008330
8331 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008332 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8333 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008334 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008335 mApp, subId, callingPackage, callingFeatureId,
8336 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008337 return -1;
8338 }
8339
8340 final long identity = Binder.clearCallingIdentity();
8341 try {
8342 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8343 } finally {
8344 Binder.restoreCallingIdentity(identity);
8345 }
8346 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008347
8348 @Override
8349 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008350 TelephonyPermissions
8351 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008352 mApp, subId, "getCdmaRoamingMode");
8353
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8357 } finally {
8358 Binder.restoreCallingIdentity(identity);
8359 }
8360 }
8361
8362 @Override
8363 public boolean setCdmaRoamingMode(int subId, int mode) {
8364 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8365 mApp, subId, "setCdmaRoamingMode");
8366
8367 final long identity = Binder.clearCallingIdentity();
8368 try {
8369 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8370 } finally {
8371 Binder.restoreCallingIdentity(identity);
8372 }
8373 }
8374
8375 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008376 public int getCdmaSubscriptionMode(int subId) {
8377 TelephonyPermissions
8378 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8379 mApp, subId, "getCdmaSubscriptionMode");
8380
8381 final long identity = Binder.clearCallingIdentity();
8382 try {
8383 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
8388
8389 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008390 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8391 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8392 mApp, subId, "setCdmaSubscriptionMode");
8393
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
8399 }
8400 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008401
sqianc5eccab2018-10-19 18:46:41 -07008402 @Override
sqian8c685422019-02-22 15:55:18 -08008403 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008404 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008406 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8407 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008408 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8409 }
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
sqian854d44b2018-12-12 16:48:18 -08008412 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8413 for (Phone phone: PhoneFactory.getPhones()) {
8414 if (phone.getEmergencyNumberTracker() != null
8415 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8416 emergencyNumberListInternal.put(
8417 phone.getSubId(),
8418 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8419 }
sqian11b7a0e2018-12-05 18:48:28 -08008420 }
sqian854d44b2018-12-12 16:48:18 -08008421 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008422 } finally {
8423 Binder.restoreCallingIdentity(identity);
8424 }
sqianc5eccab2018-10-19 18:46:41 -07008425 }
8426
8427 @Override
sqian8c685422019-02-22 15:55:18 -08008428 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008429 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008430 if (!exactMatch) {
8431 TelephonyPermissions
8432 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008433 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008434 }
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
sqian854d44b2018-12-12 16:48:18 -08008437 for (Phone phone: PhoneFactory.getPhones()) {
8438 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008439 && phone.getEmergencyNumberTracker()
8440 .isEmergencyNumber(number, exactMatch)) {
8441 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008442 }
sqian11b7a0e2018-12-05 18:48:28 -08008443 }
8444 return false;
8445 } finally {
8446 Binder.restoreCallingIdentity(identity);
8447 }
8448 }
8449
sqianf4ca7ed2019-01-15 18:32:07 -08008450 /**
8451 * Update emergency number list for test mode.
8452 */
8453 @Override
8454 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8455 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8456 "updateEmergencyNumberListTestMode");
8457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 for (Phone phone: PhoneFactory.getPhones()) {
8461 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8462 if (tracker != null) {
8463 tracker.executeEmergencyNumberTestModeCommand(action, num);
8464 }
8465 }
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
8471 /**
8472 * Get the full emergency number list for test mode.
8473 */
8474 @Override
8475 public List<String> getEmergencyNumberListTestMode() {
8476 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8477 "getEmergencyNumberListTestMode");
8478
8479 final long identity = Binder.clearCallingIdentity();
8480 try {
8481 Set<String> emergencyNumbers = new HashSet<>();
8482 for (Phone phone: PhoneFactory.getPhones()) {
8483 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8484 if (tracker != null) {
8485 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8486 emergencyNumbers.add(num.getNumber());
8487 }
8488 }
8489 }
8490 return new ArrayList<>(emergencyNumbers);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
chen xud6b45bd2018-10-30 22:27:10 -07008496 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008497 public int getEmergencyNumberDbVersion(int subId) {
8498 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8499
8500 final long identity = Binder.clearCallingIdentity();
8501 try {
8502 final Phone phone = getPhone(subId);
8503 if (phone == null) {
8504 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8505 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8506 }
8507 return phone.getEmergencyNumberDbVersion();
8508 } finally {
8509 Binder.restoreCallingIdentity(identity);
8510 }
8511 }
8512
8513 @Override
8514 public void notifyOtaEmergencyNumberDbInstalled() {
8515 enforceModifyPermission();
8516
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 for (Phone phone: PhoneFactory.getPhones()) {
8520 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8521 if (tracker != null) {
8522 tracker.updateOtaEmergencyNumberDatabase();
8523 }
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 }
8529
8530 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008531 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008532 enforceActiveEmergencySessionPermission();
8533
8534 final long identity = Binder.clearCallingIdentity();
8535 try {
8536 for (Phone phone: PhoneFactory.getPhones()) {
8537 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8538 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008539 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8540 }
8541 }
8542 } finally {
8543 Binder.restoreCallingIdentity(identity);
8544 }
8545 }
8546
8547 @Override
8548 public void resetOtaEmergencyNumberDbFilePath() {
8549 enforceActiveEmergencySessionPermission();
8550
8551 final long identity = Binder.clearCallingIdentity();
8552 try {
8553 for (Phone phone: PhoneFactory.getPhones()) {
8554 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8555 if (tracker != null) {
8556 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008557 }
8558 }
8559 } finally {
8560 Binder.restoreCallingIdentity(identity);
8561 }
8562 }
8563
8564 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008565 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8566 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8567 Phone phone = getPhone(subId);
8568 if (phone == null) {
8569 return null;
8570 }
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 UiccProfile profile = UiccController.getInstance()
8574 .getUiccProfileForPhone(phone.getPhoneId());
8575 if (profile != null) {
8576 return profile.getCertsFromCarrierPrivilegeAccessRules();
8577 }
8578 } finally {
8579 Binder.restoreCallingIdentity(identity);
8580 }
8581 return null;
8582 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008583
8584 /**
8585 * Enable or disable a modem stack.
8586 */
8587 @Override
8588 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8589 enforceModifyPermission();
8590
8591 final long identity = Binder.clearCallingIdentity();
8592 try {
8593 Phone phone = PhoneFactory.getPhone(slotIndex);
8594 if (phone == null) {
8595 return false;
8596 } else {
8597 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8598 }
8599 } finally {
8600 Binder.restoreCallingIdentity(identity);
8601 }
8602 }
Michelecea4cf22018-12-21 15:00:11 -08008603
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008604 /**
8605 * Whether a modem stack is enabled or not.
8606 */
8607 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008608 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8609 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008610 Phone phone = PhoneFactory.getPhone(slotIndex);
8611 if (phone == null) return false;
8612
8613 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008614 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8615 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008616 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8617 }
8618
8619 final long identity = Binder.clearCallingIdentity();
8620 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008621 try {
8622 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8623 } catch (NoSuchElementException ex) {
8624 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8625 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008626 } finally {
8627 Binder.restoreCallingIdentity(identity);
8628 }
8629 }
8630
Michelecea4cf22018-12-21 15:00:11 -08008631 @Override
Michele0ea7d782019-03-19 14:58:42 -07008632 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008633 enforceModifyPermission();
8634
8635 final long identity = Binder.clearCallingIdentity();
8636 try {
8637 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008638 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008639 .commit();
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
8643 }
8644
8645 @Override
Michele0ea7d782019-03-19 14:58:42 -07008646 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008647 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008648 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008649 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8650 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008651 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008652 }
Michelecea4cf22018-12-21 15:00:11 -08008653
8654 final long identity = Binder.clearCallingIdentity();
8655 try {
Michele0ea7d782019-03-19 14:58:42 -07008656 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008657 } finally {
8658 Binder.restoreCallingIdentity(identity);
8659 }
8660 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008661
Michele0ea7d782019-03-19 14:58:42 -07008662 @TelephonyManager.IsMultiSimSupportedResult
8663 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008664 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8665 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8666 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008667 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8668 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008669 }
8670 // Check if the hardware supports multisim functionality. If usage of multisim is not
8671 // supported by the modem, indicate that it is restricted.
8672 PhoneCapability staticCapability =
8673 mPhoneConfigurationManager.getStaticPhoneCapability();
8674 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008675 loge("isMultiSimSupportedInternal: no static configuration available");
8676 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008677 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008678 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008679 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8680 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008681 }
8682 // Check if support of multiple SIMs is restricted by carrier
8683 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008684 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008685 }
8686
Michele0ea7d782019-03-19 14:58:42 -07008687 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008688 }
8689
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008690 /**
8691 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008692 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8693 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8694 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008695 * @param numOfSims number of active sims we want to switch to
8696 */
8697 @Override
8698 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008699 if (numOfSims == 1) {
8700 enforceModifyPermission();
8701 } else {
8702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8703 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8704 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008705 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008706
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008707 try {
Michele30b57b22019-03-01 12:01:14 -08008708 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008709 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008710 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8711 return;
8712 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008713 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8714 } finally {
8715 Binder.restoreCallingIdentity(identity);
8716 }
8717 }
8718
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008719 @Override
8720 public boolean isApplicationOnUicc(int subId, int appType) {
8721 enforceReadPrivilegedPermission("isApplicationOnUicc");
8722 Phone phone = getPhone(subId);
8723 if (phone == null) {
8724 return false;
8725 }
8726 final long identity = Binder.clearCallingIdentity();
8727 try {
8728 UiccCard uiccCard = phone.getUiccCard();
8729 if (uiccCard == null) {
8730 return false;
8731 }
8732 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8733 if (uiccProfile == null) {
8734 return false;
8735 }
8736 if (TelephonyManager.APPTYPE_SIM <= appType
8737 && appType <= TelephonyManager.APPTYPE_ISIM) {
8738 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8739 }
8740 return false;
8741 } finally {
8742 Binder.restoreCallingIdentity(identity);
8743 }
8744 }
8745
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008746 /**
chen xub4baa772019-04-03 10:23:41 -07008747 * Get whether making changes to modem configurations will trigger reboot.
8748 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008749 */
8750 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008751 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8752 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008754 mApp, subId, callingPackage, callingFeatureId,
8755 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008756 return false;
8757 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8761 } finally {
8762 Binder.restoreCallingIdentity(identity);
8763 }
8764 }
8765
Nathan Harold29f5f052019-02-15 13:41:57 -08008766 private void updateModemStateMetrics() {
8767 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8768 // TODO: check the state for each modem if the api is ready.
8769 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8770 }
8771
Pengquan Meng3889a572019-01-23 11:16:29 -08008772 @Override
8773 public int[] getSlotsMapping() {
8774 enforceReadPrivilegedPermission("getSlotsMapping");
8775
8776 final long identity = Binder.clearCallingIdentity();
8777 try {
8778 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8779 // All logical slots should have a mapping to a physical slot.
8780 int[] logicalSlotsMapping = new int[phoneCount];
8781 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8782 for (int i = 0; i < slotInfos.length; i++) {
8783 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8784 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8785 }
8786 }
8787 return logicalSlotsMapping;
8788 } finally {
8789 Binder.restoreCallingIdentity(identity);
8790 }
8791 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008792
8793 /**
8794 * Get the IRadio HAL Version
8795 */
8796 @Override
8797 public int getRadioHalVersion() {
8798 Phone phone = getDefaultPhone();
8799 if (phone == null) return -1;
8800 HalVersion hv = phone.getHalVersion();
8801 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8802 return hv.major * 100 + hv.minor;
8803 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008804
8805 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008806 * Get the current calling package name.
8807 * @return the current calling package name
8808 */
8809 @Override
8810 public String getCurrentPackageName() {
8811 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8812 }
8813
8814 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008815 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8816 * corresponding network requests on a subId.
8817 *
8818 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008819 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008820 * 2) APN is un-metered for this subscription, or
8821 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008822 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008823 *
8824 * @return whether data is allowed for a apn type.
8825 *
8826 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008827 */
8828 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008829 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008830 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8831 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008832
8833 // Now that all security checks passes, perform the operation as ourselves.
8834 final long identity = Binder.clearCallingIdentity();
8835 try {
8836 Phone phone = getPhone(subId);
8837 if (phone == null) return false;
8838
Jack Yu41407ee2019-05-13 16:54:09 -07008839 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008840 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8841 } finally {
8842 Binder.restoreCallingIdentity(identity);
8843 }
8844 }
8845
8846 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008847 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008848 enforceReadPrivilegedPermission("isApnMetered");
8849
8850 // Now that all security checks passes, perform the operation as ourselves.
8851 final long identity = Binder.clearCallingIdentity();
8852 try {
8853 Phone phone = getPhone(subId);
8854 if (phone == null) return true; // By default return true.
8855
Jack Yu41407ee2019-05-13 16:54:09 -07008856 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008857 } finally {
8858 Binder.restoreCallingIdentity(identity);
8859 }
8860 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008861
8862 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008863 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8864 int subscriptionId, IBooleanConsumer resultCallback) {
8865 enforceModifyPermission();
8866 long token = Binder.clearCallingIdentity();
8867 try {
8868 Phone phone = getPhone(subscriptionId);
8869 if (phone == null) {
8870 try {
8871 if (resultCallback != null) {
8872 resultCallback.accept(false);
8873 }
8874 } catch (RemoteException e) {
8875 // ignore
8876 }
8877 return;
8878 }
8879 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8880 Pair.create(specifiers, (x) -> {
8881 try {
8882 if (resultCallback != null) {
8883 resultCallback.accept(x);
8884 }
8885 } catch (RemoteException e) {
8886 // ignore
8887 }
8888 });
8889 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8890 } finally {
8891 Binder.restoreCallingIdentity(token);
8892 }
8893 }
8894
8895 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008896 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8897 TelephonyPermissions
8898 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8899 mApp, subId, "getSystemSelectionChannels");
8900 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8901 final long identity = Binder.clearCallingIdentity();
8902 try {
8903 List<RadioAccessSpecifier> specifiers =
8904 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8905 null, subId, workSource);
8906 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8907 return specifiers;
8908 } finally {
8909 Binder.restoreCallingIdentity(identity);
8910 }
8911 }
8912
8913 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008914 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008915 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008916 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8917 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8918 if (iccRecords == null) {
8919 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8920 return false;
8921 }
8922 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8923 }
8924
8925 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008926 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8927 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008928 if (callingPackage == null) {
8929 callingPackage = getCurrentPackageName();
8930 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008931 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8932 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008933 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8934 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008935 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8936 }
8937 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8938 Intent intent = new Intent();
8939 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8940 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8941 // Bring up choose default SMS subscription dialog right now
8942 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8943 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8944 mApp.startActivity(intent);
8945 }
chen xud5ca2d52019-05-28 15:20:57 -07008946
8947 @Override
8948 public String getMmsUAProfUrl(int subId) {
8949 //TODO investigate if this API should require proper permission check in R b/133791609
8950 final long identity = Binder.clearCallingIdentity();
8951 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008952 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8953 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8954 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8955 return carrierUAProfUrl;
8956 }
chen xud5ca2d52019-05-28 15:20:57 -07008957 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8958 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8959 } finally {
8960 Binder.restoreCallingIdentity(identity);
8961 }
8962 }
8963
8964 @Override
8965 public String getMmsUserAgent(int subId) {
8966 //TODO investigate if this API should require proper permission check in R b/133791609
8967 final long identity = Binder.clearCallingIdentity();
8968 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008969 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8970 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8971 if (!TextUtils.isEmpty(carrierUserAgent)) {
8972 return carrierUserAgent;
8973 }
chen xud5ca2d52019-05-28 15:20:57 -07008974 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8975 .getString(com.android.internal.R.string.config_mms_user_agent);
8976 } finally {
8977 Binder.restoreCallingIdentity(identity);
8978 }
8979 }
Jack Yub07d4972019-05-28 16:12:25 -07008980
8981 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008982 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8983 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8984
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 Phone phone = getPhone(subscriptionId);
8988 if (phone == null) return false;
8989
8990 switch (policy) {
8991 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8992 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8993 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8994 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8995 default:
8996 throw new IllegalArgumentException(policy + " is not a valid policy");
8997 }
8998 } finally {
8999 Binder.restoreCallingIdentity(identity);
9000 }
9001 }
9002
9003 @Override
9004 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9005 boolean enabled) {
9006 enforceModifyPermission();
9007
9008 final long identity = Binder.clearCallingIdentity();
9009 try {
9010 Phone phone = getPhone(subscriptionId);
9011 if (phone == null) return;
9012
9013 switch (policy) {
9014 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9015 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9016 break;
9017 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9018 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9019 break;
9020 default:
9021 throw new IllegalArgumentException(policy + " is not a valid policy");
9022 }
9023 } finally {
9024 Binder.restoreCallingIdentity(identity);
9025 }
9026 }
9027
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009028 /**
Hall Liub48cf452020-09-25 11:13:49 -07009029 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009030 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9031 * otherwise.
9032 */
9033 @Override
9034 public void setCepEnabled(boolean isCepEnabled) {
9035 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9036
9037 final long identity = Binder.clearCallingIdentity();
9038 try {
9039 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9040 for (Phone phone : PhoneFactory.getPhones()) {
9041 Phone defaultPhone = phone.getImsPhone();
9042 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9043 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9044 ImsPhoneCallTracker imsPhoneCallTracker =
9045 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9046 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9047 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9048 + imsPhone.getMsisdn());
9049 }
9050 }
9051 } finally {
9052 Binder.restoreCallingIdentity(identity);
9053 }
9054 }
allenwtsu46dcc572020-01-08 18:24:03 +08009055
9056 /**
9057 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9058 *
9059 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9060 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9061 * before being read.
9062 */
9063 @Override
9064 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9065 isCompressed) {
9066 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9067 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009068 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9069 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9070 }
9071 if (!isImsAvailableOnDevice()) {
9072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9073 "IMS not available on device.");
9074 }
9075
9076 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009077 try {
Hui Wang068ab862020-10-31 05:12:53 +00009078 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009081 }
9082 }
zoey chenf95ca592019-12-30 16:11:23 +08009083
9084 @Override
9085 public boolean isIccLockEnabled(int subId) {
9086 enforceReadPrivilegedPermission("isIccLockEnabled");
9087
9088 // Now that all security checks passes, perform the operation as ourselves.
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
9091 Phone phone = getPhone(subId);
9092 if (phone != null && phone.getIccCard() != null) {
9093 return phone.getIccCard().getIccLockEnabled();
9094 } else {
9095 return false;
9096 }
9097 } finally {
9098 Binder.restoreCallingIdentity(identity);
9099 }
9100 }
9101
9102 /**
zoey chene02881a2019-12-30 16:11:23 +08009103 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009104 *
zoey chene02881a2019-12-30 16:11:23 +08009105 * @return an integer representing the status of IccLock enabled or disabled in the following
9106 * three cases:
9107 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9108 * successfully.
9109 * - Positive number and zero for remaining password attempts.
9110 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009111 *
9112 */
9113 @Override
9114 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9115 enforceModifyPermission();
9116
9117 Phone phone = getPhone(subId);
9118 if (phone == null) {
9119 return 0;
9120 }
9121 // Now that all security checks passes, perform the operation as ourselves.
9122 final long identity = Binder.clearCallingIdentity();
9123 try {
9124 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9125 new Pair<Boolean, String>(enabled, password), phone, null);
9126 return attemptsRemaining;
9127
9128 } catch (Exception e) {
9129 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9130 } finally {
9131 Binder.restoreCallingIdentity(identity);
9132 }
9133 return 0;
9134 }
9135
9136 /**
9137 * Change the ICC password used in ICC pin lock.
9138 *
zoey chene02881a2019-12-30 16:11:23 +08009139 * @return an integer representing the status of IccLock changed in the following three cases:
9140 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9141 * - Positive number and zero for remaining password attempts.
9142 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009143 *
9144 */
9145 @Override
9146 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9147 enforceModifyPermission();
9148
9149 Phone phone = getPhone(subId);
9150 if (phone == null) {
9151 return 0;
9152 }
9153 // Now that all security checks passes, perform the operation as ourselves.
9154 final long identity = Binder.clearCallingIdentity();
9155 try {
9156 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9157 new Pair<String, String>(oldPassword, newPassword), phone, null);
9158 return attemptsRemaining;
9159
9160 } catch (Exception e) {
9161 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9162 } finally {
9163 Binder.restoreCallingIdentity(identity);
9164 }
9165 return 0;
9166 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009167
Peter Wangdafb9ac2020-01-15 14:13:38 -08009168 /**
9169 * Request for receiving user activity notification
9170 */
9171 @Override
9172 public void requestUserActivityNotification() {
9173 if (!mNotifyUserActivity.get()
9174 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9175 mNotifyUserActivity.set(true);
9176 }
9177 }
9178
9179 /**
9180 * Called when userActivity is signalled in the power manager.
9181 * This is safe to call from any thread, with any window manager locks held or not.
9182 */
9183 @Override
9184 public void userActivity() {
9185 // ***************************************
9186 // * Inherited from PhoneWindowManager *
9187 // ***************************************
9188 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9189 // WITH ITS LOCKS HELD.
9190 //
9191 // This code must be VERY careful about the locks
9192 // it acquires.
9193 // In fact, the current code acquires way too many,
9194 // and probably has lurking deadlocks.
9195
9196 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9197 throw new SecurityException("Only the OS may call notifyUserActivity()");
9198 }
9199
9200 if (mNotifyUserActivity.getAndSet(false)) {
9201 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9202 USER_ACTIVITY_NOTIFICATION_DELAY);
9203 }
9204 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009205
Malcolm Chen884180b2020-04-13 11:59:40 -07009206 @Override
9207 public boolean canConnectTo5GInDsdsMode() {
9208 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9209 }
Jack Yud10cdd42020-09-28 20:28:01 -07009210
9211 @Override
9212 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9213 String callingFeatureId) {
9214 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9215 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9216 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9217 }
9218
9219 Phone phone = getPhone(subId);
9220 if (phone == null) {
9221 throw new RuntimeException("phone is not available");
9222 }
9223 // Now that all security checks passes, perform the operation as ourselves.
9224 final long identity = Binder.clearCallingIdentity();
9225 try {
9226 return phone.getEquivalentHomePlmns();
9227 } finally {
9228 Binder.restoreCallingIdentity(identity);
9229 }
9230 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009231
Hui Wang0866fcc2020-10-12 12:14:23 -07009232 @Override
9233 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9234 UaSecurityProtocolIdentifier securityProtocol,
9235 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9236 throws RemoteException {
9237 enforceModifyPermission();
9238 if (DBG) {
9239 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9240 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9241 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9242 }
9243
9244 if (!SubscriptionManager.isValidSubscriptionId(subId)
9245 || appType < TelephonyManager.APPTYPE_UNKNOWN
9246 || appType > TelephonyManager.APPTYPE_ISIM
9247 || nafUrl == null || securityProtocol == null || callback == null) {
9248 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9249 if (callback != null) {
9250 try {
9251 callback.onAuthenticationFailure(
9252 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9253 } catch (RemoteException exception) {
9254 log("Fail to notify onAuthenticationFailure due to " + exception);
9255 }
9256 return;
9257 }
9258 }
9259
9260 final long token = Binder.clearCallingIdentity();
9261 try {
9262 getGbaManager(subId).bootstrapAuthenticationRequest(
9263 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9264 forceBootStrapping, callback));
9265 } finally {
9266 Binder.restoreCallingIdentity(token);
9267 }
9268 }
9269
Jack Nudelman24d51a52020-11-24 12:08:04 -08009270 /**
9271 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9272 * requested radio power state will actually be set. See {@link
9273 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9274 *
9275 * @param subId the subscription ID of the phone requesting to set the radio power state.
9276 * @param enable {@code true} if trying to turn radio on.
9277 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9278 * false}.
9279 */
9280 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9281 Phone phone = getPhone(subId);
9282 if (phone != null) {
9283 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9284 return true;
9285 }
9286 return false;
9287 }
9288
9289 private int handleDataThrottlingRequest(int subId,
9290 DataThrottlingRequest dataThrottlingRequest) {
9291 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9292 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9293 if (!setRadioPowerForThermal(subId, true)) {
9294 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9295 }
9296
9297 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9298
9299 int thermalMitigationResult =
9300 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9301 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9302 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9303 }
9304 return thermalMitigationResult;
9305 }
9306
9307 /**
9308 * Thermal mitigation request to control functionalities at modem.
9309 *
9310 * @param subId the id of the subscription.
9311 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9312 *
9313 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9314 */
9315 @Override
9316 @ThermalMitigationResult
9317 public int sendThermalMitigationRequest(
9318 int subId,
9319 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9320 enforceModifyPermission();
9321
9322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9323 final long identity = Binder.clearCallingIdentity();
9324
9325 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9326 try {
9327 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9328 switch (thermalMitigationAction) {
9329 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9330 thermalMitigationResult =
9331 handleDataThrottlingRequest(subId,
9332 thermalMitigationRequest.getDataThrottlingRequest());
9333 break;
9334 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9335 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9336 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9337 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9338 }
9339
9340 // Ensure that radio is on. If not able to power on due to phone being
9341 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9342 if (!setRadioPowerForThermal(subId, true)) {
9343 thermalMitigationResult =
9344 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9345 break;
9346 }
9347
9348 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9349 false);
9350 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9351 break;
9352 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9353 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9354 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9355 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9356 }
9357
9358 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9359 if (registry != null) {
9360 TelephonyConnectionService service =
9361 registry.getTelephonyConnectionService();
9362 Phone phone = getPhone(subId);
9363 if (phone == null) {
9364 thermalMitigationResult =
9365 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9366 break;
9367 }
9368
9369 if (PhoneConstantConversions.convertCallState(phone.getState())
9370 != TelephonyManager.CALL_STATE_IDLE
9371 || phone.isInEmergencySmsMode() || phone.isInEcm()
9372 || (service != null && service.isEmergencyCallPending())) {
9373 String errorMessage = "Phone state is not valid. call state = "
9374 + PhoneConstantConversions.convertCallState(phone.getState())
9375 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9376 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9377 errorMessage += service == null
9378 ? " TelephonyConnectionService is null"
9379 : " isEmergencyCallPending = "
9380 + service.isEmergencyCallPending();
9381 Log.e(LOG_TAG, errorMessage);
9382 thermalMitigationResult =
9383 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9384 break;
9385 }
9386 } else {
9387 thermalMitigationResult =
9388 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9389 break;
9390 }
9391
9392 // Turn radio off. If not able to power off due to phone being unavailable,
9393 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9394 if (!setRadioPowerForThermal(subId, false)) {
9395 thermalMitigationResult =
9396 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9397 break;
9398 }
9399 thermalMitigationResult =
9400 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9401 break;
9402 default:
9403 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9404 + "not exist. Requested action: " + thermalMitigationAction);
9405 }
9406 } catch (IllegalArgumentException e) {
9407 throw e;
9408 } catch (Exception e) {
9409 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9410 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9411 } finally {
9412 Binder.restoreCallingIdentity(identity);
9413 }
9414
9415 if (DBG) {
9416 log("thermalMitigationRequest returning with thermalMitigationResult: "
9417 + thermalMitigationResult);
9418 }
9419
9420 return thermalMitigationResult;
9421 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009422
9423 /**
9424 * Set the GbaService Package Name that Telephony will bind to.
9425 *
9426 * @param subId The sim that the GbaService is associated with.
9427 * @param packageName The name of the package to be replaced with.
9428 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9429 */
9430 @Override
9431 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9432 enforceModifyPermission();
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 return getGbaManager(subId).overrideServicePackage(packageName);
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
9442 /**
9443 * Return the package name of the currently bound GbaService.
9444 *
9445 * @param subId The sim that the GbaService is associated with.
9446 * @return the package name of the GbaService configuration, null if GBA is not supported.
9447 */
9448 @Override
9449 public String getBoundGbaService(int subId) {
9450 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9451
9452 final long identity = Binder.clearCallingIdentity();
9453 try {
9454 return getGbaManager(subId).getServicePackage();
9455 } finally {
9456 Binder.restoreCallingIdentity(identity);
9457 }
9458 }
9459
9460 /**
9461 * Set the release time for telephony to unbind GbaService.
9462 *
9463 * @param subId The sim that the GbaService is associated with.
9464 * @param interval The release time to unbind GbaService by millisecond.
9465 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9466 */
9467 @Override
9468 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9469 enforceModifyPermission();
9470
9471 final long identity = Binder.clearCallingIdentity();
9472 try {
9473 return getGbaManager(subId).overrideReleaseTime(interval);
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478
9479 /**
9480 * Return the release time for telephony to unbind GbaService.
9481 *
9482 * @param subId The sim that the GbaService is associated with.
9483 * @return The release time to unbind GbaService by millisecond.
9484 */
9485 @Override
9486 public int getGbaReleaseTime(int subId) {
9487 enforceReadPrivilegedPermission("getGbaReleaseTime");
9488
9489 final long identity = Binder.clearCallingIdentity();
9490 try {
9491 return getGbaManager(subId).getReleaseTime();
9492 } finally {
9493 Binder.restoreCallingIdentity(identity);
9494 }
9495 }
9496
9497 private GbaManager getGbaManager(int subId) {
9498 GbaManager instance = GbaManager.getInstance(subId);
9499 if (instance == null) {
9500 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9501 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9502 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9503 }
9504 return instance;
9505 }
Hui Wang068ab862020-10-31 05:12:53 +00009506
9507 /**
9508 * indicate whether the device and the carrier can support
9509 * RCS VoLTE single registration.
9510 */
9511 @Override
9512 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9513 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9514
9515 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9516 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9517 }
9518
9519 final long identity = Binder.clearCallingIdentity();
9520 try {
9521 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9522 if (rpm != null) {
9523 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9524 }
9525 return false;
9526 } finally {
9527 Binder.restoreCallingIdentity(identity);
9528 }
9529 }
9530
9531 /**
9532 * Register RCS provisioning callback.
9533 */
9534 @Override
9535 public void registerRcsProvisioningChangedCallback(int subId,
9536 IRcsConfigCallback callback) {
9537 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9538
9539 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9540 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9541 }
9542 if (!isImsAvailableOnDevice()) {
9543 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9544 "IMS not available on device.");
9545 }
9546
9547 final long identity = Binder.clearCallingIdentity();
9548 try {
9549 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9550 .addRcsProvisioningCallbackForSubscription(callback, subId);
9551 } catch (ImsException e) {
9552 throw new ServiceSpecificException(e.getCode());
9553 } finally {
9554 Binder.restoreCallingIdentity(identity);
9555 }
9556 }
9557
9558 /**
9559 * Unregister RCS provisioning callback.
9560 */
9561 @Override
9562 public void unregisterRcsProvisioningChangedCallback(int subId,
9563 IRcsConfigCallback callback) {
9564 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9565
9566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9567 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9568 }
9569 if (!isImsAvailableOnDevice()) {
9570 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9571 "IMS not available on device.");
9572 }
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9577 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9578 } catch (ImsException e) {
9579 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9580 + "is inactive, ignoring unregister.");
9581 } finally {
9582 Binder.restoreCallingIdentity(identity);
9583 }
9584 }
9585
9586 /**
9587 * trigger RCS reconfiguration.
9588 */
9589 public void triggerRcsReconfiguration(int subId) {
9590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9591 mApp, subId, "triggerRcsReconfiguration");
9592
9593 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9594 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9595 }
9596 if (!isImsAvailableOnDevice()) {
9597 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9598 "IMS not available on device.");
9599 }
9600
9601 final long identity = Binder.clearCallingIdentity();
9602 try {
9603 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9604 } finally {
9605 Binder.restoreCallingIdentity(identity);
9606 }
9607 }
9608
9609 /**
9610 * Provide the client configuration parameters of the RCS application.
9611 */
9612 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9613 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9614 mApp, subId, "setRcsClientConfiguration");
9615
9616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9617 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9618 }
9619 if (!isImsAvailableOnDevice()) {
9620 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9621 "IMS not available on device.");
9622 }
9623
9624 final long identity = Binder.clearCallingIdentity();
9625
9626 try {
9627 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9628 if (configBinder == null) {
9629 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9630 } else {
9631 configBinder.setRcsClientConfiguration(rcc);
9632 }
9633 } catch (RemoteException e) {
9634 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9635 } finally {
9636 Binder.restoreCallingIdentity(identity);
9637 }
9638 }
9639
9640 /**
9641 * Overrides the config of RCS VoLTE single registration enabled for the device.
9642 */
9643 @Override
9644 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9645 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9646 "setDeviceSingleRegistrationEnabledOverride");
9647 enforceModifyPermission();
9648
9649 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9650 : Boolean.parseBoolean(enabledStr);
9651 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9652 }
9653
9654 /**
9655 * Gets the config of RCS VoLTE single registration enabled for the device.
9656 */
9657 @Override
9658 public boolean getDeviceSingleRegistrationEnabled() {
9659 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9660 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9661 }
9662
9663 /**
9664 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9665 */
9666 @Override
9667 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9668 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9669 "setCarrierSingleRegistrationEnabledOverride");
9670 enforceModifyPermission();
9671
9672 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9673 : Boolean.parseBoolean(enabledStr);
9674 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9675 subId, enabled);
9676 }
9677
9678 /**
9679 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9680 */
9681 @Override
9682 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9683 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9684 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9685 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009686}