blob: f8bef13cc21ec56a2123f7fb9c1e8dfe606c1fcc [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;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080054import android.os.SystemClock;
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;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080093import android.telephony.SignalStrengthUpdateRequest;
94import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080095import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080096import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080097import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070098import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800100import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800101import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800102import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000103import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700104import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700105import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800106import android.telephony.data.ApnSetting;
107import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700108import android.telephony.gba.GbaAuthRequest;
109import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700110import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800111import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000112import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700113import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700114import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800115import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700116import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800117import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700118import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000119import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700120import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800121import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800122import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800123import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800124import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800126import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700127import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700128import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800129import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800130
Andrew Lee312e8172014-10-23 17:01:36 -0700131import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800132import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800133import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800134import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700135import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700136import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700137import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800138import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700140import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800141import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700143import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800144import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800145import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700146import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700147import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800148import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700149import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800150import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700152import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700153import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700154import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700155import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800156import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700157import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700158import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700159import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700160import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700161import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700162import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700163import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800164import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800165import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800166import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700167import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800168import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700169import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800170import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700171import com.android.internal.telephony.imsphone.ImsPhone;
172import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800173import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900174import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700175import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800176import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800178import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700179import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700181import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800182import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000183import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800184import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700185import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700186import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800187import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700188import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700189import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800190import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700192import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800193import com.android.services.telephony.TelecomAccountRegistry;
194import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800195import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800196
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700197import java.io.FileDescriptor;
198import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800200import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800201import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800202import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800203import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100204import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800205import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700206import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800207import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800208import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800209import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800210import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700211
212/**
213 * Implementation of the ITelephony interface.
214 */
Santos Cordon117fee72014-05-16 17:56:12 -0700215public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216 private static final String LOG_TAG = "PhoneInterfaceManager";
217 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
218 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800219 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700220
221 // Message codes used with mMainThreadHandler
222 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700223 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
224 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700225 private static final int CMD_OPEN_CHANNEL = 9;
226 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
227 private static final int CMD_CLOSE_CHANNEL = 11;
228 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800229 private static final int CMD_NV_READ_ITEM = 13;
230 private static final int EVENT_NV_READ_ITEM_DONE = 14;
231 private static final int CMD_NV_WRITE_ITEM = 15;
232 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
233 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
234 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700235 private static final int CMD_RESET_MODEM_CONFIG = 19;
236 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800237 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
238 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800239 private static final int CMD_SEND_ENVELOPE = 25;
240 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000241 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
242 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700243 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
244 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
245 private static final int CMD_EXCHANGE_SIM_IO = 31;
246 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800247 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
248 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700249 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
250 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700251 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
252 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700253 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
254 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
255 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
256 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700257 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
258 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
259 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
260 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700261 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800262 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
263 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000264 private static final int CMD_SWITCH_SLOTS = 50;
265 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700266 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
267 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
268 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
269 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
270 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
271 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
272 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
273 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700274 private static final int CMD_GET_ALL_CELL_INFO = 60;
275 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
276 private static final int CMD_GET_CELL_LOCATION = 62;
277 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700278 private static final int CMD_MODEM_REBOOT = 64;
279 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700280 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
281 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800282 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
283 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700284 private static final int CMD_GET_MODEM_STATUS = 70;
285 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700286 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
287 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700288 private static final int CMD_ERASE_MODEM_CONFIG = 74;
289 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800290 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
291 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
292 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
293 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800294 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
295 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800296 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800297 private static final int CMD_GET_CALL_FORWARDING = 83;
298 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
299 private static final int CMD_SET_CALL_FORWARDING = 85;
300 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
301 private static final int CMD_GET_CALL_WAITING = 87;
302 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
303 private static final int CMD_SET_CALL_WAITING = 89;
304 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700305 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
306 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
307 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
308 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700309 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
310 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800311 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
312 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800313 private static final int CMD_SET_DATA_THROTTLING = 99;
314 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800315 private static final int CMD_SET_SIM_POWER = 101;
316 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800317 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
318 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
319 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
320 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800321 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
322 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000323 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700324
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800325 // Parameters of select command.
326 private static final int SELECT_COMMAND = 0xA4;
327 private static final int SELECT_P1 = 0x04;
328 private static final int SELECT_P2 = 0;
329 private static final int SELECT_P3 = 0x10;
330
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700331 /** The singleton instance. */
332 private static PhoneInterfaceManager sInstance;
333
Wink Saville3ab207e2014-11-20 13:07:20 -0800334 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800336 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700337 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800338 private AppOpsManager mAppOps;
339 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800340 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800341 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700342 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700343
Peter Wangdafb9ac2020-01-15 14:13:38 -0800344 /** User Activity */
345 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800346 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
347
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700348 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
349
Derek Tan97ebb422014-09-05 16:55:38 -0700350 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
351 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800352 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800353 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700354
Michelecea4cf22018-12-21 15:00:11 -0800355 // String to store multi SIM allowed
356 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
357
Derek Tan740e1672017-06-27 14:56:27 -0700358 // The AID of ISD-R.
359 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
360
yinxub1bed742017-04-17 11:45:04 -0700361 private NetworkScanRequestTracker mNetworkScanRequestTracker;
362
David Kelly5e06a7f2018-03-12 14:10:59 +0000363 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
364 private static final int MANUFACTURER_CODE_LENGTH = 8;
365
Jack Nudelman24d51a52020-11-24 12:08:04 -0800366 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
367
Derek Tan89e89d42014-07-08 17:00:10 -0700368 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700369 * Experiment flag to enable erase modem config on reset network, default value is false
370 */
371 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
372 "reset_network_erase_modem_config_enabled";
373
Rambo Wang0f050d82021-02-12 11:43:36 -0800374 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
375
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700376 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700377 * A request object to use for transmitting data to an ICC.
378 */
379 private static final class IccAPDUArgument {
380 public int channel, cla, command, p1, p2, p3;
381 public String data;
382
383 public IccAPDUArgument(int channel, int cla, int command,
384 int p1, int p2, int p3, String data) {
385 this.channel = channel;
386 this.cla = cla;
387 this.command = command;
388 this.p1 = p1;
389 this.p2 = p2;
390 this.p3 = p3;
391 this.data = data;
392 }
393 }
394
395 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700396 * A request object to use for transmitting data to an ICC.
397 */
398 private static final class ManualNetworkSelectionArgument {
399 public OperatorInfo operatorInfo;
400 public boolean persistSelection;
401
402 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
403 this.operatorInfo = operatorInfo;
404 this.persistSelection = persistSelection;
405 }
406 }
407
408 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
410 * request after sending. The main thread will notify the request when it is complete.
411 */
412 private static final class MainThreadRequest {
413 /** The argument to use for the request */
414 public Object argument;
415 /** The result of the request that is run on the main thread */
416 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800417 // The subscriber id that this request applies to. Defaults to
418 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
419 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420
Nathan Harold92bed182018-10-12 18:16:49 -0700421 // In cases where subId is unavailable, the caller needs to specify the phone.
422 public Phone phone;
423
vagdeviaf9a5b92018-08-15 16:01:53 -0700424 public WorkSource workSource;
425
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700426 public MainThreadRequest(Object argument) {
427 this.argument = argument;
428 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800429
Nathan Harold92bed182018-10-12 18:16:49 -0700430 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
431 this.argument = argument;
432 if (phone != null) {
433 this.phone = phone;
434 }
435 this.workSource = workSource;
436 }
437
vagdeviaf9a5b92018-08-15 16:01:53 -0700438 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800439 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800440 if (subId != null) {
441 this.subId = subId;
442 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700443 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445 }
446
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800447 private static final class IncomingThirdPartyCallArgs {
448 public final ComponentName component;
449 public final String callId;
450 public final String callerDisplayName;
451
452 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
453 String callerDisplayName) {
454 this.component = component;
455 this.callId = callId;
456 this.callerDisplayName = callerDisplayName;
457 }
458 }
459
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700460 /**
461 * A handler that processes messages on the main thread in the phone process. Since many
462 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
463 * inbound binder threads to the main thread in the phone process. The Binder thread
464 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
465 * on, which will be notified when the operation completes and will contain the result of the
466 * request.
467 *
468 * <p>If a MainThreadRequest object is provided in the msg.obj field,
469 * note that request.result must be set to something non-null for the calling thread to
470 * unblock.
471 */
472 private final class MainThreadHandler extends Handler {
473 @Override
474 public void handleMessage(Message msg) {
475 MainThreadRequest request;
476 Message onCompleted;
477 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800478 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700479 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800480 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
482 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 case CMD_HANDLE_USSD_REQUEST: {
484 request = (MainThreadRequest) msg.obj;
485 final Phone phone = getPhoneFromRequest(request);
486 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
487 String ussdRequest = ussdObject.first;
488 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700489
Pengquan Menga1bb6272018-09-06 09:59:22 -0700490 if (!isUssdApiAllowed(request.subId)) {
491 // Carrier does not support use of this API, return failure.
492 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
493 UssdResponse response = new UssdResponse(ussdRequest, null);
494 Bundle returnData = new Bundle();
495 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
496 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700497
Pengquan Menga1bb6272018-09-06 09:59:22 -0700498 request.result = true;
499 notifyRequester(request);
500 return;
501 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700502
Pengquan Menga1bb6272018-09-06 09:59:22 -0700503 try {
504 request.result = phone != null
505 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
506 } catch (CallStateException cse) {
507 request.result = false;
508 }
509 // Wake up the requesting thread
510 notifyRequester(request);
511 break;
pkanwar32d516d2016-10-14 19:37:38 -0700512 }
513
Yorke Lee716f67e2015-06-17 15:39:16 -0700514 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700515 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700516 final Phone phone = getPhoneFromRequest(request);
517 request.result = phone != null ?
518 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
519 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700520 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700522 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700524
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700525 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700526 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800528 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 if (uiccCard == null) {
530 loge("iccTransmitApduLogicalChannel: No UICC");
531 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700532 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700533 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
535 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700536 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700537 iccArgument.channel, iccArgument.cla, iccArgument.command,
538 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700539 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700540 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700541 break;
542
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700543 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800552 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700553 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800554 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700555 } else {
556 loge("iccTransmitApduLogicalChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700560 break;
561
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccTransmitApduBasicChannel: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
572 request);
573 uiccCard.iccTransmitApduBasicChannel(
574 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
575 iccArgument.p3, iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6F, 0, (byte[])null);
586 if (ar.result == null) {
587 loge("iccTransmitApduBasicChannel: Empty response");
588 } else if (ar.exception instanceof CommandException) {
589 loge("iccTransmitApduBasicChannel: CommandException: " +
590 ar.exception);
591 } else {
592 loge("iccTransmitApduBasicChannel: Unknown exception");
593 }
594 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700595 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700596 break;
597
598 case CMD_EXCHANGE_SIM_IO:
599 request = (MainThreadRequest) msg.obj;
600 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800601 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700602 if (uiccCard == null) {
603 loge("iccExchangeSimIO: No UICC");
604 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700605 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700606 } else {
607 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
608 request);
609 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
610 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
611 iccArgument.data, onCompleted);
612 }
613 break;
614
615 case EVENT_EXCHANGE_SIM_IO_DONE:
616 ar = (AsyncResult) msg.obj;
617 request = (MainThreadRequest) ar.userObj;
618 if (ar.exception == null && ar.result != null) {
619 request.result = ar.result;
620 } else {
621 request.result = new IccIoResult(0x6f, 0, (byte[])null);
622 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700624 break;
625
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 case CMD_SEND_ENVELOPE:
627 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800628 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 if (uiccCard == null) {
630 loge("sendEnvelopeWithStatus: No UICC");
631 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700632 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 } else {
634 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
635 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
636 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800637 break;
638
639 case EVENT_SEND_ENVELOPE_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700642 if (ar.exception == null && ar.result != null) {
643 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800644 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700645 request.result = new IccIoResult(0x6F, 0, (byte[])null);
646 if (ar.result == null) {
647 loge("sendEnvelopeWithStatus: Empty response");
648 } else if (ar.exception instanceof CommandException) {
649 loge("sendEnvelopeWithStatus: CommandException: " +
650 ar.exception);
651 } else {
652 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
653 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800654 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800656 break;
657
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 case CMD_OPEN_CHANNEL:
659 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800660 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800661 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700662 if (uiccCard == null) {
663 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800664 request.result = new IccOpenLogicalChannelResponse(-1,
665 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700666 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700667 } else {
668 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800669 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
670 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700671 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 break;
673
674 case EVENT_OPEN_CHANNEL_DONE:
675 ar = (AsyncResult) msg.obj;
676 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700677 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700679 int[] result = (int[]) ar.result;
680 int channelId = result[0];
681 byte[] selectResponse = null;
682 if (result.length > 1) {
683 selectResponse = new byte[result.length - 1];
684 for (int i = 1; i < result.length; ++i) {
685 selectResponse[i - 1] = (byte) result[i];
686 }
687 }
688 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700689 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 if (ar.result == null) {
692 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700693 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700694 if (ar.exception != null) {
695 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
696 }
697
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700698 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700699 if (ar.exception instanceof CommandException) {
700 CommandException.Error error =
701 ((CommandException) (ar.exception)).getCommandError();
702 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700703 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700704 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700705 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700706 }
707 }
708 openChannelResp = new IccOpenLogicalChannelResponse(
709 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700711 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 break;
714
715 case CMD_CLOSE_CHANNEL:
716 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800717 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700718 if (uiccCard == null) {
719 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900720 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700721 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700722 } else {
723 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
724 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
725 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700726 break;
727
728 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800729 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
730 break;
731
732 case CMD_NV_READ_ITEM:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
736 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800737 break;
738
739 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 ar = (AsyncResult) msg.obj;
741 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800742 if (ar.exception == null && ar.result != null) {
743 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700744 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800745 request.result = "";
746 if (ar.result == null) {
747 loge("nvReadItem: Empty response");
748 } else if (ar.exception instanceof CommandException) {
749 loge("nvReadItem: CommandException: " +
750 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700751 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800752 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700753 }
754 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700755 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700756 break;
757
Jake Hambye994d462014-02-03 13:10:13 -0800758 case CMD_NV_WRITE_ITEM:
759 request = (MainThreadRequest) msg.obj;
760 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
761 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700763 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800764 break;
765
766 case EVENT_NV_WRITE_ITEM_DONE:
767 handleNullReturnEvent(msg, "nvWriteItem");
768 break;
769
770 case CMD_NV_WRITE_CDMA_PRL:
771 request = (MainThreadRequest) msg.obj;
772 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800773 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800774 break;
775
776 case EVENT_NV_WRITE_CDMA_PRL_DONE:
777 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
778 break;
779
chen xu6dac5ab2018-10-26 17:39:23 -0700780 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800781 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700782 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800783 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800784 break;
785
chen xu6dac5ab2018-10-26 17:39:23 -0700786 case EVENT_RESET_MODEM_CONFIG_DONE:
787 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800788 break;
789
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700790 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
791 request = (MainThreadRequest) msg.obj;
792 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
793 request);
794 Phone phone = getPhoneFromRequest(request);
795 if (phone != null) {
796 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
797 } else {
798 loge("isNRDualConnectivityEnabled: No phone object");
799 request.result = false;
800 notifyRequester(request);
801 }
802 break;
803 }
804
805 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
806 ar = (AsyncResult) msg.obj;
807 request = (MainThreadRequest) ar.userObj;
808 if (ar.exception == null && ar.result != null) {
809 request.result = ar.result;
810 } else {
811 // request.result must be set to something non-null
812 // for the calling thread to unblock
813 if (request.result != null) {
814 request.result = ar.result;
815 } else {
816 request.result = false;
817 }
818 if (ar.result == null) {
819 loge("isNRDualConnectivityEnabled: Empty response");
820 } else if (ar.exception instanceof CommandException) {
821 loge("isNRDualConnectivityEnabled: CommandException: "
822 + ar.exception);
823 } else {
824 loge("isNRDualConnectivityEnabled: Unknown exception");
825 }
826 }
827 notifyRequester(request);
828 break;
829
830 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
833 Phone phone = getPhoneFromRequest(request);
834 if (phone != null) {
835 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
836 request.workSource);
837 } else {
838 loge("enableNrDualConnectivity: No phone object");
839 request.result =
840 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
841 notifyRequester(request);
842 }
843 break;
844 }
845
846 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
847 ar = (AsyncResult) msg.obj;
848 request = (MainThreadRequest) ar.userObj;
849 if (ar.exception == null) {
850 request.result =
851 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
852 } else {
853 request.result =
854 TelephonyManager
855 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
856 if (ar.exception instanceof CommandException) {
857 CommandException.Error error =
858 ((CommandException) (ar.exception)).getCommandError();
859 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
860 request.result =
861 TelephonyManager
862 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
863 }
864 loge("enableNrDualConnectivity" + ": CommandException: "
865 + ar.exception);
866 } else {
867 loge("enableNrDualConnectivity" + ": Unknown exception");
868 }
869 }
870 notifyRequester(request);
871 break;
872 }
873
SongFerngWang9e060372020-12-21 16:41:52 +0800874 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800876 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
877 request);
878 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 break;
880
SongFerngWang9e060372020-12-21 16:41:52 +0800881 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result; // Integer
886 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530887 // request.result must be set to something non-null
888 // for the calling thread to unblock
889 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800891 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800892 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800893 loge("getAllowedNetworkTypesBitmask: CommandException: "
894 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800896 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 break;
901
SongFerngWang9e060372020-12-21 16:41:52 +0800902 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800903 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800904 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
905 request);
906 Pair<Integer, Long> reasonWithNetworkTypes =
907 (Pair<Integer, Long>) request.argument;
908 getPhoneFromRequest(request).setAllowedNetworkTypes(
909 reasonWithNetworkTypes.first,
910 reasonWithNetworkTypes.second,
911 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800912 break;
913
SongFerngWang9e060372020-12-21 16:41:52 +0800914 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
915 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800916 break;
917
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000918 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
919 request = (MainThreadRequest)msg.obj;
920 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800921 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000922 break;
923
924 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
925 ar = (AsyncResult)msg.obj;
926 request = (MainThreadRequest)ar.userObj;
927 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700928 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000929 break;
930
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800931 case CMD_SET_VOICEMAIL_NUMBER:
932 request = (MainThreadRequest) msg.obj;
933 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
934 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800935 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
936 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800937 break;
938
939 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
940 handleNullReturnEvent(msg, "setVoicemailNumber");
941 break;
942
Stuart Scott54788802015-03-30 13:18:01 -0700943 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
946 request);
947 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
948 break;
949
950 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
951 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
952 break;
953
Shishir Agrawal302c8692015-06-19 13:49:39 -0700954 case CMD_PERFORM_NETWORK_SCAN:
955 request = (MainThreadRequest) msg.obj;
956 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
957 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
958 break;
959
Hall Liua1acea22020-09-18 19:04:59 -0700960 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800961 request = (MainThreadRequest) msg.obj;
962 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700963 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
964 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
965 request.argument;
966 int callForwardingReason = args.first;
967 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800968 break;
Hall Liua1acea22020-09-18 19:04:59 -0700969 }
970 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800971 ar = (AsyncResult) msg.obj;
972 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700973 TelephonyManager.CallForwardingInfoCallback callback =
974 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
975 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800976 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700977 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800978 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
979 for (CallForwardInfo callForwardInfo : callForwardInfos) {
980 // Service Class is a bit mask per 3gpp 27.007. Search for
981 // any service for voice call.
982 if ((callForwardInfo.serviceClass
983 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700984 callForwardingInfo = new CallForwardingInfo(true,
985 callForwardInfo.reason,
986 callForwardInfo.number,
987 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800988 break;
989 }
990 }
991 // Didn't find a call forward info for voice call.
992 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700993 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
994 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800995 }
Hall Liua1acea22020-09-18 19:04:59 -0700996 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800997 } else {
998 if (ar.result == null) {
999 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1000 }
1001 if (ar.exception != null) {
1002 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1003 }
Hall Liuae527aa2020-09-29 17:10:18 -07001004 int errorCode = TelephonyManager
1005 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001006 if (ar.exception instanceof CommandException) {
1007 CommandException.Error error =
1008 ((CommandException) (ar.exception)).getCommandError();
1009 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001010 errorCode = TelephonyManager
1011 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001012 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001013 errorCode = TelephonyManager
1014 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001015 }
1016 }
Hall Liua1acea22020-09-18 19:04:59 -07001017 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001018 }
sqian80370722020-01-29 15:02:51 -08001019 break;
Hall Liua1acea22020-09-18 19:04:59 -07001020 }
sqian80370722020-01-29 15:02:51 -08001021
Hall Liua1acea22020-09-18 19:04:59 -07001022 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001025 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001026 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001027 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1028 request.argument).first;
1029 request.phone.setCallForwardingOption(
1030 callForwardingInfoToSet.isEnabled()
1031 ? CommandsInterface.CF_ACTION_ENABLE
1032 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001033 callForwardingInfoToSet.getReason(),
1034 callForwardingInfoToSet.getNumber(),
1035 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1036 break;
Hall Liua1acea22020-09-18 19:04:59 -07001037 }
sqian80370722020-01-29 15:02:51 -08001038
Hall Liua1acea22020-09-18 19:04:59 -07001039 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001040 ar = (AsyncResult) msg.obj;
1041 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001042 Consumer<Integer> callback =
1043 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1044 request.argument).second;
1045 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001046 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001047 int errorCode = TelephonyManager.CallForwardingInfoCallback
1048 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001049 if (ar.exception instanceof CommandException) {
1050 CommandException.Error error =
1051 ((CommandException) (ar.exception)).getCommandError();
1052 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001053 errorCode = TelephonyManager.CallForwardingInfoCallback
1054 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001055 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001056 errorCode = TelephonyManager.CallForwardingInfoCallback
1057 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001058 }
1059 }
1060 callback.accept(errorCode);
1061 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001062 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001063 }
sqian80370722020-01-29 15:02:51 -08001064 break;
Hall Liua1acea22020-09-18 19:04:59 -07001065 }
sqian80370722020-01-29 15:02:51 -08001066
Hall Liua1acea22020-09-18 19:04:59 -07001067 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001068 request = (MainThreadRequest) msg.obj;
1069 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1070 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1071 break;
Hall Liua1acea22020-09-18 19:04:59 -07001072 }
sqian80370722020-01-29 15:02:51 -08001073
Hall Liua1acea22020-09-18 19:04:59 -07001074 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001075 ar = (AsyncResult) msg.obj;
1076 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001077 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001078 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1079 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001080 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001081 // Service Class is a bit mask per 3gpp 27.007.
1082 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001083 if (callForwardResults.length > 1
1084 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001085 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001086 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001087 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1088 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001089 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001090 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001091 }
1092 } else {
1093 if (ar.result == null) {
1094 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1095 }
1096 if (ar.exception != null) {
1097 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1098 }
1099 if (ar.exception instanceof CommandException) {
1100 CommandException.Error error =
1101 ((CommandException) (ar.exception)).getCommandError();
1102 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1103 callForwardingStatus =
1104 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1105 }
1106 }
1107 }
Hall Liua1acea22020-09-18 19:04:59 -07001108 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001109 break;
Hall Liua1acea22020-09-18 19:04:59 -07001110 }
sqian80370722020-01-29 15:02:51 -08001111
Hall Liua1acea22020-09-18 19:04:59 -07001112 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001113 request = (MainThreadRequest) msg.obj;
1114 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001115 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1116 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001117 break;
Hall Liua1acea22020-09-18 19:04:59 -07001118 }
sqian80370722020-01-29 15:02:51 -08001119
Hall Liua1acea22020-09-18 19:04:59 -07001120 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001121 ar = (AsyncResult) msg.obj;
1122 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001123 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1124 Consumer<Integer> callback =
1125 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1126 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001127 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001128 if (ar.exception instanceof CommandException) {
1129 CommandException.Error error =
1130 ((CommandException) (ar.exception)).getCommandError();
1131 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1132 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1133 } else {
1134 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1135 }
1136 } else {
1137 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1138 }
1139 } else {
1140 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1141 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001142 }
sqian80370722020-01-29 15:02:51 -08001143 break;
Hall Liua1acea22020-09-18 19:04:59 -07001144 }
sqian80370722020-01-29 15:02:51 -08001145
Shishir Agrawal302c8692015-06-19 13:49:39 -07001146 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 CellNetworkScanResult cellScanResult;
1150 if (ar.exception == null && ar.result != null) {
1151 cellScanResult = new CellNetworkScanResult(
1152 CellNetworkScanResult.STATUS_SUCCESS,
1153 (List<OperatorInfo>) ar.result);
1154 } else {
1155 if (ar.result == null) {
1156 loge("getCellNetworkScanResults: Empty response");
1157 }
1158 if (ar.exception != null) {
1159 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1160 }
1161 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1162 if (ar.exception instanceof CommandException) {
1163 CommandException.Error error =
1164 ((CommandException) (ar.exception)).getCommandError();
1165 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1166 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1167 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1168 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1169 }
1170 }
1171 cellScanResult = new CellNetworkScanResult(errorCode, null);
1172 }
1173 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001174 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001175 break;
1176
1177 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1178 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001179 ManualNetworkSelectionArgument selArg =
1180 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1182 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001183 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1184 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001185 break;
1186
1187 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001188 ar = (AsyncResult) msg.obj;
1189 request = (MainThreadRequest) ar.userObj;
1190 if (ar.exception == null) {
1191 request.result = true;
1192 } else {
1193 request.result = false;
1194 loge("setNetworkSelectionModeManual " + ar.exception);
1195 }
1196 notifyRequester(request);
1197 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001198 break;
1199
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001200 case CMD_GET_MODEM_ACTIVITY_INFO:
1201 request = (MainThreadRequest) msg.obj;
1202 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001203 if (defaultPhone != null) {
1204 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001205 } else {
1206 ResultReceiver result = (ResultReceiver) request.argument;
1207 Bundle bundle = new Bundle();
1208 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1209 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1210 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001211 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001212 break;
1213
1214 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1215 ar = (AsyncResult) msg.obj;
1216 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001217 ResultReceiver result = (ResultReceiver) request.argument;
1218
1219 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001220 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001221 // Update the last modem activity info and the result of the request.
1222 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1223 if (isModemActivityInfoValid(info)) {
1224 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1225 int[] txTimeMs = info.getTransmitTimeMillis();
1226 int[] lastModemTxTimeMs = mLastModemActivityInfo
1227 .getTransmitTimeMillis();
1228 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1229 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1230 }
1231 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1232 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1233 + mLastModemActivityInfo.getSleepTimeMillis());
1234 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1235 + mLastModemActivityInfo.getIdleTimeMillis());
1236 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1237 mLastModemActivityInfo.setReceiveTimeMillis(
1238 info.getReceiveTimeMillis()
1239 + mLastModemActivityInfo.getReceiveTimeMillis());
1240 }
1241 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1242 mLastModemActivityInfo.getSleepTimeMillis(),
1243 mLastModemActivityInfo.getIdleTimeMillis(),
1244 mLastModemActivityInfo.getTransmitTimeMillis(),
1245 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001246 } else {
1247 if (ar.result == null) {
1248 loge("queryModemActivityInfo: Empty response");
1249 } else if (ar.exception instanceof CommandException) {
1250 loge("queryModemActivityInfo: CommandException: " +
1251 ar.exception);
1252 } else {
1253 loge("queryModemActivityInfo: Unknown exception");
1254 }
1255 }
sqian1a1be542020-03-05 11:37:28 -08001256 Bundle bundle = new Bundle();
1257 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1258 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001259 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001260 break;
1261
Meng Wang1a7c35a2016-05-05 20:56:15 -07001262 case CMD_SET_ALLOWED_CARRIERS:
1263 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001264 CarrierRestrictionRules argument =
1265 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001266 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001267 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001268 break;
1269
1270 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1271 ar = (AsyncResult) msg.obj;
1272 request = (MainThreadRequest) ar.userObj;
1273 if (ar.exception == null && ar.result != null) {
1274 request.result = ar.result;
1275 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001276 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1277 if (ar.exception instanceof CommandException) {
1278 loge("setAllowedCarriers: CommandException: " + ar.exception);
1279 CommandException.Error error =
1280 ((CommandException) (ar.exception)).getCommandError();
1281 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1282 request.result =
1283 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1284 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 } else {
1286 loge("setAllowedCarriers: Unknown exception");
1287 }
1288 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001289 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001290 break;
1291
1292 case CMD_GET_ALLOWED_CARRIERS:
1293 request = (MainThreadRequest) msg.obj;
1294 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001295 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001296 break;
1297
1298 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1299 ar = (AsyncResult) msg.obj;
1300 request = (MainThreadRequest) ar.userObj;
1301 if (ar.exception == null && ar.result != null) {
1302 request.result = ar.result;
1303 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001304 request.result = new IllegalStateException(
1305 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001306 if (ar.result == null) {
1307 loge("getAllowedCarriers: Empty response");
1308 } else if (ar.exception instanceof CommandException) {
1309 loge("getAllowedCarriers: CommandException: " +
1310 ar.exception);
1311 } else {
1312 loge("getAllowedCarriers: Unknown exception");
1313 }
1314 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001315 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001316 break;
1317
Nathan Haroldb3014052017-01-25 15:57:32 -08001318 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1319 ar = (AsyncResult) msg.obj;
1320 request = (MainThreadRequest) ar.userObj;
1321 if (ar.exception == null && ar.result != null) {
1322 request.result = ar.result;
1323 } else {
1324 request.result = new IllegalArgumentException(
1325 "Failed to retrieve Forbidden Plmns");
1326 if (ar.result == null) {
1327 loge("getForbiddenPlmns: Empty response");
1328 } else {
1329 loge("getForbiddenPlmns: Unknown exception");
1330 }
1331 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001332 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001333 break;
1334
1335 case CMD_GET_FORBIDDEN_PLMNS:
1336 request = (MainThreadRequest) msg.obj;
1337 uiccCard = getUiccCardFromRequest(request);
1338 if (uiccCard == null) {
1339 loge("getForbiddenPlmns() UiccCard is null");
1340 request.result = new IllegalArgumentException(
1341 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001342 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001343 break;
1344 }
1345 Integer appType = (Integer) request.argument;
1346 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1347 if (uiccApp == null) {
1348 loge("getForbiddenPlmns() no app with specified type -- "
1349 + appType);
1350 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001351 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001352 break;
1353 } else {
1354 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1355 + " specified type -- " + appType);
1356 }
1357 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1358 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1359 onCompleted);
1360 break;
1361
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001362 case CMD_SWITCH_SLOTS:
1363 request = (MainThreadRequest) msg.obj;
1364 int[] physicalSlots = (int[]) request.argument;
1365 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1366 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1367 break;
1368
1369 case EVENT_SWITCH_SLOTS_DONE:
1370 ar = (AsyncResult) msg.obj;
1371 request = (MainThreadRequest) ar.userObj;
1372 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001373 notifyRequester(request);
1374 break;
1375 case CMD_GET_NETWORK_SELECTION_MODE:
1376 request = (MainThreadRequest) msg.obj;
1377 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1378 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1379 break;
1380
1381 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1382 ar = (AsyncResult) msg.obj;
1383 request = (MainThreadRequest) ar.userObj;
1384 if (ar.exception != null) {
1385 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1386 } else {
1387 int mode = ((int[]) ar.result)[0];
1388 if (mode == 0) {
1389 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1390 } else {
1391 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1392 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001393 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001394 notifyRequester(request);
1395 break;
1396 case CMD_GET_CDMA_ROAMING_MODE:
1397 request = (MainThreadRequest) msg.obj;
1398 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1399 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1400 break;
1401 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception != null) {
1405 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1406 } else {
1407 request.result = ((int[]) ar.result)[0];
1408 }
1409 notifyRequester(request);
1410 break;
1411 case CMD_SET_CDMA_ROAMING_MODE:
1412 request = (MainThreadRequest) msg.obj;
1413 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1414 int mode = (int) request.argument;
1415 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1416 break;
1417 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1418 ar = (AsyncResult) msg.obj;
1419 request = (MainThreadRequest) ar.userObj;
1420 request.result = ar.exception == null;
1421 notifyRequester(request);
1422 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001423 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1424 request = (MainThreadRequest) msg.obj;
1425 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1426 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1427 break;
1428 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 if (ar.exception != null) {
1432 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1433 } else {
1434 request.result = ((int[]) ar.result)[0];
1435 }
1436 notifyRequester(request);
1437 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001438 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1439 request = (MainThreadRequest) msg.obj;
1440 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1441 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001442 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1443 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001444 break;
1445 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1446 ar = (AsyncResult) msg.obj;
1447 request = (MainThreadRequest) ar.userObj;
1448 request.result = ar.exception == null;
1449 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001450 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 case CMD_GET_ALL_CELL_INFO:
1452 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001453 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001454 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001455 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 case EVENT_GET_ALL_CELL_INFO_DONE:
1457 ar = (AsyncResult) msg.obj;
1458 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001459 // If a timeout occurs, the response will be null
1460 request.result = (ar.exception == null && ar.result != null)
1461 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001462 synchronized (request) {
1463 request.notifyAll();
1464 }
1465 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001466 case CMD_REQUEST_CELL_INFO_UPDATE:
1467 request = (MainThreadRequest) msg.obj;
1468 request.phone.requestCellInfoUpdate(request.workSource,
1469 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1470 break;
1471 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1472 ar = (AsyncResult) msg.obj;
1473 request = (MainThreadRequest) ar.userObj;
1474 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1475 try {
1476 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001478 cb.onError(
1479 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1480 ar.exception.getClass().getName(),
1481 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001484 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001485 } else {
1486 // use the result as returned
1487 cb.onCellInfo((List<CellInfo>) ar.result);
1488 }
1489 } catch (RemoteException re) {
1490 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1491 }
1492 break;
Sarah Chincc055732020-11-18 13:39:35 -08001493 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001494 request = (MainThreadRequest) msg.obj;
1495 WorkSource ws = (WorkSource) request.argument;
1496 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001497 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001498 break;
Sarah Chincc055732020-11-18 13:39:35 -08001499 }
1500 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001501 ar = (AsyncResult) msg.obj;
1502 request = (MainThreadRequest) ar.userObj;
1503 if (ar.exception == null) {
1504 request.result = ar.result;
1505 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001506 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001507 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001508 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001509 }
1510
1511 synchronized (request) {
1512 request.notifyAll();
1513 }
1514 break;
Sarah Chincc055732020-11-18 13:39:35 -08001515 }
chen xu6dac5ab2018-10-26 17:39:23 -07001516 case CMD_MODEM_REBOOT:
1517 request = (MainThreadRequest) msg.obj;
1518 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001519 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001520 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001521 case EVENT_CMD_MODEM_REBOOT_DONE:
1522 handleNullReturnEvent(msg, "rebootModem");
1523 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001524 case CMD_REQUEST_ENABLE_MODEM:
1525 request = (MainThreadRequest) msg.obj;
1526 boolean enable = (boolean) request.argument;
1527 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001528 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001529 PhoneConfigurationManager.getInstance()
1530 .enablePhone(request.phone, enable, onCompleted);
1531 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001532 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001533 ar = (AsyncResult) msg.obj;
1534 request = (MainThreadRequest) ar.userObj;
1535 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001536 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001537 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001538 if ((boolean) request.result) {
1539 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1540 updateModemStateMetrics();
1541 } else {
1542 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1543 + ar.exception);
1544 }
1545 notifyRequester(request);
1546 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001547 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001548 case CMD_GET_MODEM_STATUS:
1549 request = (MainThreadRequest) msg.obj;
1550 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1551 PhoneConfigurationManager.getInstance()
1552 .getPhoneStatusFromModem(request.phone, onCompleted);
1553 break;
1554 case EVENT_GET_MODEM_STATUS_DONE:
1555 ar = (AsyncResult) msg.obj;
1556 request = (MainThreadRequest) ar.userObj;
1557 int id = request.phone.getPhoneId();
1558 if (ar.exception == null && ar.result != null) {
1559 request.result = ar.result;
1560 //update the cache as modem status has changed
1561 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1562 (boolean) request.result);
1563 } else {
1564 // Return true if modem status cannot be retrieved. For most cases,
1565 // modem status is on. And for older version modems, GET_MODEM_STATUS
1566 // and disable modem are not supported. Modem is always on.
1567 // TODO: this should be fixed in R to support a third
1568 // status UNKNOWN b/131631629
1569 request.result = true;
1570 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1571 + ar.exception);
1572 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001573 notifyRequester(request);
1574 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001575 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1576 request = (MainThreadRequest) msg.obj;
1577 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1578 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1579 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1580 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1581 break;
1582 }
1583 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1584 ar = (AsyncResult) msg.obj;
1585 request = (MainThreadRequest) ar.userObj;
1586 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1587 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1588 args.second.accept(ar.exception == null);
1589 notifyRequester(request);
1590 break;
1591 }
Sarah Chincc055732020-11-18 13:39:35 -08001592 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1593 request = (MainThreadRequest) msg.obj;
1594 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1595 Phone phone = getPhoneFromRequest(request);
1596 if (phone != null) {
1597 phone.getSystemSelectionChannels(onCompleted);
1598 } else {
1599 loge("getSystemSelectionChannels: No phone object");
1600 request.result = new ArrayList<RadioAccessSpecifier>();
1601 notifyRequester(request);
1602 }
1603 break;
1604 }
1605 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1606 ar = (AsyncResult) msg.obj;
1607 request = (MainThreadRequest) ar.userObj;
1608 if (ar.exception == null && ar.result != null) {
1609 request.result = ar.result;
1610 } else {
1611 request.result = new IllegalArgumentException(
1612 "Failed to retrieve system selection channels");
1613 if (ar.result == null) {
1614 loge("getSystemSelectionChannels: Empty response");
1615 } else {
1616 loge("getSystemSelectionChannels: Unknown exception");
1617 }
1618 }
1619 notifyRequester(request);
1620 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001621 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1622 ar = (AsyncResult) msg.obj;
1623 request = (MainThreadRequest) ar.userObj;
1624 if (ar.exception == null && ar.result != null) {
1625 request.result = ar.result;
1626 } else {
1627 request.result = -1;
1628 loge("Failed to set Forbidden Plmns");
1629 if (ar.result == null) {
1630 loge("setForbidenPlmns: Empty response");
1631 } else if (ar.exception != null) {
1632 loge("setForbiddenPlmns: Exception: " + ar.exception);
1633 request.result = -1;
1634 } else {
1635 loge("setForbiddenPlmns: Unknown exception");
1636 }
1637 }
1638 notifyRequester(request);
1639 break;
1640 case CMD_SET_FORBIDDEN_PLMNS:
1641 request = (MainThreadRequest) msg.obj;
1642 uiccCard = getUiccCardFromRequest(request);
1643 if (uiccCard == null) {
1644 loge("setForbiddenPlmns: UiccCard is null");
1645 request.result = -1;
1646 notifyRequester(request);
1647 break;
1648 }
1649 Pair<Integer, List<String>> setFplmnsArgs =
1650 (Pair<Integer, List<String>>) request.argument;
1651 appType = setFplmnsArgs.first;
1652 List<String> fplmns = setFplmnsArgs.second;
1653 uiccApp = uiccCard.getApplicationByType(appType);
1654 if (uiccApp == null) {
1655 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1656 request.result = -1;
1657 loge("Failed to get UICC App");
1658 notifyRequester(request);
1659 } else {
1660 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1661 ((SIMRecords) uiccApp.getIccRecords())
1662 .setForbiddenPlmns(onCompleted, fplmns);
1663 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001664 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001665 case CMD_ERASE_MODEM_CONFIG:
1666 request = (MainThreadRequest) msg.obj;
1667 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1668 defaultPhone.eraseModemConfig(onCompleted);
1669 break;
1670 case EVENT_ERASE_MODEM_CONFIG_DONE:
1671 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001672 break;
zoey chenf95ca592019-12-30 16:11:23 +08001673
1674 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1677 Pair<String, String> changed = (Pair<String, String>) request.argument;
1678 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1679 changed.first, changed.second, onCompleted);
1680 break;
1681 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 if (ar.exception == null) {
1685 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001686 // If the operation is successful, update the PIN storage
1687 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1688 int phoneId = getPhoneFromRequest(request).getPhoneId();
1689 UiccController.getInstance().getPinStorage()
1690 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001691 } else {
1692 request.result = msg.arg1;
1693 }
1694 notifyRequester(request);
1695 break;
1696
Michele Berionned9fbae52020-11-13 02:36:59 +00001697 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001698 request = (MainThreadRequest) msg.obj;
1699 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1700 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1701 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1702 enabled.first, enabled.second, onCompleted);
1703 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001704 }
zoey chenf95ca592019-12-30 16:11:23 +08001705 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1706 ar = (AsyncResult) msg.obj;
1707 request = (MainThreadRequest) ar.userObj;
1708 if (ar.exception == null) {
1709 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001710 // If the operation is successful, update the PIN storage
1711 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1712 int phoneId = getPhoneFromRequest(request).getPhoneId();
1713 if (enabled.first) {
1714 UiccController.getInstance().getPinStorage()
1715 .storePin(enabled.second, phoneId);
1716 } else {
1717 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1718 }
zoey chenf95ca592019-12-30 16:11:23 +08001719 } else {
1720 request.result = msg.arg1;
1721 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001722
1723
zoey chenf95ca592019-12-30 16:11:23 +08001724 notifyRequester(request);
1725 break;
1726
Peter Wangdafb9ac2020-01-15 14:13:38 -08001727 case MSG_NOTIFY_USER_ACTIVITY:
1728 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001729 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001730 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1731 getDefaultPhone().getContext().sendBroadcastAsUser(
1732 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1733 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001734
1735 case CMD_SET_DATA_THROTTLING: {
1736 request = (MainThreadRequest) msg.obj;
1737 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1738 DataThrottlingRequest dataThrottlingRequest =
1739 (DataThrottlingRequest) request.argument;
1740 Phone phone = getPhoneFromRequest(request);
1741 if (phone != null) {
1742 phone.setDataThrottling(onCompleted,
1743 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1744 dataThrottlingRequest.getCompletionDurationMillis());
1745 } else {
1746 loge("setDataThrottling: No phone object");
1747 request.result =
1748 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1749 notifyRequester(request);
1750 }
1751
1752 break;
1753 }
1754 case EVENT_SET_DATA_THROTTLING_DONE:
1755 ar = (AsyncResult) msg.obj;
1756 request = (MainThreadRequest) ar.userObj;
1757
1758 if (ar.exception == null) {
1759 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1760 } else if (ar.exception instanceof CommandException) {
1761 loge("setDataThrottling: CommandException: " + ar.exception);
1762 CommandException.Error error =
1763 ((CommandException) (ar.exception)).getCommandError();
1764
1765 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1766 request.result = TelephonyManager
1767 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1768 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1769 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1770 } else {
1771 request.result =
1772 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1773 }
1774 } else {
1775 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1776 }
1777 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1778 notifyRequester(request);
1779 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001780
1781 case CMD_SET_SIM_POWER: {
1782 request = (MainThreadRequest) msg.obj;
1783 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1784 request = (MainThreadRequest) msg.obj;
1785 int stateToSet =
1786 ((Pair<Integer, IIntegerConsumer>)
1787 request.argument).first;
1788 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1789 break;
1790 }
1791 case EVENT_SET_SIM_POWER_DONE: {
1792 ar = (AsyncResult) msg.obj;
1793 request = (MainThreadRequest) ar.userObj;
1794 IIntegerConsumer callback =
1795 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1796 if (ar.exception != null) {
1797 loge("setSimPower exception: " + ar.exception);
1798 int errorCode = TelephonyManager.CallForwardingInfoCallback
1799 .RESULT_ERROR_UNKNOWN;
1800 if (ar.exception instanceof CommandException) {
1801 CommandException.Error error =
1802 ((CommandException) (ar.exception)).getCommandError();
1803 if (error == CommandException.Error.SIM_ERR) {
1804 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1805 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1806 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1807 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1808 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1809 } else {
1810 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1811 }
1812 }
1813 try {
1814 callback.accept(errorCode);
1815 } catch (RemoteException e) {
1816 // Ignore if the remote process is no longer available to call back.
1817 Log.w(LOG_TAG, "setSimPower: callback not available.");
1818 }
1819 } else {
1820 try {
1821 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1822 } catch (RemoteException e) {
1823 // Ignore if the remote process is no longer available to call back.
1824 Log.w(LOG_TAG, "setSimPower: callback not available.");
1825 }
1826 }
1827 break;
1828 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001829 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1830 request = (MainThreadRequest) msg.obj;
1831
1832 final Phone phone = getPhoneFromRequest(request);
1833 if (phone == null || phone.getServiceStateTracker() == null) {
1834 request.result = new IllegalStateException("Phone or SST is null");
1835 notifyRequester(request);
1836 break;
1837 }
1838
1839 Pair<Integer, SignalStrengthUpdateRequest> pair =
1840 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1841 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1842 request);
1843 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1844 request.subId, pair.first /*callingUid*/,
1845 pair.second /*request*/, onCompleted);
1846 break;
1847 }
1848 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1849 ar = (AsyncResult) msg.obj;
1850 request = (MainThreadRequest) ar.userObj;
1851 // request.result will be the exception of ar if present, true otherwise.
1852 // Be cautious not to leave result null which will wait() forever
1853 request.result = ar.exception != null ? ar.exception : true;
1854 notifyRequester(request);
1855 break;
1856 }
1857 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1858 request = (MainThreadRequest) msg.obj;
1859
1860 Phone phone = getPhoneFromRequest(request);
1861 if (phone == null || phone.getServiceStateTracker() == null) {
1862 request.result = new IllegalStateException("Phone or SST is null");
1863 notifyRequester(request);
1864 break;
1865 }
1866
1867 Pair<Integer, SignalStrengthUpdateRequest> pair =
1868 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1869 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1870 request);
1871 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1872 request.subId, pair.first /*callingUid*/,
1873 pair.second /*request*/, onCompleted);
1874 break;
1875 }
1876 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1877 ar = (AsyncResult) msg.obj;
1878 request = (MainThreadRequest) ar.userObj;
1879 request.result = ar.exception != null ? ar.exception : true;
1880 notifyRequester(request);
1881 break;
1882 }
Jordan Liud5366d92020-11-24 14:50:34 -08001883
Michele Berionned9fbae52020-11-13 02:36:59 +00001884 case CMD_PREPARE_UNATTENDED_REBOOT:
1885 request = (MainThreadRequest) msg.obj;
1886 request.result =
1887 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1888 notifyRequester(request);
1889 break;
1890
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001891 default:
1892 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1893 break;
1894 }
1895 }
Jake Hambye994d462014-02-03 13:10:13 -08001896
Pengquan Menga1bb6272018-09-06 09:59:22 -07001897 private void notifyRequester(MainThreadRequest request) {
1898 synchronized (request) {
1899 request.notifyAll();
1900 }
1901 }
1902
Jake Hambye994d462014-02-03 13:10:13 -08001903 private void handleNullReturnEvent(Message msg, String command) {
1904 AsyncResult ar = (AsyncResult) msg.obj;
1905 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1906 if (ar.exception == null) {
1907 request.result = true;
1908 } else {
1909 request.result = false;
1910 if (ar.exception instanceof CommandException) {
1911 loge(command + ": CommandException: " + ar.exception);
1912 } else {
1913 loge(command + ": Unknown exception");
1914 }
1915 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001916 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001917 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001918 }
1919
1920 /**
1921 * Posts the specified command to be executed on the main thread,
1922 * waits for the request to complete, and returns the result.
1923 * @see #sendRequestAsync
1924 */
1925 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001926 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1927 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001928 }
1929
1930 /**
1931 * Posts the specified command to be executed on the main thread,
1932 * waits for the request to complete, and returns the result.
1933 * @see #sendRequestAsync
1934 */
1935 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1936 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001937 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001938 }
1939
1940 /**
1941 * Posts the specified command to be executed on the main thread,
1942 * waits for the request to complete, and returns the result.
1943 * @see #sendRequestAsync
1944 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001945 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001946 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1947 }
1948
1949 /**
1950 * Posts the specified command to be executed on the main thread,
1951 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1952 * if not timeout or null otherwise.
1953 * @see #sendRequestAsync
1954 */
1955 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1956 long timeoutInMs) {
1957 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001958 }
1959
1960 /**
1961 * Posts the specified command to be executed on the main thread,
1962 * waits for the request to complete, and returns the result.
1963 * @see #sendRequestAsync
1964 */
Nathan Harold92bed182018-10-12 18:16:49 -07001965 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001966 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001967 }
1968
1969 /**
1970 * Posts the specified command to be executed on the main thread,
1971 * waits for the request to complete, and returns the result.
1972 * @see #sendRequestAsync
1973 */
1974 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001975 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1976 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001977 }
1978
1979 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001980 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1981 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1982 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001983 * @see #sendRequestAsync
1984 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001985 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1986 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001987 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1988 throw new RuntimeException("This method will deadlock if called from the main thread.");
1989 }
1990
Nathan Harold92bed182018-10-12 18:16:49 -07001991 MainThreadRequest request = null;
1992 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1993 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1994 } else if (phone != null) {
1995 request = new MainThreadRequest(argument, phone, workSource);
1996 } else {
1997 request = new MainThreadRequest(argument, subId, workSource);
1998 }
1999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 Message msg = mMainThreadHandler.obtainMessage(command, request);
2001 msg.sendToTarget();
2002
Rambo Wang0f050d82021-02-12 11:43:36 -08002003
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002004 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002005 if (timeoutInMs >= 0) {
2006 // Wait for at least timeoutInMs before returning null request result
2007 long now = SystemClock.elapsedRealtime();
2008 long deadline = now + timeoutInMs;
2009 while (request == null && now < deadline) {
2010 try {
2011 request.wait(deadline - now);
2012 } catch (InterruptedException e) {
2013 // Do nothing, go back and check if request is completed or timeout
2014 } finally {
2015 now = SystemClock.elapsedRealtime();
2016 }
2017 }
2018 } else {
2019 // Wait for the request to complete
2020 while (request.result == null) {
2021 try {
2022 request.wait();
2023 } catch (InterruptedException e) {
2024 // Do nothing, go back and wait until the request is complete
2025 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002026 }
2027 }
2028 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002029 if (request.result == null) {
2030 Log.wtf(LOG_TAG,
2031 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 return request.result;
2034 }
2035
2036 /**
2037 * Asynchronous ("fire and forget") version of sendRequest():
2038 * Posts the specified command to be executed on the main thread, and
2039 * returns immediately.
2040 * @see #sendRequest
2041 */
2042 private void sendRequestAsync(int command) {
2043 mMainThreadHandler.sendEmptyMessage(command);
2044 }
2045
2046 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002047 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002048 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002049 */
2050 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002051 sendRequestAsync(command, argument, null, null);
2052 }
2053
2054 /**
2055 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2056 * @see {@link #sendRequest(int,Object)}
2057 */
2058 private void sendRequestAsync(
2059 int command, Object argument, Phone phone, WorkSource workSource) {
2060 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002061 Message msg = mMainThreadHandler.obtainMessage(command, request);
2062 msg.sendToTarget();
2063 }
2064
2065 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 * Initialize the singleton PhoneInterfaceManager instance.
2067 * This is only done once, at startup, from PhoneApp.onCreate().
2068 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002069 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002070 synchronized (PhoneInterfaceManager.class) {
2071 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002072 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 } else {
2074 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2075 }
2076 return sInstance;
2077 }
2078 }
2079
2080 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002081 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002082 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002084 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002085 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002086 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2087 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002088 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002089 mTelephonySharedPreferences =
2090 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002091 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002092 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002093 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002094
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002095 publish();
2096 }
2097
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002098 private Phone getDefaultPhone() {
2099 Phone thePhone = getPhone(getDefaultSubscription());
2100 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2101 }
2102
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002103 private void publish() {
2104 if (DBG) log("publish: " + this);
2105
Peter Wangc035ce42020-01-08 21:00:22 -08002106 TelephonyFrameworkInitializer
2107 .getTelephonyServiceManager()
2108 .getTelephonyServiceRegisterer()
2109 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002110 }
2111
Stuart Scott584921c2015-01-15 17:10:34 -08002112 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002113 if (request.phone != null) {
2114 return request.phone;
2115 } else {
2116 return getPhoneFromSubId(request.subId);
2117 }
2118 }
2119
2120 private Phone getPhoneFromSubId(int subId) {
2121 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2122 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002123 }
2124
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002125 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2126 Phone phone = getPhoneFromRequest(request);
2127 return phone == null ? null :
2128 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2129 }
2130
Wink Saville36469e72014-06-11 15:17:00 -07002131 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002132 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002133 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002134 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002136 private void sendEraseModemConfig(Phone phone) {
2137 if (phone != null) {
2138 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2139 mApp, phone.getSubId(), "eraseModemConfig");
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2143 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2144 } finally {
2145 Binder.restoreCallingIdentity(identity);
2146 }
2147 }
2148 }
2149
Peter Wang050bb052020-01-13 23:33:09 -08002150 private boolean isImsAvailableOnDevice() {
2151 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2152 if (pm == null) {
2153 // For some reason package manger is not available.. This will fail internally anyway,
2154 // so do not throw error and allow.
2155 return true;
2156 }
2157 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2158 }
2159
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002160 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002161 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002162 }
2163
Wink Savilleb564aae2014-10-23 10:18:09 -07002164 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 if (DBG) log("dial: " + number);
2166 // No permission check needed here: This is just a wrapper around the
2167 // ACTION_DIAL intent, which is available to any app since it puts up
2168 // the UI before it does anything.
2169
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 String url = createTelUrl(number);
2173 if (url == null) {
2174 return;
2175 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002176
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002177 // PENDING: should we just silently fail if phone is offhook or ringing?
2178 PhoneConstants.State state = mCM.getState(subId);
2179 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2180 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2181 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2182 mApp.startActivity(intent);
2183 }
2184 } finally {
2185 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002186 }
2187 }
2188
2189 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002190 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002191 }
2192
Wink Savilleb564aae2014-10-23 10:18:09 -07002193 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002194 if (DBG) log("call: " + number);
2195
2196 // This is just a wrapper around the ACTION_CALL intent, but we still
2197 // need to do a permission check since we're calling startActivity()
2198 // from the context of the phone app.
2199 enforceCallPermission();
2200
Jordan Liu1617b712019-07-10 15:06:26 -07002201 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002202 != AppOpsManager.MODE_ALLOWED) {
2203 return;
2204 }
2205
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002206 final long identity = Binder.clearCallingIdentity();
2207 try {
2208 String url = createTelUrl(number);
2209 if (url == null) {
2210 return;
2211 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213 boolean isValid = false;
2214 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2215 if (slist != null) {
2216 for (SubscriptionInfo subInfoRecord : slist) {
2217 if (subInfoRecord.getSubscriptionId() == subId) {
2218 isValid = true;
2219 break;
2220 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002221 }
Wink Saville08874612014-08-31 19:19:58 -07002222 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002223 if (!isValid) {
2224 return;
2225 }
Wink Saville08874612014-08-31 19:19:58 -07002226
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2228 intent.putExtra(SUBSCRIPTION_KEY, subId);
2229 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2230 mApp.startActivity(intent);
2231 } finally {
2232 Binder.restoreCallingIdentity(identity);
2233 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002234 }
2235
Wink Savilleb564aae2014-10-23 10:18:09 -07002236 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002237 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002238 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2239 }
2240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002242 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002243 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002247 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002248
2249 final long identity = Binder.clearCallingIdentity();
2250 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002251 Phone phone = getPhone(subId);
2252 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253 checkSimPin.start();
2254 return checkSimPin.unlockSim(null, pin);
2255 } finally {
2256 Binder.restoreCallingIdentity(identity);
2257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002258 }
2259
Wink Savilleb564aae2014-10-23 10:18:09 -07002260 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002261 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262
2263 final long identity = Binder.clearCallingIdentity();
2264 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002265 Phone phone = getPhone(subId);
2266 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267 checkSimPuk.start();
2268 return checkSimPuk.unlockSim(puk, pin);
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
2271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
2274 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002275 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002276 * a synchronous one.
2277 */
2278 private static class UnlockSim extends Thread {
2279
2280 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002281 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002282
2283 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002284 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2285 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002286
2287 // For replies from SimCard interface
2288 private Handler mHandler;
2289
2290 // For async handler to identify request type
2291 private static final int SUPPLY_PIN_COMPLETE = 100;
2292
Michele Berionned9fbae52020-11-13 02:36:59 +00002293 UnlockSim(int phoneId, IccCard simCard) {
2294 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002295 mSimCard = simCard;
2296 }
2297
2298 @Override
2299 public void run() {
2300 Looper.prepare();
2301 synchronized (UnlockSim.this) {
2302 mHandler = new Handler() {
2303 @Override
2304 public void handleMessage(Message msg) {
2305 AsyncResult ar = (AsyncResult) msg.obj;
2306 switch (msg.what) {
2307 case SUPPLY_PIN_COMPLETE:
2308 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2309 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002310 mRetryCount = msg.arg1;
2311 if (ar.exception != null) {
2312 if (ar.exception instanceof CommandException &&
2313 ((CommandException)(ar.exception)).getCommandError()
2314 == CommandException.Error.PASSWORD_INCORRECT) {
2315 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002316 } //When UiccCardApp dispose,handle message and return exception
2317 else if (ar.exception instanceof CommandException &&
2318 ((CommandException) (ar.exception)).getCommandError()
2319 == CommandException.Error.ABORTED) {
2320 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002321 } else {
2322 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2323 }
2324 } else {
2325 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002327 mDone = true;
2328 UnlockSim.this.notifyAll();
2329 }
2330 break;
2331 }
2332 }
2333 };
2334 UnlockSim.this.notifyAll();
2335 }
2336 Looper.loop();
2337 }
2338
2339 /*
2340 * Use PIN or PUK to unlock SIM card
2341 *
2342 * If PUK is null, unlock SIM card with PIN
2343 *
2344 * If PUK is not null, unlock SIM card with PUK and set PIN code
2345 */
Wink Saville9de0f752013-10-22 19:04:03 -07002346 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347
2348 while (mHandler == null) {
2349 try {
2350 wait();
2351 } catch (InterruptedException e) {
2352 Thread.currentThread().interrupt();
2353 }
2354 }
2355 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2356
2357 if (puk == null) {
2358 mSimCard.supplyPin(pin, callback);
2359 } else {
2360 mSimCard.supplyPuk(puk, pin, callback);
2361 }
2362
2363 while (!mDone) {
2364 try {
2365 Log.d(LOG_TAG, "wait for done");
2366 wait();
2367 } catch (InterruptedException e) {
2368 // Restore the interrupted status
2369 Thread.currentThread().interrupt();
2370 }
2371 }
2372 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002373 int[] resultArray = new int[2];
2374 resultArray[0] = mResult;
2375 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002376
2377 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2378 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2379 }
2380
Wink Saville9de0f752013-10-22 19:04:03 -07002381 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383 }
2384
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002385 /**
2386 * This method has been removed due to privacy and stability concerns.
2387 */
2388 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002390 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2391 return;
Wink Saville36469e72014-06-11 15:17:00 -07002392 }
2393
Nathan Harold1f889d82020-06-04 17:05:26 -07002394 @Override
2395 public void updateServiceLocationWithPackageName(String callingPackage) {
2396 mApp.getSystemService(AppOpsManager.class)
2397 .checkPackage(Binder.getCallingUid(), callingPackage);
2398
Nathan Haroldf096d982020-11-18 17:18:06 -08002399 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002400 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2401 // Callers targeting S have no business invoking this method.
2402 return;
2403 }
2404
2405 LocationAccessPolicy.LocationPermissionResult locationResult =
2406 LocationAccessPolicy.checkLocationPermission(mApp,
2407 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2408 .setCallingPackage(callingPackage)
2409 .setCallingFeatureId(null)
2410 .setCallingPid(Binder.getCallingPid())
2411 .setCallingUid(Binder.getCallingUid())
2412 .setMethod("updateServiceLocation")
2413 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2414 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2415 .build());
2416 // Apps that lack location permission have no business calling this method;
2417 // however, because no permission was declared in the public API, denials must
2418 // all be "soft".
2419 switch (locationResult) {
2420 case DENIED_HARD: /* fall through */
2421 case DENIED_SOFT:
2422 return;
2423 }
2424
2425 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002426 final long identity = Binder.clearCallingIdentity();
2427 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002428 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002429 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002430 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 }
2432 } finally {
2433 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435 }
2436
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002437 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002438 @Override
2439 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002440 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002441 }
2442
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002443
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002444 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002445 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2446 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2447 callingFeatureId);
2448 }
2449
2450 @Deprecated
2451 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002452 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002453 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2454 }
2455
2456 @Override
2457 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2458 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002459 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002460 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002461 return false;
2462 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002463
2464 final long identity = Binder.clearCallingIdentity();
2465 try {
2466 return isRadioOnForSubscriber(subId);
2467 } finally {
2468 Binder.restoreCallingIdentity(identity);
2469 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002470 }
2471
2472 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002473 final long identity = Binder.clearCallingIdentity();
2474 try {
2475 final Phone phone = getPhone(subId);
2476 if (phone != null) {
2477 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2478 } else {
2479 return false;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
2486 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002487 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 }
Wink Saville36469e72014-06-11 15:17:00 -07002489
Wink Savilleb564aae2014-10-23 10:18:09 -07002490 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002491 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492
2493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 final Phone phone = getPhone(subId);
2496 if (phone != null) {
2497 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2498 }
2499 } finally {
2500 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002501 }
Wink Saville36469e72014-06-11 15:17:00 -07002502 }
2503
2504 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002505 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002506 }
2507
Wink Savilleb564aae2014-10-23 10:18:09 -07002508 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002509 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002510
2511 final long identity = Binder.clearCallingIdentity();
2512 try {
2513 final Phone phone = getPhone(subId);
2514 if (phone == null) {
2515 return false;
2516 }
2517 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2518 toggleRadioOnOffForSubscriber(subId);
2519 }
2520 return true;
2521 } finally {
2522 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002524 }
Wink Saville36469e72014-06-11 15:17:00 -07002525
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002526 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002527 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002528 /*
2529 * If any of the Radios are available, it will need to be
2530 * shutdown. So return true if any Radio is available.
2531 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002532 final long identity = Binder.clearCallingIdentity();
2533 try {
2534 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2535 Phone phone = PhoneFactory.getPhone(i);
2536 if (phone != null && phone.isRadioAvailable()) return true;
2537 }
2538 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2539 return false;
2540 } finally {
2541 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002542 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 }
2544
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002546 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547 enforceModifyPermission();
2548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2552 logv("Shutting down Phone " + i);
2553 shutdownRadioUsingPhoneId(i);
2554 }
2555 } finally {
2556 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002557 }
2558 }
2559
2560 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002561 Phone phone = PhoneFactory.getPhone(phoneId);
2562 if (phone != null && phone.isRadioAvailable()) {
2563 phone.shutdownRadio();
2564 }
2565 }
2566
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002567 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002568 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002569
2570 final long identity = Binder.clearCallingIdentity();
2571 try {
2572 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2573 if (defaultPhone != null) {
2574 defaultPhone.setRadioPower(turnOn);
2575 return true;
2576 } else {
2577 loge("There's no default phone.");
2578 return false;
2579 }
2580 } finally {
2581 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002582 }
Wink Saville36469e72014-06-11 15:17:00 -07002583 }
2584
Wink Savilleb564aae2014-10-23 10:18:09 -07002585 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 final Phone phone = getPhone(subId);
2591 if (phone != null) {
2592 phone.setRadioPower(turnOn);
2593 return true;
2594 } else {
2595 return false;
2596 }
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002599 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002600 }
2601
Wink Saville36469e72014-06-11 15:17:00 -07002602 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002603 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002604 public boolean enableDataConnectivity() {
2605 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002606
2607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 int subId = mSubscriptionController.getDefaultDataSubId();
2610 final Phone phone = getPhone(subId);
2611 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002612 phone.getDataEnabledSettings().setDataEnabled(
2613 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002614 return true;
2615 } else {
2616 return false;
2617 }
2618 } finally {
2619 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002620 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002621 }
2622
Wink Saville36469e72014-06-11 15:17:00 -07002623 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002624 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002625 public boolean disableDataConnectivity() {
2626 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002627
2628 final long identity = Binder.clearCallingIdentity();
2629 try {
2630 int subId = mSubscriptionController.getDefaultDataSubId();
2631 final Phone phone = getPhone(subId);
2632 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002633 phone.getDataEnabledSettings().setDataEnabled(
2634 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002635 return true;
2636 } else {
2637 return false;
2638 }
2639 } finally {
2640 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002641 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002642 }
2643
Sanket Padawe356d7632015-06-22 14:03:32 -07002644 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002645 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646 final long identity = Binder.clearCallingIdentity();
2647 try {
2648 final Phone phone = getPhone(subId);
2649 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002650 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 } else {
2652 return false;
2653 }
2654 } finally {
2655 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002656 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002657 }
2658
2659 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002660 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002661 }
2662
pkanwarae03a6b2016-11-06 20:37:09 -08002663 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002664 enforceCallPermission();
2665
2666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2669 return;
2670 }
2671 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2672 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2673 } finally {
2674 Binder.restoreCallingIdentity(identity);
2675 }
pkanwar32d516d2016-10-14 19:37:38 -07002676 };
2677
Wink Savilleb564aae2014-10-23 10:18:09 -07002678 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002680
2681 final long identity = Binder.clearCallingIdentity();
2682 try {
2683 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2684 return false;
2685 }
2686 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2687 } finally {
2688 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002690 }
2691
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002692 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002693 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002694 }
2695
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002696 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002697 final long identity = Binder.clearCallingIdentity();
2698 try {
2699 Phone phone = PhoneFactory.getPhone(slotIndex);
2700 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2701 PhoneConstantConversions.convertCallState(phone.getState());
2702 } finally {
2703 Binder.restoreCallingIdentity(identity);
2704 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002705 }
2706
Sanket Padawe356d7632015-06-22 14:03:32 -07002707 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002708 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002709 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2710 }
2711
2712 @Override
2713 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002714 final long identity = Binder.clearCallingIdentity();
2715 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002716 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002717 if (phone != null) {
2718 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2719 } else {
2720 return PhoneConstantConversions.convertDataState(
2721 PhoneConstants.DataState.DISCONNECTED);
2722 }
2723 } finally {
2724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
Sanket Padawe356d7632015-06-22 14:03:32 -07002728 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002729 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002730 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2731 }
2732
2733 @Override
2734 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002735 final long identity = Binder.clearCallingIdentity();
2736 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002737 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002738 if (phone != null) {
2739 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2740 } else {
2741 return TelephonyManager.DATA_ACTIVITY_NONE;
2742 }
2743 } finally {
2744 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002745 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 }
2747
2748 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002749 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002750 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002751 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002752
2753 LocationAccessPolicy.LocationPermissionResult locationResult =
2754 LocationAccessPolicy.checkLocationPermission(mApp,
2755 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2756 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002757 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002758 .setCallingPid(Binder.getCallingPid())
2759 .setCallingUid(Binder.getCallingUid())
2760 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002761 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002762 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2763 .build());
2764 switch (locationResult) {
2765 case DENIED_HARD:
2766 throw new SecurityException("Not allowed to access cell location");
2767 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002768 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2769 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002770 }
2771
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002772 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 final long identity = Binder.clearCallingIdentity();
2774 try {
2775 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002776 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002777 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 } finally {
2779 Binder.restoreCallingIdentity(identity);
2780 }
Svetoslav64fad262015-04-14 14:35:21 -07002781 }
2782
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 @Override
Jack Yu01425032020-02-22 19:38:58 -08002784 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002785 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2786 // registered cell info, so return a NULL country instead.
2787 final long identity = Binder.clearCallingIdentity();
2788 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002789 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2790 // Get default phone in this case.
2791 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2792 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002793 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002794 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002795 if (phone == null) return "";
2796 ServiceStateTracker sst = phone.getServiceStateTracker();
2797 if (sst == null) return "";
2798 LocaleTracker lt = sst.getLocaleTracker();
2799 if (lt == null) return "";
2800 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2801 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2802 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002803 } finally {
2804 Binder.restoreCallingIdentity(identity);
2805 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002806 }
2807
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002808 /**
2809 * This method was removed due to potential issues caused by performing partial
2810 * updates of service state, and lack of a credible use case.
2811 *
2812 * This has the ability to break the telephony implementation by disabling notification of
2813 * changes in device connectivity. DO NOT USE THIS!
2814 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002815 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002816 public void enableLocationUpdates() {
2817 mApp.enforceCallingOrSelfPermission(
2818 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002819 }
2820
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002821 /**
2822 * This method was removed due to potential issues caused by performing partial
2823 * updates of service state, and lack of a credible use case.
2824 *
2825 * This has the ability to break the telephony implementation by disabling notification of
2826 * changes in device connectivity. DO NOT USE THIS!
2827 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 @Override
2829 public void disableLocationUpdates() {
2830 mApp.enforceCallingOrSelfPermission(
2831 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002832 }
2833
2834 @Override
2835 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002836 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2837 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002838 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002839 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2840 throw new SecurityException(
2841 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2842 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002843
Jordan Liu1617b712019-07-10 15:06:26 -07002844 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2846 return null;
2847 }
Svetoslav64fad262015-04-14 14:35:21 -07002848
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002849 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002851 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002852 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002853
Nathan Haroldf180aac2018-06-01 18:43:55 -07002854 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2855 for (CellInfo ci : info) {
2856 if (ci instanceof CellInfoGsm) {
2857 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2858 } else if (ci instanceof CellInfoWcdma) {
2859 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002862 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002863 }
2864
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002865 private List<CellInfo> getCachedCellInfo() {
2866 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2867 for (Phone phone : PhoneFactory.getPhones()) {
2868 List<CellInfo> info = phone.getAllCellInfo();
2869 if (info != null) cellInfos.addAll(info);
2870 }
2871 return cellInfos;
2872 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002873
2874 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002875 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002876 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002877 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002878
2879 LocationAccessPolicy.LocationPermissionResult locationResult =
2880 LocationAccessPolicy.checkLocationPermission(mApp,
2881 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2882 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002883 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002884 .setCallingPid(Binder.getCallingPid())
2885 .setCallingUid(Binder.getCallingUid())
2886 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002887 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002888 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2889 .build());
2890 switch (locationResult) {
2891 case DENIED_HARD:
2892 throw new SecurityException("Not allowed to access cell info");
2893 case DENIED_SOFT:
2894 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002895 }
2896
Nathan Haroldf096d982020-11-18 17:18:06 -08002897 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002898 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2899 return getCachedCellInfo();
2900 }
2901
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002902 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002903 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2907 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002908 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002909 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002910 if (info != null) cellInfos.addAll(info);
2911 }
2912 return cellInfos;
2913 } finally {
2914 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002915 }
2916 }
2917
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002918 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002919 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2920 String callingFeatureId) {
2921 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2922 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002923 }
2924
2925 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002926 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2927 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002928 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002929 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002930 }
2931
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002932 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2933 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002934 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002935 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002936
2937 LocationAccessPolicy.LocationPermissionResult locationResult =
2938 LocationAccessPolicy.checkLocationPermission(mApp,
2939 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2940 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002941 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002942 .setCallingPid(Binder.getCallingPid())
2943 .setCallingUid(Binder.getCallingUid())
2944 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002945 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2946 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002947 .build());
2948 switch (locationResult) {
2949 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002950 if (TelephonyPermissions
2951 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002952 // Safetynet logging for b/154934934
2953 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2954 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002955 throw new SecurityException("Not allowed to access cell info");
2956 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002957 if (TelephonyPermissions
2958 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002959 // Safetynet logging for b/154934934
2960 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2961 }
Nathan Harold5320c422019-05-09 10:26:08 -07002962 try {
2963 cb.onCellInfo(new ArrayList<CellInfo>());
2964 } catch (RemoteException re) {
2965 // Drop without consequences
2966 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002967 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002968 }
2969
Nathan Harolda939a962019-05-09 10:13:47 -07002970
2971 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002972 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2973
2974 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2975 }
2976
2977 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002978 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002979 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002980 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981
2982 final long identity = Binder.clearCallingIdentity();
2983 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002984 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985 } finally {
2986 Binder.restoreCallingIdentity(identity);
2987 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002988 }
2989
Shishir Agrawala9f32182016-04-12 12:00:16 -07002990 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002992 Phone phone = PhoneFactory.getPhone(slotIndex);
2993 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002994 return null;
2995 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002996 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002997 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002998 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002999 return null;
3000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
3002 final long identity = Binder.clearCallingIdentity();
3003 try {
3004 return phone.getImei();
3005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003008 }
3009
3010 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003011 public String getTypeAllocationCodeForSlot(int slotIndex) {
3012 Phone phone = PhoneFactory.getPhone(slotIndex);
3013 String tac = null;
3014 if (phone != null) {
3015 String imei = phone.getImei();
3016 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3017 }
3018 return tac;
3019 }
3020
3021 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003022 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003023 Phone phone = PhoneFactory.getPhone(slotIndex);
3024 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003025 return null;
3026 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003027
Jeff Davidson913390f2018-02-23 17:11:49 -08003028 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003029 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003030 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003031 return null;
3032 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 return phone.getMeid();
3037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Jack Yu2af8d712017-03-15 17:14:14 -07003040 }
3041
3042 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003043 public String getManufacturerCodeForSlot(int slotIndex) {
3044 Phone phone = PhoneFactory.getPhone(slotIndex);
3045 String manufacturerCode = null;
3046 if (phone != null) {
3047 String meid = phone.getMeid();
3048 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3049 }
3050 return manufacturerCode;
3051 }
3052
3053 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003054 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3055 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003056 Phone phone = PhoneFactory.getPhone(slotIndex);
3057 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003058 return null;
3059 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003060 int subId = phone.getSubId();
3061 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003062 mApp, subId, callingPackage, callingFeatureId,
3063 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003064 return null;
3065 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066
3067 final long identity = Binder.clearCallingIdentity();
3068 try {
3069 return phone.getDeviceSvn();
3070 } finally {
3071 Binder.restoreCallingIdentity(identity);
3072 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003073 }
3074
fionaxu43304da2017-11-27 22:51:16 -08003075 @Override
3076 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 final long identity = Binder.clearCallingIdentity();
3078 try {
3079 final Phone phone = getPhone(subId);
3080 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3081 } finally {
3082 Binder.restoreCallingIdentity(identity);
3083 }
fionaxu43304da2017-11-27 22:51:16 -08003084 }
3085
3086 @Override
3087 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 final Phone phone = getPhone(subId);
3091 return phone == null ? null : phone.getCarrierName();
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
3094 }
fionaxu43304da2017-11-27 22:51:16 -08003095 }
3096
calvinpanffe225e2018-11-01 19:43:06 +08003097 @Override
chen xu0026ca62019-03-06 15:28:50 -08003098 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 final Phone phone = getPhone(subId);
3102 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003103 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003104 } finally {
3105 Binder.restoreCallingIdentity(identity);
3106 }
3107 }
3108
3109 @Override
chen xu0026ca62019-03-06 15:28:50 -08003110 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003114 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003115 } finally {
3116 Binder.restoreCallingIdentity(identity);
3117 }
3118 }
3119
chen xu651eec72018-11-11 19:03:44 -08003120 @Override
chen xu864e11c2018-12-06 22:10:03 -08003121 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3122 if (!isSubscriptionMccMnc) {
3123 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3124 }
chen xu651eec72018-11-11 19:03:44 -08003125 final Phone phone = PhoneFactory.getPhone(slotIndex);
3126 if (phone == null) {
3127 return TelephonyManager.UNKNOWN_CARRIER_ID;
3128 }
3129 final long identity = Binder.clearCallingIdentity();
3130 try {
3131 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3132 } finally {
3133 Binder.restoreCallingIdentity(identity);
3134 }
3135 }
3136
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003137 //
3138 // Internal helper methods.
3139 //
3140
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003141 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3143 *
3144 * @throws SecurityException if the caller does not have the required permission
3145 */
3146 private void enforceModifyPermission() {
3147 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3148 }
3149
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003150 /**
3151 * Make sure the caller is system.
3152 *
3153 * @throws SecurityException if the caller is not system.
3154 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003155 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003156 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3157 throw new SecurityException("Caller must be system");
3158 }
3159 }
3160
Shuo Qianf2b2df42019-11-13 17:43:31 -08003161 private void enforceActiveEmergencySessionPermission() {
3162 mApp.enforceCallingOrSelfPermission(
3163 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3164 }
3165
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003166 /**
3167 * Make sure the caller has the CALL_PHONE permission.
3168 *
3169 * @throws SecurityException if the caller does not have the required permission
3170 */
3171 private void enforceCallPermission() {
3172 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3173 }
3174
paulhu423b5f22019-08-23 19:17:33 +08003175 private void enforceSettingsPermission() {
3176 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003177 }
3178
Michele Berionned9fbae52020-11-13 02:36:59 +00003179 private void enforceRebootPermission() {
3180 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3181 }
3182
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003183 private String createTelUrl(String number) {
3184 if (TextUtils.isEmpty(number)) {
3185 return null;
3186 }
3187
Jake Hambye994d462014-02-03 13:10:13 -08003188 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003189 }
3190
Ihab Awadf9e92732013-12-05 18:02:52 -08003191 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003192 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3193 }
3194
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003195 private static void logv(String msg) {
3196 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3197 }
3198
Ihab Awadf9e92732013-12-05 18:02:52 -08003199 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3201 }
3202
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003203 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003204 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003205 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003206 }
3207
Sanket Padawe356d7632015-06-22 14:03:32 -07003208 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003209 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 final long identity = Binder.clearCallingIdentity();
3211 try {
3212 final Phone phone = PhoneFactory.getPhone(slotIndex);
3213 if (phone == null) {
3214 return PhoneConstants.PHONE_TYPE_NONE;
3215 } else {
3216 return phone.getPhoneType();
3217 }
3218 } finally {
3219 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003220 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003221 }
3222
3223 /**
3224 * Returns the CDMA ERI icon index to display
3225 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003226 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003227 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3228 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3229 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003230 }
3231
Sanket Padawe356d7632015-06-22 14:03:32 -07003232 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003233 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3234 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003235 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003236 mApp, subId, callingPackage, callingFeatureId,
3237 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003238 return -1;
3239 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003240
3241 final long identity = Binder.clearCallingIdentity();
3242 try {
3243 final Phone phone = getPhone(subId);
3244 if (phone != null) {
3245 return phone.getCdmaEriIconIndex();
3246 } else {
3247 return -1;
3248 }
3249 } finally {
3250 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003252 }
3253
3254 /**
3255 * Returns the CDMA ERI icon mode,
3256 * 0 - ON
3257 * 1 - FLASHING
3258 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003259 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003260 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3261 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3262 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003263 }
3264
Sanket Padawe356d7632015-06-22 14:03:32 -07003265 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003266 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3267 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003268 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003269 mApp, subId, callingPackage, callingFeatureId,
3270 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003271 return -1;
3272 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003273
3274 final long identity = Binder.clearCallingIdentity();
3275 try {
3276 final Phone phone = getPhone(subId);
3277 if (phone != null) {
3278 return phone.getCdmaEriIconMode();
3279 } else {
3280 return -1;
3281 }
3282 } finally {
3283 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003284 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003285 }
3286
3287 /**
3288 * Returns the CDMA ERI text,
3289 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003290 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003291 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3292 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3293 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003294 }
3295
Sanket Padawe356d7632015-06-22 14:03:32 -07003296 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003297 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3298 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003300 mApp, subId, callingPackage, callingFeatureId,
3301 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003302 return null;
3303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 if (phone != null) {
3309 return phone.getCdmaEriText();
3310 } else {
3311 return null;
3312 }
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003316 }
3317
3318 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003319 * Returns the CDMA MDN.
3320 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003321 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003322 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003323 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3324 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003325
3326 final long identity = Binder.clearCallingIdentity();
3327 try {
3328 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003329 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330 return phone.getLine1Number();
3331 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003332 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003333 return null;
3334 }
3335 } finally {
3336 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003337 }
3338 }
3339
3340 /**
3341 * Returns the CDMA MIN.
3342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003343 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003344 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3346 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003347
3348 final long identity = Binder.clearCallingIdentity();
3349 try {
3350 final Phone phone = getPhone(subId);
3351 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3352 return phone.getCdmaMin();
3353 } else {
3354 return null;
3355 }
3356 } finally {
3357 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003358 }
3359 }
3360
Hall Liud892bec2018-11-30 14:51:45 -08003361 @Override
3362 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3363 INumberVerificationCallback callback, String callingPackage) {
3364 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3365 != PERMISSION_GRANTED) {
3366 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3367 }
3368 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3369
3370 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3371 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003372 throw new SecurityException("Calling package must be configured in the device config: "
3373 + "calling package: " + callingPackage
3374 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003375 }
3376
3377 if (range == null) {
3378 throw new NullPointerException("Range must be non-null");
3379 }
3380
3381 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003382 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003383
3384 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3385 }
3386
Junda Liuca05d5d2014-08-14 22:36:34 -07003387 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003388 * Returns true if CDMA provisioning needs to run.
3389 */
3390 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003391 final long identity = Binder.clearCallingIdentity();
3392 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003394 } finally {
3395 Binder.restoreCallingIdentity(identity);
3396 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003397 }
3398
3399 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003400 * Sets the voice mail number of a given subId.
3401 */
3402 @Override
3403 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003404 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3405 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003406
3407 final long identity = Binder.clearCallingIdentity();
3408 try {
3409 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3410 new Pair<String, String>(alphaTag, number), new Integer(subId));
3411 return success;
3412 } finally {
3413 Binder.restoreCallingIdentity(identity);
3414 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003415 }
3416
Ta-wei Yen87c49842016-05-13 21:19:52 -07003417 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003418 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3419 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003420 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3421 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003422 if (!TextUtils.equals(callingPackage, systemDialer)) {
3423 throw new SecurityException("caller must be system dialer");
3424 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003425
3426 final long identity = Binder.clearCallingIdentity();
3427 try {
3428 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3429 if (phoneAccountHandle == null) {
3430 return null;
3431 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003432 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003433 } finally {
3434 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003435 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003436 }
3437
3438 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003439 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3440 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003441 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003442 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003443 mApp, subId, callingPackage, callingFeatureId,
3444 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003445 return null;
3446 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003448 final long identity = Binder.clearCallingIdentity();
3449 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003450 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003451 } finally {
3452 Binder.restoreCallingIdentity(identity);
3453 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003454 }
3455
3456 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003457 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3458 VisualVoicemailSmsFilterSettings settings) {
3459 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003460
3461 final long identity = Binder.clearCallingIdentity();
3462 try {
3463 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003464 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465 } finally {
3466 Binder.restoreCallingIdentity(identity);
3467 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003468 }
3469
3470 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003471 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3472 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003473
3474 final long identity = Binder.clearCallingIdentity();
3475 try {
3476 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003477 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478 } finally {
3479 Binder.restoreCallingIdentity(identity);
3480 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003481 }
3482
3483 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003484 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3485 String callingPackage, int subId) {
3486 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003487
3488 final long identity = Binder.clearCallingIdentity();
3489 try {
3490 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003491 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492 } finally {
3493 Binder.restoreCallingIdentity(identity);
3494 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003495 }
3496
3497 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003498 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003499 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003500
3501 final long identity = Binder.clearCallingIdentity();
3502 try {
3503 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003504 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505 } finally {
3506 Binder.restoreCallingIdentity(identity);
3507 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003508 }
3509
3510 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003511 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3512 String callingAttributionTag, int subId, String number, int port, String text,
3513 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003514 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003515 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003516 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003517 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003518 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3519 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003520 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003521
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003522 /**
fionaxu0152e512016-11-14 13:36:14 -08003523 * Sets the voice activation state of a given subId.
3524 */
3525 @Override
3526 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003527 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3528 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529
3530 final long identity = Binder.clearCallingIdentity();
3531 try {
3532 final Phone phone = getPhone(subId);
3533 if (phone != null) {
3534 phone.setVoiceActivationState(activationState);
3535 } else {
3536 loge("setVoiceActivationState fails with invalid subId: " + subId);
3537 }
3538 } finally {
3539 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003540 }
3541 }
3542
3543 /**
3544 * Sets the data activation state of a given subId.
3545 */
3546 @Override
3547 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3549 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003550
3551 final long identity = Binder.clearCallingIdentity();
3552 try {
3553 final Phone phone = getPhone(subId);
3554 if (phone != null) {
3555 phone.setDataActivationState(activationState);
3556 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003557 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003558 }
3559 } finally {
3560 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003561 }
3562 }
3563
3564 /**
3565 * Returns the voice activation state of a given subId.
3566 */
3567 @Override
3568 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003570
fionaxu0152e512016-11-14 13:36:14 -08003571 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 if (phone != null) {
3575 return phone.getVoiceActivationState();
3576 } else {
3577 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3578 }
3579 } finally {
3580 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003581 }
3582 }
3583
3584 /**
3585 * Returns the data activation state of a given subId.
3586 */
3587 @Override
3588 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003590
fionaxu0152e512016-11-14 13:36:14 -08003591 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 if (phone != null) {
3595 return phone.getDataActivationState();
3596 } else {
3597 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3598 }
3599 } finally {
3600 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003601 }
3602 }
3603
3604 /**
Wink Saville36469e72014-06-11 15:17:00 -07003605 * Returns the unread count of voicemails for a subId
3606 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003607 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003608 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3609 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003611 mApp, subId, callingPackage, callingFeatureId,
3612 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003613 return 0;
3614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615 final long identity = Binder.clearCallingIdentity();
3616 try {
3617 final Phone phone = getPhone(subId);
3618 if (phone != null) {
3619 return phone.getVoiceMessageCount();
3620 } else {
3621 return 0;
3622 }
3623 } finally {
3624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003626 }
3627
3628 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003629 * returns true, if the device is in a state where both voice and data
3630 * are supported simultaneously. This can change based on location or network condition.
3631 */
3632 @Override
3633 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003634 final long identity = Binder.clearCallingIdentity();
3635 try {
3636 final Phone phone = getPhone(subId);
3637 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3638 } finally {
3639 Binder.restoreCallingIdentity(identity);
3640 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003641 }
3642
3643 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003644 * Send the dialer code if called from the current default dialer or the caller has
3645 * carrier privilege.
3646 * @param inputCode The dialer code to send
3647 */
3648 @Override
3649 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003650 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003651 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003652 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3653 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003654 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003655 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003656 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003658
3659 final long identity = Binder.clearCallingIdentity();
3660 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003661 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
fionaxu235cc5e2017-03-06 22:25:57 -08003665 }
3666
Pengquan Menga1bb6272018-09-06 09:59:22 -07003667 @Override
3668 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003669 TelephonyPermissions
3670 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3671 mApp, subId, "getNetworkSelectionMode");
3672 final long identity = Binder.clearCallingIdentity();
3673 try {
3674 if (!isActiveSubscription(subId)) {
3675 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3676 }
3677 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3678 } finally {
3679 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003680 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003681 }
3682
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003684 public boolean isInEmergencySmsMode() {
3685 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3686 final long identity = Binder.clearCallingIdentity();
3687 try {
3688 for (Phone phone : PhoneFactory.getPhones()) {
3689 if (phone.isInEmergencySmsMode()) {
3690 return true;
3691 }
3692 }
3693 } finally {
3694 Binder.restoreCallingIdentity(identity);
3695 }
3696 return false;
3697 }
3698
shilu366312e2019-12-17 09:28:10 -08003699 /**
3700 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3701 * @param subId The subscription to use to check the configuration.
3702 * @param c The callback that will be used to send the result.
3703 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003704 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003705 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3706 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003707 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3708 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003709
Brad Ebinger77b832e2019-10-17 17:03:22 -07003710 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3712 "IMS not available on device.");
3713 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 final long token = Binder.clearCallingIdentity();
3715 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003716 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003717 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003718 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003719 } catch (ImsException e) {
3720 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003721 } finally {
3722 Binder.restoreCallingIdentity(token);
3723 }
3724 }
3725
shilu366312e2019-12-17 09:28:10 -08003726 /**
3727 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3728 * @param subId The subscription to use to check the configuration.
3729 * @param c The callback that will be used to send the result.
3730 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003732 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003733 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3734 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003735 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3736 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3737 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003738 final long token = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3742 .removeRegistrationCallbackForSubscription(c, subId);
3743 } catch (ImsException e) {
3744 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3745 + "is inactive, ignoring unregister.");
3746 // If the subscription is no longer active, just return, since the callback
3747 // will already have been removed internally.
3748 } finally {
3749 Binder.restoreCallingIdentity(token);
3750 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 }
3752
Brad Ebinger774ba362019-10-22 17:36:18 -07003753 /**
3754 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3755 */
3756 @Override
3757 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3758 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3759 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3760 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3761 "IMS not available on device.");
3762 }
3763 final long token = Binder.clearCallingIdentity();
3764 try {
3765 Phone phone = getPhone(subId);
3766 if (phone == null) {
3767 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3768 + subId + "'");
3769 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3770 }
3771 phone.getImsRegistrationState(regState -> {
3772 try {
3773 consumer.accept((regState == null)
3774 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3775 } catch (RemoteException e) {
3776 // Ignore if the remote process is no longer available to call back.
3777 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3778 }
3779 });
3780 } finally {
3781 Binder.restoreCallingIdentity(token);
3782 }
3783 }
3784
3785 /**
3786 * Get the transport type for the IMS service registration state.
3787 */
3788 @Override
3789 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003790 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3791 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003792 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3793 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3794 "IMS not available on device.");
3795 }
3796 final long token = Binder.clearCallingIdentity();
3797 try {
3798 Phone phone = getPhone(subId);
3799 if (phone == null) {
3800 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3801 + subId + "'");
3802 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3803 }
3804 phone.getImsRegistrationTech(regTech -> {
3805 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3806 int regTechConverted = (regTech == null)
3807 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3808 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3809 regTechConverted);
3810 try {
3811 consumer.accept(regTechConverted);
3812 } catch (RemoteException e) {
3813 // Ignore if the remote process is no longer available to call back.
3814 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3815 }
3816 });
3817 } finally {
3818 Binder.restoreCallingIdentity(token);
3819 }
3820 }
3821
shilu366312e2019-12-17 09:28:10 -08003822 /**
3823 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3824 * @param subId The subscription to use to check the configuration.
3825 * @param c The callback that will be used to send the result.
3826 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003827 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003828 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3829 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003830 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3831 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003832 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3833 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3834 "IMS not available on device.");
3835 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3837 final long token = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (ImsException e) {
3842 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003843 } finally {
3844 Binder.restoreCallingIdentity(token);
3845 }
3846 }
3847
shilu366312e2019-12-17 09:28:10 -08003848 /**
3849 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3850 * @param subId The subscription to use to check the configuration.
3851 * @param c The callback that will be used to send the result.
3852 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003853 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003854 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003855 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3856 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003857 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3858 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3859 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003860
3861 final long token = Binder.clearCallingIdentity();
3862 try {
3863 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3864 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003865 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003866 } catch (ImsException e) {
3867 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3868 + "is inactive, ignoring unregister.");
3869 // If the subscription is no longer active, just return, since the callback
3870 // will already have been removed internally.
3871 } finally {
3872 Binder.restoreCallingIdentity(token);
3873 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003874 }
3875
3876 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003877 public boolean isCapable(int subId, int capability, int regTech) {
3878 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3880 final long token = Binder.clearCallingIdentity();
3881 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003882 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003883 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003884 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3886 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003887 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003888 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3889 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 } finally {
3891 Binder.restoreCallingIdentity(token);
3892 }
3893 }
3894
3895 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003896 public boolean isAvailable(int subId, int capability, int regTech) {
3897 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003898 final long token = Binder.clearCallingIdentity();
3899 try {
3900 Phone phone = getPhone(subId);
3901 if (phone == null) return false;
3902 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003903 } catch (com.android.ims.ImsException e) {
3904 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3905 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003906 } finally {
3907 Binder.restoreCallingIdentity(token);
3908 }
3909 }
3910
Brad Ebinger77b832e2019-10-17 17:03:22 -07003911 /**
3912 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3913 * subscription.
3914 * @param subId The subscription to use to check the configuration.
3915 * @param callback The callback that will be used to send the result.
3916 * @param capability The MmTelFeature capability that will be used to send the result.
3917 * @param transportType The transport type of the MmTelFeature capability.
3918 */
3919 @Override
3920 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3921 int transportType) {
3922 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3923 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3924 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3925 "IMS not available on device.");
3926 }
3927 final long token = Binder.clearCallingIdentity();
3928 try {
3929 int slotId = getSlotIndex(subId);
3930 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3931 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3932 + subId + "'");
3933 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3934 }
3935 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3936 transportType, aBoolean -> {
3937 try {
3938 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3939 } catch (RemoteException e) {
3940 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3941 + "running. Ignore");
3942 }
3943 });
3944 } finally {
3945 Binder.restoreCallingIdentity(token);
3946 }
3947 }
3948
shilu366312e2019-12-17 09:28:10 -08003949 /**
3950 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3951 * @param subId The subscription to use to check the configuration.
3952 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003953 @Override
3954 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003955 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3956 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003957
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3959 final long token = Binder.clearCallingIdentity();
3960 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003961 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003962 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003963 } catch (ImsException e) {
3964 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003965 } finally {
3966 Binder.restoreCallingIdentity(token);
3967 }
3968 }
3969
3970 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003971 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003973 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003974 final long identity = Binder.clearCallingIdentity();
3975 try {
3976 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003977 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003978 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003979 } catch (ImsException e) {
3980 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 } finally {
3982 Binder.restoreCallingIdentity(identity);
3983 }
3984 }
3985
shilu366312e2019-12-17 09:28:10 -08003986 /**
3987 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3988 * @param subId The subscription to use to check the configuration.
3989 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003990 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003991 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003992 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3993 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003994 final long identity = Binder.clearCallingIdentity();
3995 try {
3996 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003997 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3998 } catch (ImsException e) {
3999 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004000 } finally {
4001 Binder.restoreCallingIdentity(identity);
4002 }
4003 }
4004
4005 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004006 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004008 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004009 final long identity = Binder.clearCallingIdentity();
4010 try {
4011 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004012 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004013 } catch (ImsException e) {
4014 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004015 } finally {
4016 Binder.restoreCallingIdentity(identity);
4017 }
4018 }
4019
shilu366312e2019-12-17 09:28:10 -08004020 /**
4021 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4022 * @param subId The subscription to use to check the configuration.
4023 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 @Override
4025 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004026 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4027 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004028 final long identity = Binder.clearCallingIdentity();
4029 try {
4030 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004031 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004032 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004033 } catch (ImsException e) {
4034 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004035 } finally {
4036 Binder.restoreCallingIdentity(identity);
4037 }
4038 }
4039
4040 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004041 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004043 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004044 final long identity = Binder.clearCallingIdentity();
4045 try {
4046 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004047 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004048 } catch (ImsException e) {
4049 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 } finally {
4051 Binder.restoreCallingIdentity(identity);
4052 }
4053 }
4054
shilu366312e2019-12-17 09:28:10 -08004055 /**
4056 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4057 * @param subId The subscription to use to check the configuration.
4058 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 @Override
4060 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004061 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4062 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004063 final long identity = Binder.clearCallingIdentity();
4064 try {
4065 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004066 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004067 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004068 } catch (ImsException e) {
4069 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004070 } finally {
4071 Binder.restoreCallingIdentity(identity);
4072 }
4073 }
4074
4075 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004076 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004078 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 final long identity = Binder.clearCallingIdentity();
4080 try {
4081 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004082 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004083 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004084 } catch (ImsException e) {
4085 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004086 } finally {
4087 Binder.restoreCallingIdentity(identity);
4088 }
4089 }
4090
4091 @Override
4092 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4093 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4094 "setVoWiFiNonPersistent");
4095 final long identity = Binder.clearCallingIdentity();
4096 try {
4097 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004098 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004099 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004100 } catch (ImsException e) {
4101 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004102 } finally {
4103 Binder.restoreCallingIdentity(identity);
4104 }
4105 }
4106
shilu366312e2019-12-17 09:28:10 -08004107 /**
4108 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4109 * @param subId The subscription to use to check the configuration.
4110 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004111 @Override
4112 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004113 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4114 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004115 final long identity = Binder.clearCallingIdentity();
4116 try {
4117 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004118 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004119 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004120 } catch (ImsException e) {
4121 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004122 } finally {
4123 Binder.restoreCallingIdentity(identity);
4124 }
4125 }
4126
4127 @Override
4128 public void setVoWiFiModeSetting(int subId, int mode) {
4129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4130 "setVoWiFiModeSetting");
4131 final long identity = Binder.clearCallingIdentity();
4132 try {
4133 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004134 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004135 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004136 } catch (ImsException e) {
4137 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
4144 public int getVoWiFiRoamingModeSetting(int subId) {
4145 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4146 final long identity = Binder.clearCallingIdentity();
4147 try {
4148 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004149 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004151 } catch (ImsException e) {
4152 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004153 } finally {
4154 Binder.restoreCallingIdentity(identity);
4155 }
4156 }
4157
4158 @Override
4159 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4160 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4161 "setVoWiFiRoamingModeSetting");
4162 final long identity = Binder.clearCallingIdentity();
4163 try {
4164 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004165 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004166 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004167 } catch (ImsException e) {
4168 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4177 "setRttCapabilityEnabled");
4178 final long identity = Binder.clearCallingIdentity();
4179 try {
4180 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004181 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4182 } catch (ImsException e) {
4183 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004184 } finally {
4185 Binder.restoreCallingIdentity(identity);
4186 }
4187 }
4188
shilu366312e2019-12-17 09:28:10 -08004189 /**
4190 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4191 * @param subId The subscription to use to check the configuration.
4192 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004193 @Override
4194 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004195 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4196 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004197 final long identity = Binder.clearCallingIdentity();
4198 try {
4199 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004200 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004201 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004202 } catch (ImsException e) {
4203 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004204 } finally {
4205 Binder.restoreCallingIdentity(identity);
4206 }
4207 }
4208
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 @Override
4210 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4211 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4212 final long identity = Binder.clearCallingIdentity();
4213 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004214 if (!isImsAvailableOnDevice()) {
4215 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4216 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004217 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004218 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004219 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004220 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004221 } catch (ImsException e) {
4222 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004223 } finally {
4224 Binder.restoreCallingIdentity(identity);
4225 }
4226 }
4227
4228 @Override
4229 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4230 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4231 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004232 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4233 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4234 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 try {
4236 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004237 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004238 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004239 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004240 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4241 + "is inactive, ignoring unregister.");
4242 // If the subscription is no longer active, just return, since the callback will already
4243 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004244 } finally {
4245 Binder.restoreCallingIdentity(identity);
4246 }
4247 }
4248
allenwtsu99c623b2020-01-03 18:24:23 +08004249
4250 private void checkModifyPhoneStatePermission(int subId, String message) {
4251 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4252 message);
4253 }
4254
4255 private boolean isImsProvisioningRequired(int subId, int capability,
4256 boolean isMmtelCapability) {
4257 Phone phone = getPhone(subId);
4258 if (phone == null) {
4259 loge("phone instance null for subid " + subId);
4260 return false;
4261 }
4262 if (isMmtelCapability) {
4263 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4264 return false;
4265 }
4266 } else {
4267 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4268 return false;
4269 }
4270 }
4271 return true;
4272 }
4273
4274 @Override
4275 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4276 boolean isProvisioned) {
4277 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4278
4279 final long identity = Binder.clearCallingIdentity();
4280 try {
4281 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4282 if (!isImsProvisioningRequired(subId, capability, false)) {
4283 return;
4284 }
4285
4286 // this capability requires provisioning, route to the correct API.
4287 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4288 switch (capability) {
4289 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4290 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4291 ims.setEabProvisioned(isProvisioned);
4292 break;
4293 default: {
4294 throw new IllegalArgumentException("Tried to set provisioning for "
4295 + "rcs capability '" + capability + "', which does not require "
4296 + "provisioning.");
4297 }
4298 }
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
4301 }
4302
4303 }
4304
4305
4306 @Override
4307 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4308 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4309 final long identity = Binder.clearCallingIdentity();
4310 try {
4311 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4312 if (!isImsProvisioningRequired(subId, capability, false)) {
4313 return true;
4314 }
4315
4316 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4317 switch (capability) {
4318 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4319 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4320 return ims.isEabProvisionedOnDevice();
4321
4322 default: {
4323 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4324 + "capability '" + capability + "', which does not require "
4325 + "provisioning.");
4326 }
4327 }
4328
4329 } finally {
4330 Binder.restoreCallingIdentity(identity);
4331 }
4332 }
4333
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004334 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004335 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4336 boolean isProvisioned) {
4337 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4338 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4339 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4340 }
allenwtsu99c623b2020-01-03 18:24:23 +08004341 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004342 final long identity = Binder.clearCallingIdentity();
4343 try {
4344 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004345 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004346 return;
4347 }
4348
4349 // this capability requires provisioning, route to the correct API.
4350 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4351 switch (capability) {
4352 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4353 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4354 ims.setVolteProvisioned(isProvisioned);
4355 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4356 ims.setWfcProvisioned(isProvisioned);
4357 }
4358 break;
4359 }
4360 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4361 // There is currently no difference in VT provisioning type.
4362 ims.setVtProvisioned(isProvisioned);
4363 break;
4364 }
4365 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4366 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4367 // change the capability of the feature instead if needed.
4368 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4369 == isProvisioned) {
4370 // No change in provisioning.
4371 return;
4372 }
4373 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4374 try {
4375 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004376 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004377 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4378 + ", Exception" + e.getMessage());
4379 }
4380 break;
4381 }
4382 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004383 throw new IllegalArgumentException("Tried to set provisioning for "
4384 + "MmTel capability '" + capability + "', which does not require "
4385 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004386 }
4387 }
4388
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
4391 }
4392 }
4393
4394 @Override
4395 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4396 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4397 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4398 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4399 }
4400 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4401 final long identity = Binder.clearCallingIdentity();
4402 try {
4403 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004404 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004405 return true;
4406 }
4407
4408 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4409 switch (capability) {
4410 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4411 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4412 return ims.isVolteProvisionedOnDevice();
4413 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4414 return ims.isWfcProvisionedOnDevice();
4415 }
4416 // This should never happen, since we are checking tech above to make sure it
4417 // is either LTE or IWLAN.
4418 throw new IllegalArgumentException("Invalid radio technology for voice "
4419 + "capability.");
4420 }
4421 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4422 // There is currently no difference in VT provisioning type.
4423 return ims.isVtProvisionedOnDevice();
4424 }
4425 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4426 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4427 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4428 }
4429 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004430 throw new IllegalArgumentException(
4431 "Tried to get provisioning for MmTel capability '" + capability
4432 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004433 }
4434 }
4435
4436 } finally {
4437 Binder.restoreCallingIdentity(identity);
4438 }
4439 }
4440
4441 @Override
4442 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4443 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4444 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4445 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4446 }
4447 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4448 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4449 return (provisionedBits & capability) > 0;
4450 }
4451
4452 @Override
4453 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4454 boolean isProvisioned) {
4455 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4456 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4457 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4458 }
4459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4460 "setProvisioningStatusForCapability");
4461 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4462 // If the current provisioning status for capability already matches isProvisioned,
4463 // do nothing.
4464 if (((provisionedBits & capability) > 0) == isProvisioned) {
4465 return;
4466 }
4467 if (isProvisioned) {
4468 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4469 } else {
4470 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4471 }
4472 }
4473
4474 /**
4475 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4476 * technology. The bitfield should mirror the bitfield defined by
4477 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4478 */
4479 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4480 String key = getMmTelProvisioningKey(subId, tech);
4481 // Default is no capabilities are provisioned.
4482 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4483 }
4484
4485 /**
4486 * Sets the MmTel capability provisioning bitfield (defined by
4487 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4488 * technology specified.
4489 *
4490 * Note: This is a synchronous command and should not be called on UI thread.
4491 */
4492 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4493 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4494 String key = getMmTelProvisioningKey(subId, tech);
4495 editor.putInt(key, newField);
4496 editor.commit();
4497 }
4498
4499 private static String getMmTelProvisioningKey(int subId, int tech) {
4500 // resulting key is provision_ims_mmtel_{subId}_{tech}
4501 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4502 }
4503
4504 /**
4505 * Query CarrierConfig to see if the specified capability requires provisioning for the
4506 * carrier associated with the subscription id.
4507 */
4508 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4509 int capability) {
4510 CarrierConfigManager configManager = new CarrierConfigManager(context);
4511 PersistableBundle c = configManager.getConfigForSubId(subId);
4512 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004513 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004514 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4515 false);
4516 boolean requireVoiceVtProvisioning = c.getBoolean(
4517 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4518
4519 // First check to make sure that the capability requires provisioning.
4520 switch (capability) {
4521 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4522 // intentional fallthrough
4523 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4524 if (requireVoiceVtProvisioning) {
4525 // Voice and Video requires provisioning
4526 return true;
4527 }
4528 break;
4529 }
4530 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4531 if (requireUtProvisioning) {
4532 // UT requires provisioning
4533 return true;
4534 }
4535 break;
4536 }
4537 }
4538 return false;
4539 }
4540
allenwtsu99c623b2020-01-03 18:24:23 +08004541 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4542 int capability) {
4543 CarrierConfigManager configManager = new CarrierConfigManager(context);
4544 PersistableBundle c = configManager.getConfigForSubId(subId);
4545
4546 boolean requireRcsProvisioning = c.getBoolean(
4547 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4548
4549 // First check to make sure that the capability requires provisioning.
4550 switch (capability) {
4551 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4552 // intentional fallthrough
4553 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4554 if (requireRcsProvisioning) {
4555 // OPTION or PRESENCE requires provisioning
4556 return true;
4557 }
4558 break;
4559 }
4560 }
4561 return false;
4562 }
4563
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004564 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004565 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004566 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4567 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4568 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004569 enforceReadPrivilegedPermission("getImsProvisioningInt");
4570 final long identity = Binder.clearCallingIdentity();
4571 try {
4572 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 int slotId = getSlotIndex(subId);
4574 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4575 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4576 + subId + "' for key:" + key);
4577 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4578 }
4579 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004580 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004581 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4582 + subId + "' for key:" + key);
4583 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004584 } finally {
4585 Binder.restoreCallingIdentity(identity);
4586 }
4587 }
4588
4589 @Override
4590 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004591 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4592 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4593 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004594 enforceReadPrivilegedPermission("getImsProvisioningString");
4595 final long identity = Binder.clearCallingIdentity();
4596 try {
4597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004598 int slotId = getSlotIndex(subId);
4599 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4600 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4601 + subId + "' for key:" + key);
4602 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4603 }
4604 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004605 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004606 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4607 + subId + "' for key:" + key);
4608 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004609 } finally {
4610 Binder.restoreCallingIdentity(identity);
4611 }
4612 }
4613
4614 @Override
4615 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004616 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4617 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4618 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004619 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4620 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004621 final long identity = Binder.clearCallingIdentity();
4622 try {
4623 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004624 int slotId = getSlotIndex(subId);
4625 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4626 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4627 + subId + "' for key:" + key);
4628 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4629 }
4630 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004631 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4633 + "' for key:" + key);
4634 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004635 } finally {
4636 Binder.restoreCallingIdentity(identity);
4637 }
4638 }
4639
4640 @Override
4641 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004642 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4643 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4644 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004645 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4646 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004647 final long identity = Binder.clearCallingIdentity();
4648 try {
4649 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004650 int slotId = getSlotIndex(subId);
4651 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4652 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4653 + subId + "' for key:" + key);
4654 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4655 }
4656 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004657 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004658 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4659 + "' for key:" + key);
4660 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004661 } finally {
4662 Binder.restoreCallingIdentity(identity);
4663 }
4664 }
4665
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004666 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004667 int slotId = SubscriptionManager.getSlotIndex(subId);
4668 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004669 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4670 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004671 }
4672 return slotId;
4673 }
4674
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004675 private int getSlotIndex(int subId) {
4676 int slotId = SubscriptionManager.getSlotIndex(subId);
4677 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4678 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4679 }
4680 return slotId;
4681 }
4682
Wink Saville36469e72014-06-11 15:17:00 -07004683 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004684 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004685 */
4686 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004687 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4688 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004689 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004690 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004691 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004692 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004693 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004694 mApp, subId, callingPackage, callingFeatureId,
4695 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4697 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004699 final long identity = Binder.clearCallingIdentity();
4700 try {
4701 final Phone phone = getPhone(subId);
4702 if (phone != null) {
4703 return phone.getServiceState().getDataNetworkType();
4704 } else {
4705 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4706 }
4707 } finally {
4708 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004710 }
4711
4712 /**
4713 * Returns the data network type
4714 */
4715 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004716 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4717 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4718 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004719 }
4720
4721 /**
4722 * Returns the data network type for a subId
4723 */
4724 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004725 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4726 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004727 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004728 mApp, subId, callingPackage, callingFeatureId,
4729 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004730 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4731 }
4732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004733 final long identity = Binder.clearCallingIdentity();
4734 try {
4735 final Phone phone = getPhone(subId);
4736 if (phone != null) {
4737 return phone.getServiceState().getDataNetworkType();
4738 } else {
4739 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4740 }
4741 } finally {
4742 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004743 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004744 }
4745
4746 /**
Wink Saville36469e72014-06-11 15:17:00 -07004747 * Returns the Voice network type for a subId
4748 */
4749 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004750 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4751 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004752 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004753 mApp, subId, callingPackage, callingFeatureId,
4754 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004755 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4756 }
4757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 final Phone phone = getPhone(subId);
4761 if (phone != null) {
4762 return phone.getServiceState().getVoiceNetworkType();
4763 } else {
4764 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4765 }
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004768 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004769 }
4770
4771 /**
4772 * @return true if a ICC card is present
4773 */
4774 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004775 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004776 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4777 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004778 }
4779
4780 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004781 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004782 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004783 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004784 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004785 final long identity = Binder.clearCallingIdentity();
4786 try {
4787 final Phone phone = PhoneFactory.getPhone(slotIndex);
4788 if (phone != null) {
4789 return phone.getIccCard().hasIccCard();
4790 } else {
4791 return false;
4792 }
4793 } finally {
4794 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004795 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004796 }
4797
4798 /**
4799 * Return if the current radio is LTE on CDMA. This
4800 * is a tri-state return value as for a period of time
4801 * the mode may be unknown.
4802 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004803 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004804 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004805 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004806 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004807 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004808 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4809 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4810 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004811 }
4812
Sanket Padawe356d7632015-06-22 14:03:32 -07004813 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004814 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4815 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004816 try {
4817 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4818 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004819 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4820 }
4821
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004822 final long identity = Binder.clearCallingIdentity();
4823 try {
4824 final Phone phone = getPhone(subId);
4825 if (phone == null) {
4826 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4827 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004828 return TelephonyProperties.lte_on_cdma_device()
4829 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 }
4831 } finally {
4832 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004833 }
Wink Saville36469e72014-06-11 15:17:00 -07004834 }
4835
Wink Saville36469e72014-06-11 15:17:00 -07004836 /**
4837 * {@hide}
4838 * Returns Default subId, 0 in the case of single standby.
4839 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004840 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004841 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004842 }
4843
Shishir Agrawala9f32182016-04-12 12:00:16 -07004844 private int getSlotForDefaultSubscription() {
4845 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4846 }
4847
Wink Savilleb564aae2014-10-23 10:18:09 -07004848 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004849 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004850 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004851
Pengquan Menge92a50d2018-09-21 15:54:48 -07004852 private boolean isActiveSubscription(int subId) {
4853 return mSubscriptionController.isActiveSubId(subId);
4854 }
4855
Ihab Awadf2177b72013-11-25 13:33:23 -08004856 /**
4857 * @see android.telephony.TelephonyManager.WifiCallingChoices
4858 */
4859 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 final long identity = Binder.clearCallingIdentity();
4861 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004862 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004863 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4864 getWhenToMakeWifiCallsDefaultPreference());
4865 } finally {
4866 Binder.restoreCallingIdentity(identity);
4867 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004868 }
4869
4870 /**
4871 * @see android.telephony.TelephonyManager.WifiCallingChoices
4872 */
4873 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 final long identity = Binder.clearCallingIdentity();
4875 try {
4876 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004877 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4879 } finally {
4880 Binder.restoreCallingIdentity(identity);
4881 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004882 }
4883
Sailesh Nepald1e68152013-12-12 19:08:02 -08004884 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004885 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004886 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004887 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004888
Jordan Liu4c733742019-02-28 12:03:40 -08004889 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4890 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4891 if (phoneId == -1) {
4892 throw new IllegalArgumentException("Given slot index: " + slotIndex
4893 + " does not correspond to an active phone");
4894 }
4895 return PhoneFactory.getPhone(phoneId);
4896 }
4897
Shishir Agrawal566b7612013-10-28 14:41:00 -07004898 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004899 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4900 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4902 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004903 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004904 if (DBG) {
4905 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4906 }
4907 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4908 p2);
4909 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004910
Jordan Liu4c733742019-02-28 12:03:40 -08004911
4912 @Override
4913 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4914 int slotIndex, String callingPackage, String aid, int p2) {
4915 enforceModifyPermission();
4916 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4917 if (DBG) {
4918 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4919 }
4920 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4921 callingPackage, aid, p2);
4922 }
4923
4924 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4925 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
4928 if (TextUtils.equals(ISDR_AID, aid)) {
4929 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004930 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4931 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 if (bestComponent == null
4933 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4934 loge("The calling package is not allowed to access ISD-R.");
4935 throw new SecurityException(
4936 "The calling package is not allowed to access ISD-R.");
4937 }
Derek Tan740e1672017-06-27 14:56:27 -07004938 }
Derek Tan740e1672017-06-27 14:56:27 -07004939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004941 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4942 null /* workSource */);
4943 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 return response;
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004948 }
4949
4950 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004951 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004952 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4953 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004954 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4955 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4956 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004957
Jordan Liu4c733742019-02-28 12:03:40 -08004958 @Override
4959 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4960 enforceModifyPermission();
4961 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4962 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4963 channel);
4964 }
4965
4966 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004967 final long identity = Binder.clearCallingIdentity();
4968 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 if (channel < 0) {
4970 return false;
4971 }
Jordan Liu4c733742019-02-28 12:03:40 -08004972 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4973 null /* workSource */);
4974 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975 return success;
4976 } finally {
4977 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004979 }
4980
4981 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004982 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004983 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004984 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4985 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004986 if (DBG) {
4987 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4988 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4989 + p3 + " data=" + data);
4990 }
4991 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4992 command, p1, p2, p3, data);
4993 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004994
Jordan Liu4c733742019-02-28 12:03:40 -08004995 @Override
4996 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4997 int command, int p1, int p2, int p3, String data) {
4998 enforceModifyPermission();
4999 if (DBG) {
5000 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5001 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5002 + p3 + " data=" + data);
5003 }
5004 return iccTransmitApduLogicalChannelWithPermission(
5005 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5006 data);
5007 }
5008
5009 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5010 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005011 final long identity = Binder.clearCallingIdentity();
5012 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005013 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005014 return "";
5015 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005016
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005018 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5019 null /* workSource */);
5020 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 // Append the returned status code to the end of the response payload.
5023 String s = Integer.toHexString(
5024 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5025 if (response.payload != null) {
5026 s = IccUtils.bytesToHexString(response.payload) + s;
5027 }
5028 return s;
5029 } finally {
5030 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005031 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005032 }
Jake Hambye994d462014-02-03 13:10:13 -08005033
Evan Charltonc66da362014-05-16 14:06:40 -07005034 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005035 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5036 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005037 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5038 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005040 if (DBG) {
5041 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5042 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5043 }
5044 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5045 cla, command, p1, p2, p3, data);
5046 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005047
Jordan Liu4c733742019-02-28 12:03:40 -08005048 @Override
5049 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5050 int command, int p1, int p2, int p3, String data) {
5051 enforceModifyPermission();
5052 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5053 if (DBG) {
5054 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5055 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5056 + " data=" + data);
5057 }
5058
5059 return iccTransmitApduBasicChannelWithPermission(
5060 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5061 p2, p3, data);
5062 }
5063
5064 // open APDU basic channel assuming the caller has sufficient permissions
5065 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5066 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005067 final long identity = Binder.clearCallingIdentity();
5068 try {
5069 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5070 && TextUtils.equals(ISDR_AID, data)) {
5071 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005072 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5073 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 if (bestComponent == null
5075 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5076 loge("The calling package is not allowed to select ISD-R.");
5077 throw new SecurityException(
5078 "The calling package is not allowed to select ISD-R.");
5079 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005080 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005082 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005083 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5084 null /* workSource */);
5085 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 // Append the returned status code to the end of the response payload.
5088 String s = Integer.toHexString(
5089 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5090 if (response.payload != null) {
5091 s = IccUtils.bytesToHexString(response.payload) + s;
5092 }
5093 return s;
5094 } finally {
5095 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005096 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005097 }
5098
5099 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005100 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005101 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5103 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005104
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005105 final long identity = Binder.clearCallingIdentity();
5106 try {
5107 if (DBG) {
5108 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5109 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5110 }
5111
5112 IccIoResult response =
5113 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5114 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5115 subId);
5116
5117 if (DBG) {
5118 log("Exchange SIM_IO [R]" + response);
5119 }
5120
5121 byte[] result = null;
5122 int length = 2;
5123 if (response.payload != null) {
5124 length = 2 + response.payload.length;
5125 result = new byte[length];
5126 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5127 } else {
5128 result = new byte[length];
5129 }
5130
5131 result[length - 1] = (byte) response.sw2;
5132 result[length - 2] = (byte) response.sw1;
5133 return result;
5134 } finally {
5135 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005136 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005137 }
5138
Nathan Haroldb3014052017-01-25 15:57:32 -08005139 /**
5140 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5141 * on a particular subscription
5142 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005143 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5144 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005145 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005146 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005147 return null;
5148 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005149
5150 final long identity = Binder.clearCallingIdentity();
5151 try {
5152 if (appType != TelephonyManager.APPTYPE_USIM
5153 && appType != TelephonyManager.APPTYPE_SIM) {
5154 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5155 return null;
5156 }
5157 Object response = sendRequest(
5158 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5159 if (response instanceof String[]) {
5160 return (String[]) response;
5161 }
yincheng zhaod698b842019-09-06 17:06:54 -07005162 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005163 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005164 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005165 } finally {
5166 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005167 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005168 }
5169
yincheng zhaod698b842019-09-06 17:06:54 -07005170 /**
5171 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5172 * subscription.
5173 *
5174 * @param subId the id of the subscription.
5175 * @param appType the uicc app type, must be USIM or SIM.
5176 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5177 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005178 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005179 * @return number of fplmns that is successfully written to the SIM.
5180 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005181 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5182 String callingFeatureId) {
5183 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5184 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005185 if (DBG) logv("no permissions for setForbiddenplmns");
5186 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5187 }
5188 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5189 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5190 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5191 }
5192 if (fplmns == null) {
5193 throw new IllegalArgumentException("Fplmn List provided is null");
5194 }
5195 for (String fplmn : fplmns) {
5196 if (!CellIdentity.isValidPlmn(fplmn)) {
5197 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5198 }
5199 }
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
5202 Object response = sendRequest(
5203 CMD_SET_FORBIDDEN_PLMNS,
5204 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5205 subId);
5206 return (int) response;
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
5210 }
5211
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005212 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005213 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005214 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5215 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005216
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005217 final long identity = Binder.clearCallingIdentity();
5218 try {
5219 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5220 if (response.payload == null) {
5221 return "";
5222 }
Evan Charltonc66da362014-05-16 14:06:40 -07005223
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005224 // Append the returned status code to the end of the response payload.
5225 String s = Integer.toHexString(
5226 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5227 s = IccUtils.bytesToHexString(response.payload) + s;
5228 return s;
5229 } finally {
5230 Binder.restoreCallingIdentity(identity);
5231 }
Evan Charltonc66da362014-05-16 14:06:40 -07005232 }
5233
Jake Hambye994d462014-02-03 13:10:13 -08005234 /**
5235 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5236 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5237 *
5238 * @param itemID the ID of the item to read
5239 * @return the NV item as a String, or null on error.
5240 */
5241 @Override
5242 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005243 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005244 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5245 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246
5247 final long identity = Binder.clearCallingIdentity();
5248 try {
5249 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005250 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5252 return value;
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Jake Hambye994d462014-02-03 13:10:13 -08005256 }
5257
5258 /**
5259 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5260 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5261 *
5262 * @param itemID the ID of the item to read
5263 * @param itemValue the value to write, as a String
5264 * @return true on success; false on any failure
5265 */
5266 @Override
5267 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005268 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005269 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5270 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271
5272 final long identity = Binder.clearCallingIdentity();
5273 try {
5274 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5275 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005276 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5278 return success;
5279 } finally {
5280 Binder.restoreCallingIdentity(identity);
5281 }
Jake Hambye994d462014-02-03 13:10:13 -08005282 }
5283
5284 /**
5285 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5286 * Used for device configuration by some CDMA operators.
5287 *
5288 * @param preferredRoamingList byte array containing the new PRL
5289 * @return true on success; false on any failure
5290 */
5291 @Override
5292 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005293 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5294 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005295
5296 final long identity = Binder.clearCallingIdentity();
5297 try {
5298 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5299 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5300 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5301 return success;
5302 } finally {
5303 Binder.restoreCallingIdentity(identity);
5304 }
Jake Hambye994d462014-02-03 13:10:13 -08005305 }
5306
5307 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005308 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005309 * Used for device configuration by some CDMA operators.
5310 *
chen xu6dac5ab2018-10-26 17:39:23 -07005311 * @param slotIndex - device slot.
5312 *
Jake Hambye994d462014-02-03 13:10:13 -08005313 * @return true on success; false on any failure
5314 */
5315 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005316 public boolean resetModemConfig(int slotIndex) {
5317 Phone phone = PhoneFactory.getPhone(slotIndex);
5318 if (phone != null) {
5319 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5320 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005321
chen xu6dac5ab2018-10-26 17:39:23 -07005322 final long identity = Binder.clearCallingIdentity();
5323 try {
5324 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5325 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5326 return success;
5327 } finally {
5328 Binder.restoreCallingIdentity(identity);
5329 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005330 }
chen xu6dac5ab2018-10-26 17:39:23 -07005331 return false;
5332 }
5333
5334 /**
5335 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5336 *
5337 * @param slotIndex - device slot.
5338 *
5339 * @return true on success; false on any failure
5340 */
5341 @Override
5342 public boolean rebootModem(int slotIndex) {
5343 Phone phone = PhoneFactory.getPhone(slotIndex);
5344 if (phone != null) {
5345 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5346 mApp, phone.getSubId(), "rebootModem");
5347
5348 final long identity = Binder.clearCallingIdentity();
5349 try {
5350 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5351 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5352 return success;
5353 } finally {
5354 Binder.restoreCallingIdentity(identity);
5355 }
5356 }
5357 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005358 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005359
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005360 public String[] getPcscfAddress(String apnType, String callingPackage,
5361 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005362 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005363 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5364 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005365 return new String[0];
5366 }
5367
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 final long identity = Binder.clearCallingIdentity();
5369 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005370 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
Wink Saville36469e72014-06-11 15:17:00 -07005374 }
5375
Brad Ebinger51f743a2017-01-23 13:50:20 -08005376 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005377 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5378 * {@link #disableIms(int)}.
5379 * @param slotIndex device slot.
5380 */
5381 public void resetIms(int slotIndex) {
5382 enforceModifyPermission();
5383
5384 final long identity = Binder.clearCallingIdentity();
5385 try {
5386 if (mImsResolver == null) {
5387 // may happen if the does not support IMS.
5388 return;
5389 }
5390 mImsResolver.disableIms(slotIndex);
5391 mImsResolver.enableIms(slotIndex);
5392 } finally {
5393 Binder.restoreCallingIdentity(identity);
5394 }
5395 }
5396
5397 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005398 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5399 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005400 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005401 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005402 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005403
5404 final long identity = Binder.clearCallingIdentity();
5405 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005406 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005407 // may happen if the device does not support IMS.
5408 return;
5409 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005410 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005411 } finally {
5412 Binder.restoreCallingIdentity(identity);
5413 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005414 }
5415
5416 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005417 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5418 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005419 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005420 public void disableIms(int slotId) {
5421 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005422
5423 final long identity = Binder.clearCallingIdentity();
5424 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005425 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005426 // may happen if the device does not support IMS.
5427 return;
5428 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005429 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 } finally {
5431 Binder.restoreCallingIdentity(identity);
5432 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005433 }
5434
5435 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005436 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5437 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005438 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005439 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005440 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005441 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005442
5443 final long identity = Binder.clearCallingIdentity();
5444 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005445 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005446 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5447 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005448 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005449 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005450 } finally {
5451 Binder.restoreCallingIdentity(identity);
5452 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005453 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005454 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005455 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5456 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005457 @Override
5458 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005459 enforceModifyPermission();
5460
5461 final long identity = Binder.clearCallingIdentity();
5462 try {
5463 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005464 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005465 } finally {
5466 Binder.restoreCallingIdentity(identity);
5467 }
5468 }
5469
5470 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005471 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005472 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005473 */
5474 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5475 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476
5477 final long identity = Binder.clearCallingIdentity();
5478 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005479 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005480 // may happen if the device does not support IMS.
5481 return null;
5482 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005483 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 } finally {
5485 Binder.restoreCallingIdentity(identity);
5486 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005487 }
5488
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005489 /**
5490 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005491 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005492 */
5493 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5494 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005495
5496 final long identity = Binder.clearCallingIdentity();
5497 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005498 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005499 // may happen if the device does not support IMS.
5500 return null;
5501 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005502 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005503 } finally {
5504 Binder.restoreCallingIdentity(identity);
5505 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005506 }
5507
Brad Ebinger884c07b2018-02-15 16:17:40 -08005508 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005509 * Sets the ImsService Package Name that Telephony will bind to.
5510 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005511 * @param slotIndex the slot ID that the ImsService should bind for.
5512 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005513 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005514 * @param featureTypes An integer array of feature types associated with a packageName.
5515 * @param packageName The name of the package that the current configuration will be replaced
5516 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005517 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005518 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005519 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5520 int[] featureTypes, String packageName) {
5521 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5522 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005523 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5524 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005525 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005526
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005527 final long identity = Binder.clearCallingIdentity();
5528 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005529 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005530 // may happen if the device does not support IMS.
5531 return false;
5532 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005533 Map<Integer, String> featureConfig = new HashMap<>();
5534 for (int featureType : featureTypes) {
5535 featureConfig.put(featureType, packageName);
5536 }
5537 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5538 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005539 } finally {
5540 Binder.restoreCallingIdentity(identity);
5541 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005542 }
5543
5544 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005545 * Clears any carrier ImsService overrides for the slot index specified that were previously
5546 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5547 *
5548 * This should only be used for testing.
5549 *
5550 * @param slotIndex the slot ID that the ImsService should bind for.
5551 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5552 */
5553 @Override
5554 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5555 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5556 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5557 "clearCarrierImsServiceOverride");
5558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5559 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5560 "clearCarrierImsServiceOverride");
5561
5562 final long identity = Binder.clearCallingIdentity();
5563 try {
5564 if (mImsResolver == null) {
5565 // may happen if the device does not support IMS.
5566 return false;
5567 }
5568 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
5572 }
5573
5574 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005575 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005576 *
5577 * @param slotId The slot that the ImsService is associated with.
5578 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5579 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005580 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005581 * @return the package name of the ImsService configuration.
5582 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005583 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5584 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005585 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005586 TelephonyPermissions
5587 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5588 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5589 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005591 final long identity = Binder.clearCallingIdentity();
5592 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005593 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005594 // may happen if the device does not support IMS.
5595 return "";
5596 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005597 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005598 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5599 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005600 } finally {
5601 Binder.restoreCallingIdentity(identity);
5602 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005603 }
5604
Brad Ebinger77b832e2019-10-17 17:03:22 -07005605 /**
5606 * Get the MmTelFeature state associated with the requested subscription id.
5607 * @param subId The subscription that the MmTelFeature is associated with.
5608 * @param callback A callback with an integer containing the
5609 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5610 */
5611 @Override
5612 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5613 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5614 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5615 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5616 "IMS not available on device.");
5617 }
5618 final long token = Binder.clearCallingIdentity();
5619 try {
5620 int slotId = getSlotIndex(subId);
5621 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5622 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5623 + subId + "'");
5624 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5625 }
5626 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5627 try {
5628 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5629 } catch (RemoteException e) {
5630 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5631 + "Ignore");
5632 }
5633 });
5634 } finally {
5635 Binder.restoreCallingIdentity(token);
5636 }
5637 }
5638
Daniel Brightbb5840b2021-01-12 15:48:18 -08005639 /**
5640 * Sets the ims registration state on all valid {@link Phone}s.
5641 */
5642 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005643 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644
5645 final long identity = Binder.clearCallingIdentity();
5646 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005647 // NOTE: Before S, this method only set the default phone.
5648 for (final Phone phone : PhoneFactory.getPhones()) {
5649 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5650 phone.setImsRegistrationState(registered);
5651 }
5652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005653 } finally {
5654 Binder.restoreCallingIdentity(identity);
5655 }
Wink Saville36469e72014-06-11 15:17:00 -07005656 }
5657
5658 /**
Stuart Scott54788802015-03-30 13:18:01 -07005659 * Set the network selection mode to automatic.
5660 *
5661 */
5662 @Override
5663 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005664 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5665 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666
5667 final long identity = Binder.clearCallingIdentity();
5668 try {
shilufc958392020-01-20 11:36:01 -08005669 if (!isActiveSubscription(subId)) {
5670 return;
5671 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005673 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5674 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005675 } finally {
5676 Binder.restoreCallingIdentity(identity);
5677 }
Stuart Scott54788802015-03-30 13:18:01 -07005678 }
5679
Jack Yud10cdd42020-09-28 20:28:01 -07005680 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005681 * Ask the radio to connect to the input network and change selection mode to manual.
5682 *
5683 * @param subId the id of the subscription.
5684 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5685 * the operator to attach to.
5686 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5687 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5688 * normal network selection next time.
5689 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005690 */
5691 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005692 public boolean setNetworkSelectionModeManual(
5693 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005694 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5695 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005696
5697 if (!isActiveSubscription(subId)) {
5698 return false;
5699 }
5700
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005701 final long identity = Binder.clearCallingIdentity();
5702 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005703 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005705 if (DBG) {
5706 log("setNetworkSelectionModeManual: subId: " + subId
5707 + " operator: " + operatorInfo);
5708 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5710 } finally {
5711 Binder.restoreCallingIdentity(identity);
5712 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005713 }
shilu84f6e8b2019-12-19 13:58:01 -08005714 /**
5715 * Get the manual network selection
5716 *
5717 * @param subId the id of the subscription.
5718 *
5719 * @return the previously saved user selected PLMN
5720 */
5721 @Override
5722 public String getManualNetworkSelectionPlmn(int subId) {
5723 TelephonyPermissions
5724 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5725 mApp, subId, "getManualNetworkSelectionPlmn");
5726
5727 final long identity = Binder.clearCallingIdentity();
5728 try {
5729 if (!isActiveSubscription(subId)) {
5730 return "";
5731 }
5732
5733 final Phone phone = getPhone(subId);
5734 if (phone == null) {
5735 return "";
5736 }
5737 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5738 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5739 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5740 } finally {
5741 Binder.restoreCallingIdentity(identity);
5742 }
5743 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005744
5745 /**
5746 * Scans for available networks.
5747 */
5748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005749 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5750 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5752 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005753 LocationAccessPolicy.LocationPermissionResult locationResult =
5754 LocationAccessPolicy.checkLocationPermission(mApp,
5755 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5756 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005757 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005758 .setCallingPid(Binder.getCallingPid())
5759 .setCallingUid(Binder.getCallingUid())
5760 .setMethod("getCellNetworkScanResults")
5761 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5762 .build());
5763 switch (locationResult) {
5764 case DENIED_HARD:
5765 throw new SecurityException("Not allowed to access scan results -- location");
5766 case DENIED_SOFT:
5767 return null;
5768 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005769
Pengquan Menga1bb6272018-09-06 09:59:22 -07005770 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005771 try {
5772 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005773 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 } finally {
5776 Binder.restoreCallingIdentity(identity);
5777 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005778 }
5779
5780 /**
sqian80370722020-01-29 15:02:51 -08005781 * Get the call forwarding info, given the call forwarding reason.
5782 */
5783 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005784 public void getCallForwarding(int subId, int callForwardingReason,
5785 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005786 enforceReadPrivilegedPermission("getCallForwarding");
5787 long identity = Binder.clearCallingIdentity();
5788 try {
5789 if (DBG) {
5790 log("getCallForwarding: subId " + subId
5791 + " callForwardingReason" + callForwardingReason);
5792 }
Hall Liua1acea22020-09-18 19:04:59 -07005793
5794 Phone phone = getPhone(subId);
5795 if (phone == null) {
5796 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005797 callback.onError(
5798 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005799 } catch (RemoteException e) {
5800 // ignore
5801 }
5802 return;
5803 }
5804
5805 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5806 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5807 @Override
5808 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5809 try {
5810 callback.onCallForwardingInfoAvailable(info);
5811 } catch (RemoteException e) {
5812 // ignore
5813 }
5814 }
5815
5816 @Override
5817 public void onError(int error) {
5818 try {
5819 callback.onError(error);
5820 } catch (RemoteException e) {
5821 // ignore
5822 }
5823 }
5824 });
5825 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005826 } finally {
5827 Binder.restoreCallingIdentity(identity);
5828 }
5829 }
5830
5831 /**
5832 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5833 * reason, the number to forward, and the timeout before the forwarding is attempted.
5834 */
5835 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005836 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5837 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005838 enforceModifyPermission();
5839 long identity = Binder.clearCallingIdentity();
5840 try {
5841 if (DBG) {
5842 log("setCallForwarding: subId " + subId
5843 + " callForwardingInfo" + callForwardingInfo);
5844 }
Hall Liua1acea22020-09-18 19:04:59 -07005845
5846 Phone phone = getPhone(subId);
5847 if (phone == null) {
5848 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005849 callback.accept(
5850 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005851 } catch (RemoteException e) {
5852 // ignore
5853 }
5854 return;
5855 }
5856
5857 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5858 FunctionalUtils.ignoreRemoteException(callback::accept));
5859
5860 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005861 } finally {
5862 Binder.restoreCallingIdentity(identity);
5863 }
5864 }
5865
5866 /**
Hall Liua1acea22020-09-18 19:04:59 -07005867 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005868 */
5869 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005870 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005871 enforceReadPrivilegedPermission("getCallForwarding");
5872 long identity = Binder.clearCallingIdentity();
5873 try {
Hall Liua1acea22020-09-18 19:04:59 -07005874
5875 Phone phone = getPhone(subId);
5876 if (phone == null) {
5877 try {
5878 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5879 } catch (RemoteException e) {
5880 // ignore
5881 }
5882 return;
5883 }
5884
5885 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5886
sqian80370722020-01-29 15:02:51 -08005887 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005888 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005889 } finally {
5890 Binder.restoreCallingIdentity(identity);
5891 }
5892 }
5893
5894 /**
Hall Liua1acea22020-09-18 19:04:59 -07005895 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005896 */
5897 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005898 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005899 enforceModifyPermission();
5900 long identity = Binder.clearCallingIdentity();
5901 try {
Hall Liua1acea22020-09-18 19:04:59 -07005902 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5903
5904 Phone phone = getPhone(subId);
5905 if (phone == null) {
5906 try {
5907 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5908 } catch (RemoteException e) {
5909 // ignore
5910 }
5911 return;
5912 }
5913
5914 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5915 FunctionalUtils.ignoreRemoteException(callback::accept));
5916
5917 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005918 } finally {
5919 Binder.restoreCallingIdentity(identity);
5920 }
5921 }
5922
5923 /**
yinxub1bed742017-04-17 11:45:04 -07005924 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005925 *
yinxub1bed742017-04-17 11:45:04 -07005926 * @param subId id of the subscription
5927 * @param request contains the radio access networks with bands/channels to scan
5928 * @param messenger callback messenger for scan results or errors
5929 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005930 * @return the id of the requested scan which can be used to stop the scan.
5931 */
5932 @Override
5933 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005934 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5936 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005937 LocationAccessPolicy.LocationPermissionResult locationResult =
5938 LocationAccessPolicy.checkLocationPermission(mApp,
5939 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5940 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005941 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005942 .setCallingPid(Binder.getCallingPid())
5943 .setCallingUid(Binder.getCallingUid())
5944 .setMethod("requestNetworkScan")
5945 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5946 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005947 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005948 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5949 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005950 if (e != null) {
5951 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5952 throw e;
5953 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005954 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005955 return TelephonyScanManager.INVALID_SCAN_ID;
5956 }
5957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005958 }
Hall Liu912dfd32019-04-25 14:02:26 -07005959 int callingUid = Binder.getCallingUid();
5960 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005961 final long identity = Binder.clearCallingIdentity();
5962 try {
5963 return mNetworkScanRequestTracker.startNetworkScan(
5964 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005965 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005966 } finally {
5967 Binder.restoreCallingIdentity(identity);
5968 }
yinxu504e1392017-04-12 16:03:22 -07005969 }
5970
Hall Liub2ac8ef2019-02-28 15:56:23 -08005971 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005972 NetworkScanRequest request, int subId, String callingPackage) {
5973 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005974 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5975 boolean hasNetworkScanPermission =
5976 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5977 == PERMISSION_GRANTED;
5978
5979 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5980 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5981 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005982 }
5983
5984 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5985 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005986 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5987 return new SecurityException("Specific channels must not be"
5988 + " scanned without location access.");
5989 }
5990 }
5991 }
5992
Hall Liub2ac8ef2019-02-28 15:56:23 -08005993 return null;
5994 }
5995
yinxu504e1392017-04-12 16:03:22 -07005996 /**
5997 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005998 *
5999 * @param subId id of the subscription
6000 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006001 */
6002 @Override
6003 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006004 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6005 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006
Hall Liu912dfd32019-04-25 14:02:26 -07006007 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 final long identity = Binder.clearCallingIdentity();
6009 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006010 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011 } finally {
6012 Binder.restoreCallingIdentity(identity);
6013 }
yinxu504e1392017-04-12 16:03:22 -07006014 }
6015
6016 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006017 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006018 *
SongFerngWang9e060372020-12-21 16:41:52 +08006019 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006020 */
6021 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006022 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006023 TelephonyPermissions
6024 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006025 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006026
6027 final long identity = Binder.clearCallingIdentity();
6028 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006029 if (DBG) log("getAllowedNetworkTypesBitmask");
6030 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6031 int networkTypesBitmask = (result != null ? result[0] : -1);
6032 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6033 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006034 } finally {
6035 Binder.restoreCallingIdentity(identity);
6036 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006037 }
6038
6039 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006040 * Get the allowed network types for certain reason.
6041 *
6042 * @param subId the id of the subscription.
6043 * @param reason the reason the allowed network type change is taking place
6044 * @return the allowed network types.
6045 */
6046 @Override
6047 public long getAllowedNetworkTypesForReason(int subId,
6048 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6049 TelephonyPermissions
6050 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6051 mApp, subId, "getAllowedNetworkTypesForReason");
6052 final long identity = Binder.clearCallingIdentity();
6053 try {
6054 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6055 } finally {
6056 Binder.restoreCallingIdentity(identity);
6057 }
6058 }
6059
6060 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006061 * Enable/Disable E-UTRA-NR Dual Connectivity
6062 * @param subId subscription id of the sim card
6063 * @param nrDualConnectivityState expected NR dual connectivity state
6064 * This can be passed following states
6065 * <ol>
6066 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6067 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6068 * <li>Disable NR dual connectivity and force secondary cell to be released
6069 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6070 * </ol>
6071 * @return operation result.
6072 */
6073 @Override
6074 public int setNrDualConnectivityState(int subId,
6075 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6077 mApp, subId, "enableNRDualConnectivity");
6078 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6082 nrDualConnectivityState, subId,
6083 workSource);
6084 if (DBG) log("enableNRDualConnectivity result: " + result);
6085 return result;
6086 } finally {
6087 Binder.restoreCallingIdentity(identity);
6088 }
6089 }
6090
6091 /**
6092 * Is E-UTRA-NR Dual Connectivity enabled
6093 * @return true if dual connectivity is enabled else false
6094 */
6095 @Override
6096 public boolean isNrDualConnectivityEnabled(int subId) {
6097 TelephonyPermissions
6098 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6099 mApp, subId, "isNRDualConnectivityEnabled");
6100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6101 final long identity = Binder.clearCallingIdentity();
6102 try {
6103 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6104 null, subId, workSource);
6105 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6106 return isEnabled;
6107 } finally {
6108 Binder.restoreCallingIdentity(identity);
6109 }
6110 }
6111
6112 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006113 * get carrier bandwidth per primary and secondary carrier
6114 * @param subId subscription id of the sim card
6115 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6116 */
6117 @Override
6118 public CarrierBandwidth getCarrierBandwidth(int subId) {
6119 TelephonyPermissions
6120 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6121 mApp, subId, "isNRDualConnectivityEnabled");
6122 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 CarrierBandwidth carrierBandwidth =
6126 getPhoneFromSubId(subId).getCarrierBandwidth();
6127 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6128 return carrierBandwidth;
6129 } finally {
6130 Binder.restoreCallingIdentity(identity);
6131 }
6132 }
6133
6134 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006135 * Set the allowed network types of the device and
6136 * provide the reason triggering the allowed network change.
6137 *
6138 * @param subId the id of the subscription.
6139 * @param reason the reason the allowed network type change is taking place
6140 * @param allowedNetworkTypes the allowed network types.
6141 * @return true on success; false on any failure.
6142 */
6143 @Override
6144 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006145 @TelephonyManager.AllowedNetworkTypesReason int reason,
6146 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6148 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006149 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6150 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6151 return false;
6152 }
6153
6154 if (DBG) {
6155 log("setAllowedNetworkTypesForReason: " + reason
6156 + " value: " + allowedNetworkTypes);
6157 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006158 final long identity = Binder.clearCallingIdentity();
6159 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006160 Boolean success = (Boolean) sendRequest(
6161 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6162 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6163
6164 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6165 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006166 } finally {
6167 Binder.restoreCallingIdentity(identity);
6168 }
6169 }
6170
6171 /**
Miaoa84611c2019-03-15 09:21:10 +08006172 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006173 *
Miaoa84611c2019-03-15 09:21:10 +08006174 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006175 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006176 * @hide
6177 */
6178 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006179 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006180 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006181 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006182 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006183 try {
Miaoa84611c2019-03-15 09:21:10 +08006184 if (phone != null) {
6185 return phone.hasMatchedTetherApnSetting();
6186 } else {
6187 return false;
6188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006189 } finally {
6190 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006191 }
Junda Liu475951f2014-11-07 16:45:03 -08006192 }
6193
6194 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006195 * Enable or disable always reporting signal strength changes from radio.
6196 *
6197 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6198 */
6199 @Override
6200 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6201 enforceModifyPermission();
6202 enforceSystemCaller();
6203
6204 final long identity = Binder.clearCallingIdentity();
6205 final Phone phone = getPhone(subId);
6206 try {
6207 if (phone != null) {
6208 if (DBG) {
6209 log("setAlwaysReportSignalStrength: subId=" + subId
6210 + " isEnable=" + isEnable);
6211 }
6212 phone.setAlwaysReportSignalStrength(isEnable);
6213 } else {
6214 loge("setAlwaysReportSignalStrength: no phone found for subId="
6215 + subId);
6216 }
6217 } finally {
6218 Binder.restoreCallingIdentity(identity);
6219 }
6220 }
6221
6222 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006223 * Get the user enabled state of Mobile Data.
6224 *
6225 * TODO: remove and use isUserDataEnabled.
6226 * This can't be removed now because some vendor codes
6227 * calls through ITelephony directly while they should
6228 * use TelephonyManager.
6229 *
6230 * @return true on enabled
6231 */
6232 @Override
6233 public boolean getDataEnabled(int subId) {
6234 return isUserDataEnabled(subId);
6235 }
6236
6237 /**
6238 * Get whether mobile data is enabled per user setting.
6239 *
6240 * There are other factors deciding whether mobile data is actually enabled, but they are
6241 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006242 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006243 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006244 *
6245 * @return {@code true} if data is enabled else {@code false}
6246 */
6247 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006248 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006249 try {
6250 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6251 null);
6252 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6254 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006255 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256
6257 final long identity = Binder.clearCallingIdentity();
6258 try {
6259 int phoneId = mSubscriptionController.getPhoneId(subId);
6260 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6261 Phone phone = PhoneFactory.getPhone(phoneId);
6262 if (phone != null) {
6263 boolean retVal = phone.isUserDataEnabled();
6264 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6265 return retVal;
6266 } else {
6267 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6268 return false;
6269 }
6270 } finally {
6271 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006272 }
6273 }
6274
6275 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006276 * Checks if the device is capable of mobile data by considering whether whether the
6277 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6278 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006279 *
Shuo Qian985d1232020-01-08 14:30:06 -08006280 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006281 */
6282 @Override
6283 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006284 try {
6285 try {
6286 mApp.enforceCallingOrSelfPermission(
6287 android.Manifest.permission.ACCESS_NETWORK_STATE,
6288 null);
6289 } catch (Exception e) {
6290 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6291 "isDataEnabled");
6292 }
6293 } catch (Exception e) {
6294 enforceReadPrivilegedPermission("isDataEnabled");
6295 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006296
6297 final long identity = Binder.clearCallingIdentity();
6298 try {
6299 int phoneId = mSubscriptionController.getPhoneId(subId);
6300 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6301 Phone phone = PhoneFactory.getPhone(phoneId);
6302 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006303 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006304 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6305 return retVal;
6306 } else {
6307 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6308 return false;
6309 }
6310 } finally {
6311 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006312 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006313 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006314
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006315 /**
6316 * Check if data is enabled for a specific reason
6317 * @param subId Subscription index
6318 * @param reason the reason the data enable change is taking place
6319 * @return {@code true} if the overall data is enabled; {@code false} if not.
6320 */
6321 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006322 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006323 @TelephonyManager.DataEnabledReason int reason) {
6324 try {
6325 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6326 null);
6327 } catch (Exception e) {
6328 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006329 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006330 }
6331
6332
6333 final long identity = Binder.clearCallingIdentity();
6334 try {
6335 int phoneId = mSubscriptionController.getPhoneId(subId);
6336 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006337 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006338 + " reason=" + reason);
6339 }
6340 Phone phone = PhoneFactory.getPhone(phoneId);
6341 if (phone != null) {
6342 boolean retVal;
6343 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6344 retVal = phone.isUserDataEnabled();
6345 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006346 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006347 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006348 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006349 return retVal;
6350 } else {
6351 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006352 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006353 + subId + " retVal=false");
6354 }
6355 return false;
6356 }
6357 } finally {
6358 Binder.restoreCallingIdentity(identity);
6359 }
6360 }
6361
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006362 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006363 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006364 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6365 // Skip the check if it's one of these special uids
6366 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6367 }
6368
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006369 //load access rules from carrier configs, and check those as well: b/139133814
6370 SubscriptionController subController = SubscriptionController.getInstance();
6371 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6372 || subController == null) return privilegeFromSim;
6373
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006374 PackageManager pkgMgr = phone.getContext().getPackageManager();
6375 String[] packages = pkgMgr.getPackagesForUid(uid);
6376
6377 final long identity = Binder.clearCallingIdentity();
6378 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006379 int subId = phone.getSubId();
6380 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6381 // A test override is in place for the privileges for this subId, so don't try to
6382 // read the subscription privileges.
6383 return privilegeFromSim;
6384 }
6385 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006386 SubscriptionManager subManager = (SubscriptionManager)
6387 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6388 for (String pkg : packages) {
6389 if (subManager.canManageSubscription(subInfo, pkg)) {
6390 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6391 }
6392 }
6393 return privilegeFromSim;
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
6397 }
6398
6399 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6400 String pkgName) {
6401 //load access rules from carrier configs, and check those as well: b/139133814
6402 SubscriptionController subController = SubscriptionController.getInstance();
6403 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6404 || subController == null) return privilegeFromSim;
6405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006408 int subId = phone.getSubId();
6409 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6410 // A test override is in place for the privileges for this subId, so don't try to
6411 // read the subscription privileges.
6412 return privilegeFromSim;
6413 }
6414 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006415 SubscriptionManager subManager = (SubscriptionManager)
6416 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6417 return subManager.canManageSubscription(subInfo, pkgName)
6418 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6419 } finally {
6420 Binder.restoreCallingIdentity(identity);
6421 }
6422 }
6423
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006424 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006425 public int getCarrierPrivilegeStatus(int subId) {
6426 final Phone phone = getPhone(subId);
6427 if (phone == null) {
6428 loge("getCarrierPrivilegeStatus: Invalid subId");
6429 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6430 }
6431 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006432 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006433 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6435 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006436
6437 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6438 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006439 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006440 }
Junda Liu29340342014-07-10 15:23:27 -07006441
6442 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006443 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006444 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006445 final Phone phone = getPhone(subId);
6446 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006447 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6449 }
6450 UiccProfile profile =
6451 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6452 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006453 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006454 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6455 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006456 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006457 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006458 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006459 }
6460
6461 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006462 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6463 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006464 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006465 }
6466
6467 int phoneId = SubscriptionManager.getPhoneId(subId);
6468 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006469 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006470 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006471 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6472 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006473 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6474 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6475 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006476 }
6477
6478 @Override
6479 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006480 if (TextUtils.isEmpty(pkgName))
6481 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006482 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6483 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6484 UiccCard card = UiccController.getInstance().getUiccCard(i);
6485 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006486 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006487 continue;
6488 }
6489
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006490 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6491 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6492 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006493 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6494 break;
6495 }
6496 }
6497
6498 return result;
Junda Liu29340342014-07-10 15:23:27 -07006499 }
Derek Tan89e89d42014-07-08 17:00:10 -07006500
6501 @Override
Junda Liue64de782015-04-16 17:19:16 -07006502 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6503 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6504 loge("phoneId " + phoneId + " is not valid.");
6505 return null;
6506 }
6507 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006508 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006509 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006510 return null ;
6511 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006512 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006513 }
6514
Amith Yamasani6e118872016-02-19 12:53:51 -08006515 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006516 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006517 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006518 List<String> privilegedPackages = new ArrayList<>();
6519 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006520 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6521 // has UICC in that slot.
6522 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006523 if (card.hasCarrierPrivilegeRules()) {
6524 if (packages == null) {
6525 // Only check packages in user 0 for now
6526 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006527 PackageManager.MATCH_DISABLED_COMPONENTS
6528 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006529 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006530 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006531 }
6532 for (int p = packages.size() - 1; p >= 0; p--) {
6533 PackageInfo pkgInfo = packages.get(p);
6534 if (pkgInfo != null && pkgInfo.packageName != null
6535 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006536 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006537 privilegedPackages.add(pkgInfo.packageName);
6538 }
6539 }
6540 }
6541 }
6542 return privilegedPackages;
6543 }
6544
chen xuf7e9fe82019-05-09 19:31:02 -07006545 @Override
6546 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006547 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6548
6549 final long identity = Binder.clearCallingIdentity();
6550
chen xuf7e9fe82019-05-09 19:31:02 -07006551 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006552 try {
6553 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6554 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6555 }
6556 } finally {
6557 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006558 }
6559 return privilegedPackages;
6560 }
6561
Wink Savilleb564aae2014-10-23 10:18:09 -07006562 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006563 final Phone phone = getPhone(subId);
6564 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006565 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006566 return null;
6567 }
6568 String iccId = card.getIccId();
6569 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006570 return null;
6571 }
6572 return iccId;
6573 }
6574
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006575 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006576 public void setCallComposerStatus(int subId, int status) {
6577 enforceModifyPermission();
6578
6579 final long identity = Binder.clearCallingIdentity();
6580 try {
6581 Phone phone = getPhone(subId);
6582 if (phone != null) {
6583 Phone defaultPhone = phone.getImsPhone();
6584 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6585 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6586 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006587 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6588 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006589 }
6590 }
Shuo Qiand8782462020-12-22 19:10:14 -08006591 } catch (ImsException e) {
6592 throw new ServiceSpecificException(e.getCode());
6593 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006594 Binder.restoreCallingIdentity(identity);
6595 }
6596 }
6597
6598 @Override
6599 public int getCallComposerStatus(int subId) {
6600 enforceReadPrivilegedPermission("getCallComposerStatus");
6601
6602 final long identity = Binder.clearCallingIdentity();
6603 try {
6604 Phone phone = getPhone(subId);
6605 if (phone != null) {
6606 Phone defaultPhone = phone.getImsPhone();
6607 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6608 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6609 return imsPhone.getCallComposerStatus();
6610 }
6611 }
6612 } finally {
6613 Binder.restoreCallingIdentity(identity);
6614 }
6615 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6616 }
6617
6618 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006619 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6620 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006621 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006622 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006623
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006624 final long identity = Binder.clearCallingIdentity();
6625 try {
6626 final String iccId = getIccId(subId);
6627 final Phone phone = getPhone(subId);
6628 if (phone == null) {
6629 return false;
6630 }
6631 final String subscriberId = phone.getSubscriberId();
6632
6633 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006634 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006635 + subscriberId + " to " + number);
6636 }
6637
6638 if (TextUtils.isEmpty(iccId)) {
6639 return false;
6640 }
6641
6642 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6643
6644 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6645 if (alphaTag == null) {
6646 editor.remove(alphaTagPrefKey);
6647 } else {
6648 editor.putString(alphaTagPrefKey, alphaTag);
6649 }
6650
6651 // Record both the line number and IMSI for this ICCID, since we need to
6652 // track all merged IMSIs based on line number
6653 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6654 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6655 if (number == null) {
6656 editor.remove(numberPrefKey);
6657 editor.remove(subscriberPrefKey);
6658 } else {
6659 editor.putString(numberPrefKey, number);
6660 editor.putString(subscriberPrefKey, subscriberId);
6661 }
6662
6663 editor.commit();
6664 return true;
6665 } finally {
6666 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006667 }
Derek Tan7226c842014-07-02 17:42:23 -07006668 }
6669
6670 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006671 public String getLine1NumberForDisplay(int subId, String callingPackage,
6672 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006673 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006674 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006675 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006676 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006677 return null;
6678 }
Derek Tan97ebb422014-09-05 16:55:38 -07006679
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 final long identity = Binder.clearCallingIdentity();
6681 try {
6682 String iccId = getIccId(subId);
6683 if (iccId != null) {
6684 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6685 if (DBG_MERGE) {
6686 log("getLine1NumberForDisplay returning "
6687 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6688 }
6689 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006690 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6692 return null;
6693 } finally {
6694 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006695 }
Derek Tan7226c842014-07-02 17:42:23 -07006696 }
6697
6698 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006699 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6700 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006701 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006702 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006703 return null;
6704 }
Derek Tan97ebb422014-09-05 16:55:38 -07006705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006706 final long identity = Binder.clearCallingIdentity();
6707 try {
6708 String iccId = getIccId(subId);
6709 if (iccId != null) {
6710 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6711 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6712 }
6713 return null;
6714 } finally {
6715 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006716 }
Derek Tan7226c842014-07-02 17:42:23 -07006717 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006718
6719 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006720 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6721 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006722 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6723 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006724 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006725 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006726 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006727 return null;
6728 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006729
Jordan Liub49b04b2019-05-06 14:45:15 -07006730 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6731 // the process, where TelephonyManager was instantiated.
6732 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006733 final long identity = Binder.clearCallingIdentity();
6734 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006735 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 final TelephonyManager tele = TelephonyManager.from(context);
6737 final SubscriptionManager sub = SubscriptionManager.from(context);
6738
6739 // Figure out what subscribers are currently active
6740 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741
Jordan Liub49b04b2019-05-06 14:45:15 -07006742 // Only consider subs which match the current subId
6743 // This logic can be simplified. See b/131189269 for progress.
6744 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006745 activeSubscriberIds.add(tele.getSubscriberId(subId));
6746 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006747
6748 // First pass, find a number override for an active subscriber
6749 String mergeNumber = null;
6750 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6751 for (String key : prefs.keySet()) {
6752 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6753 final String subscriberId = (String) prefs.get(key);
6754 if (activeSubscriberIds.contains(subscriberId)) {
6755 final String iccId = key.substring(
6756 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6757 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6758 mergeNumber = (String) prefs.get(numberKey);
6759 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006760 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006761 + " for active subscriber " + subscriberId);
6762 }
6763 if (!TextUtils.isEmpty(mergeNumber)) {
6764 break;
6765 }
6766 }
6767 }
6768 }
6769
6770 // Shortcut when no active merged subscribers
6771 if (TextUtils.isEmpty(mergeNumber)) {
6772 return null;
6773 }
6774
6775 // Second pass, find all subscribers under that line override
6776 final ArraySet<String> result = new ArraySet<>();
6777 for (String key : prefs.keySet()) {
6778 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6779 final String number = (String) prefs.get(key);
6780 if (mergeNumber.equals(number)) {
6781 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6782 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6783 final String subscriberId = (String) prefs.get(subscriberKey);
6784 if (!TextUtils.isEmpty(subscriberId)) {
6785 result.add(subscriberId);
6786 }
6787 }
6788 }
6789 }
6790
6791 final String[] resultArray = result.toArray(new String[result.size()]);
6792 Arrays.sort(resultArray);
6793 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006794 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006795 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6796 }
6797 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006798 } finally {
6799 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006800 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006801 }
6802
6803 @Override
zoey chen38003472019-12-13 17:16:31 +08006804 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6805 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006806
6807 final long identity = Binder.clearCallingIdentity();
6808 try {
6809 final TelephonyManager telephonyManager = mApp.getSystemService(
6810 TelephonyManager.class);
6811 String subscriberId = telephonyManager.getSubscriberId(subId);
6812 if (subscriberId == null) {
6813 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006814 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006815 + subId);
6816 }
6817 return null;
6818 }
6819
6820 final SubscriptionInfo info = SubscriptionController.getInstance()
6821 .getSubscriptionInfo(subId);
6822 final ParcelUuid groupUuid = info.getGroupUuid();
6823 // If it doesn't belong to any group, return just subscriberId of itself.
6824 if (groupUuid == null) {
6825 return new String[]{subscriberId};
6826 }
6827
6828 // Get all subscriberIds from the group.
6829 final List<String> mergedSubscriberIds = new ArrayList<>();
6830 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006831 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006832 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006833 for (SubscriptionInfo subInfo : groupInfos) {
6834 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6835 if (subscriberId != null) {
6836 mergedSubscriberIds.add(subscriberId);
6837 }
6838 }
6839
6840 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6841 } finally {
6842 Binder.restoreCallingIdentity(identity);
6843
6844 }
6845 }
6846
6847 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006848 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006849 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006850 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851
6852 final long identity = Binder.clearCallingIdentity();
6853 try {
6854 final Phone phone = getPhone(subId);
6855 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6856 } finally {
6857 Binder.restoreCallingIdentity(identity);
6858 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006859 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006860
6861 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006862 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006863 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6864 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006865 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6866 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 final Phone phone = getPhone(subId);
6871 if (phone == null) {
6872 return false;
6873 }
6874 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6875 cdmaNonRoamingList);
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006878 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006879 }
6880
6881 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006882 @Deprecated
6883 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6884 enforceModifyPermission();
6885
6886 int returnValue = 0;
6887 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006888 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006889 if(result.exception == null) {
6890 if (result.result != null) {
6891 byte[] responseData = (byte[])(result.result);
6892 if(responseData.length > oemResp.length) {
6893 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6894 responseData.length + "bytes. Buffer Size is " +
6895 oemResp.length + "bytes.");
6896 }
6897 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6898 returnValue = responseData.length;
6899 }
6900 } else {
6901 CommandException ex = (CommandException) result.exception;
6902 returnValue = ex.getCommandError().ordinal();
6903 if(returnValue > 0) returnValue *= -1;
6904 }
6905 } catch (RuntimeException e) {
6906 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6907 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6908 if(returnValue > 0) returnValue *= -1;
6909 }
6910
6911 return returnValue;
6912 }
6913
6914 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006915 public void setRadioCapability(RadioAccessFamily[] rafs) {
6916 try {
6917 ProxyController.getInstance().setRadioCapability(rafs);
6918 } catch (RuntimeException e) {
6919 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6920 }
6921 }
6922
6923 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006924 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006925 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006926 try {
6927 TelephonyPermissions
6928 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6929 mApp, phone.getSubId(), "getRadioAccessFamily");
6930 } catch (SecurityException e) {
6931 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6932 throw e;
6933 }
chen xub97461a2018-10-26 14:17:57 -07006934 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006935 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006936 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006937 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006938 final long identity = Binder.clearCallingIdentity();
6939 try {
chen xub97461a2018-10-26 14:17:57 -07006940 TelephonyPermissions
6941 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6942 mApp, phone.getSubId(), "getRadioAccessFamily");
6943 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944 } finally {
6945 Binder.restoreCallingIdentity(identity);
6946 }
chen xub97461a2018-10-26 14:17:57 -07006947 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006948 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006949
6950 @Override
6951 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006952 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006953 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006954
6955 final long identity = Binder.clearCallingIdentity();
6956 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006957 ImsManager.getInstance(defaultPhone.getContext(),
6958 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 } finally {
6960 Binder.restoreCallingIdentity(identity);
6961 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006962 }
6963
6964 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006965 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006966 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006967 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6968 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006969 return false;
6970 }
Svet Ganovb320e182015-04-16 12:30:10 -07006971
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 final long identity = Binder.clearCallingIdentity();
6973 try {
6974 // Check the user preference and the system-level IMS setting. Even if the user has
6975 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6976 // In the long run, we may instead need to check if there exists a connection service
6977 // which can support video calling.
6978 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006979 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006980 return imsManager.isVtEnabledByPlatform()
6981 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6982 && imsManager.isVtEnabledByUser();
6983 } finally {
6984 Binder.restoreCallingIdentity(identity);
6985 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006986 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006987
Andrew Leea1239f22015-03-02 17:44:07 -08006988 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006989 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6990 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006991 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006992 mApp, subId, callingPackage, callingFeatureId,
6993 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 return false;
6995 }
6996
6997 final long identity = Binder.clearCallingIdentity();
6998 try {
6999 CarrierConfigManager configManager =
7000 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007001 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7003 } finally {
7004 Binder.restoreCallingIdentity(identity);
7005 }
Andrew Leea1239f22015-03-02 17:44:07 -08007006 }
7007
7008 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007009 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007011 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 return false;
7013 }
7014
7015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 CarrierConfigManager configManager =
7018 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007019 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
7023 }
Andrew Leea1239f22015-03-02 17:44:07 -08007024 }
7025
Andrew Lee9431b832015-03-09 18:46:45 -07007026 @Override
7027 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007028 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007029 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007030 }
7031
7032 @Override
7033 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007034 final long identity = Binder.clearCallingIdentity();
7035 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007036 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007037 } finally {
7038 Binder.restoreCallingIdentity(identity);
7039 }
Andrew Lee9431b832015-03-09 18:46:45 -07007040 }
7041
Hall Liuf6668912018-10-31 17:05:23 -07007042 /**
7043 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7044 * support for the feature and device firmware support.
7045 *
7046 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7047 */
7048 @Override
7049 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007051 final Phone phone = getPhone(subscriptionId);
7052 if (phone == null) {
7053 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7054 return false;
7055 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007057 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007058 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7059 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007060 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007061 return isCarrierSupported && isDeviceSupported;
7062 } finally {
7063 Binder.restoreCallingIdentity(identity);
7064 }
Hall Liu98187582018-01-22 19:15:32 -08007065 }
7066
Hall Liuf6668912018-10-31 17:05:23 -07007067 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007068 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7069 * RTT setting, will return true if the device and carrier both support RTT.
7070 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007071 */
7072 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 final long identity = Binder.clearCallingIdentity();
7074 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007075 boolean isRttSupported = isRttSupported(subscriptionId);
7076 boolean isUserRttSettingOn = Settings.Secure.getInt(
7077 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7078 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7079 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7080 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 } finally {
7082 Binder.restoreCallingIdentity(identity);
7083 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007084 }
7085
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007086 @Deprecated
7087 @Override
7088 public String getDeviceId(String callingPackage) {
7089 return getDeviceIdWithFeature(callingPackage, null);
7090 }
7091
Sanket Padawe7310cc72015-01-14 09:53:20 -08007092 /**
7093 * Returns the unique device ID of phone, for example, the IMEI for
7094 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7095 *
7096 * <p>Requires Permission:
7097 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7098 */
7099 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007100 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007101 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007102 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007103 return null;
7104 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007105 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007106 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007107 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007108 return null;
7109 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007110
7111 final long identity = Binder.clearCallingIdentity();
7112 try {
7113 return phone.getDeviceId();
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
7116 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007117 }
7118
Ping Sunc67b7c22016-03-02 19:16:45 +08007119 /**
7120 * {@hide}
7121 * Returns the IMS Registration Status on a particular subid
7122 *
7123 * @param subId
7124 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007125 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007126 Phone phone = getPhone(subId);
7127 if (phone != null) {
7128 return phone.isImsRegistered();
7129 } else {
7130 return false;
7131 }
7132 }
7133
Santos Cordon7a1885b2015-02-03 11:15:19 -08007134 @Override
7135 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136 final long identity = Binder.clearCallingIdentity();
7137 try {
7138 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7139 } finally {
7140 Binder.restoreCallingIdentity(identity);
7141 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007142 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007143
Tyler Gunnf70ed162019-04-03 15:28:53 -07007144 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007145 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007146 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007147 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007148 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007149 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7150 }
7151 final long identity = Binder.clearCallingIdentity();
7152 try {
7153 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7154 } finally {
7155 Binder.restoreCallingIdentity(identity);
7156 }
7157 }
7158
7159 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007160 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007161 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7162 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007163 final long identity = Binder.clearCallingIdentity();
7164 try {
7165 Phone phone = getPhone(subscriptionId);
7166 if (phone == null) {
7167 return null;
7168 }
7169 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7170 } finally {
7171 Binder.restoreCallingIdentity(identity);
7172 }
7173 }
7174
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007175 /**
7176 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007177 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007178 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007179 final long identity = Binder.clearCallingIdentity();
7180 try {
7181 Phone phone = getPhone(subId);
7182 if (phone != null) {
7183 return phone.isWifiCallingEnabled();
7184 } else {
7185 return false;
7186 }
7187 } finally {
7188 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007190 }
7191
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007192 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007193 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007194 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007195 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007196 final long identity = Binder.clearCallingIdentity();
7197 try {
7198 Phone phone = getPhone(subId);
7199 if (phone != null) {
7200 return phone.isVideoEnabled();
7201 } else {
7202 return false;
7203 }
7204 } finally {
7205 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007206 }
7207 }
7208
7209 /**
7210 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7211 * defined in {@link ImsRegistrationImplBase}.
7212 */
7213 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 final long identity = Binder.clearCallingIdentity();
7215 try {
7216 Phone phone = getPhone(subId);
7217 if (phone != null) {
7218 return phone.getImsRegistrationTech();
7219 } else {
7220 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7221 }
7222 } finally {
7223 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007224 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007225 }
7226
Stuart Scott8eef64f2015-04-08 15:13:54 -07007227 @Override
7228 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007229 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007230 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7231 return;
7232 }
7233
Svet Ganovcc087f82015-05-12 20:35:54 -07007234 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235
Svet Ganovcc087f82015-05-12 20:35:54 -07007236 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007237 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7238 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007239 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007240 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007241 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007242 setAllowedNetworkTypesForReason(subId,
7243 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7244 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7245 setAllowedNetworkTypesForReason(subId,
7246 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7247 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7248 setAllowedNetworkTypesForReason(subId,
7249 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7250 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007251 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7252 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007253 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007254 // There has been issues when Sms raw table somehow stores orphan
7255 // fragments. They lead to garbled message when new fragments come
7256 // in and combined with those stale ones. In case this happens again,
7257 // user can reset all network settings which will clean up this table.
7258 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007259 // Clean up IMS settings as well here.
7260 int slotId = getSlotIndex(subId);
7261 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7262 ImsManager.getInstance(mApp, slotId).factoryReset();
7263 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007264
7265 // Erase modem config if erase modem on network setting is enabled.
7266 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7267 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7268 if (configValue != null && Boolean.parseBoolean(configValue)) {
7269 sendEraseModemConfig(getDefaultPhone());
7270 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007273 }
7274 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007275
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007276 private void cleanUpSmsRawTable(Context context) {
7277 ContentResolver resolver = context.getContentResolver();
7278 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7279 resolver.delete(uri, null, null);
7280 }
7281
Narayan Kamath1c496c22015-04-16 14:40:19 +01007282 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007283 public String getSimLocaleForSubscriber(int subId) {
7284 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7285 final Phone phone = getPhone(subId);
7286 if (phone == null) {
7287 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007288 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 final long identity = Binder.clearCallingIdentity();
7291 try {
chen xu5d3637b2019-01-21 23:31:38 -08007292 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007293 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007294 if (info == null) {
7295 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7296 return null;
7297 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007298 // Try and fetch the locale from the carrier properties or from the SIM language
7299 // preferences (EF-PL and EF-LI)...
7300 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007301 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007302 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7303 if (localeFromDefaultSim != null) {
7304 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7305 if (DBG) log("Using locale from subId: " + subId + " locale: "
7306 + localeFromDefaultSim);
7307 return localeFromDefaultSim.toLanguageTag();
7308 } else {
7309 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 }
7311 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007312
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007313 // The SIM language preferences only store a language (e.g. fr = French), not an
7314 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7315 // the SIM and carrier preferences does not include a country we add the country
7316 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007317 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007319 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007320 return mccLocale.toLanguageTag();
7321 }
7322
7323 if (DBG) log("No locale found - returning null");
7324 return null;
7325 } finally {
7326 Binder.restoreCallingIdentity(identity);
7327 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007328 }
7329
7330 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007331 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007332 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007333 }
7334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007335 /**
7336 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7337 */
7338 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007339 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007340 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007341 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007342
Chenjie Yu1ba97252018-01-11 18:16:20 -08007343 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007344 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007345
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007346 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007347 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7348 * representing the state of the modem.
7349 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007350 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7351 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007352 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007353 */
7354 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007355 public void requestModemActivityInfo(ResultReceiver result) {
7356 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007357 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358
7359 final long identity = Binder.clearCallingIdentity();
7360 try {
sqian1a1be542020-03-05 11:37:28 -08007361 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007362 } finally {
7363 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007364 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007365 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007366
Siddharth Rayb8114062018-06-17 15:02:38 -07007367 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7368 // less than total activity duration.
7369 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7370 if (info == null) {
7371 return false;
7372 }
7373 int activityDurationMs =
7374 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7375 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007376 int[] txTimeMs = info.getTransmitTimeMillis();
7377 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7378 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007379 }
7380 return (info.isValid()
7381 && (info.getSleepTimeMillis() <= activityDurationMs)
7382 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007383 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007384 && (totalTxTimeMs <= activityDurationMs));
7385 }
7386
Jack Yu85bd38a2015-11-09 11:34:32 -08007387 /**
7388 * {@hide}
7389 * Returns the service state information on specified subscription.
7390 */
7391 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007392 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7393 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007394 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007395 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007396 return null;
7397 }
7398
Hall Liuf19c44f2018-11-27 14:38:17 -08007399 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7400 LocationAccessPolicy.checkLocationPermission(mApp,
7401 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7402 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007403 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007404 .setCallingPid(Binder.getCallingPid())
7405 .setCallingUid(Binder.getCallingUid())
7406 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007407 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7409 .build());
7410
7411 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7412 LocationAccessPolicy.checkLocationPermission(mApp,
7413 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7414 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007415 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007416 .setCallingPid(Binder.getCallingPid())
7417 .setCallingUid(Binder.getCallingUid())
7418 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007419 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007420 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7421 .build());
7422 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7423 boolean hasFinePermission =
7424 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7425 boolean hasCoarsePermission =
7426 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 final long identity = Binder.clearCallingIdentity();
7429 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007430 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7431 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7432 Rlog.d(LOG_TAG,
7433 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7434 return null;
7435 }
7436
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007437 final Phone phone = getPhone(subId);
7438 if (phone == null) {
7439 return null;
7440 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007441
Hall Liuf19c44f2018-11-27 14:38:17 -08007442 ServiceState ss = phone.getServiceState();
7443
7444 // Scrub out the location info in ServiceState depending on what level of access
7445 // the caller has.
7446 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007447 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7448 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007449 } finally {
7450 Binder.restoreCallingIdentity(identity);
7451 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007452 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007453
7454 /**
7455 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7456 *
7457 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7458 * voicemail ringtone.
7459 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7460 * PhoneAccount.
7461 */
7462 @Override
7463 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007464 final long identity = Binder.clearCallingIdentity();
7465 try {
7466 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7467 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007468 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007469 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007470
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007471 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7472 } finally {
7473 Binder.restoreCallingIdentity(identity);
7474 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007475 }
7476
7477 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007478 * Sets the per-account voicemail ringtone.
7479 *
7480 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7481 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7482 *
7483 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7484 * voicemail ringtone.
7485 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7486 * PhoneAccount.
7487 */
7488 @Override
7489 public void setVoicemailRingtoneUri(String callingPackage,
7490 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007491 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007492 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007493 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7494 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7496 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7497 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007498 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007499
7500 final long identity = Binder.clearCallingIdentity();
7501 try {
7502 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7503 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007504 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007505 }
7506 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7507 } finally {
7508 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007509 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007510 }
7511
7512 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007513 * Returns whether vibration is set for voicemail notification in Phone settings.
7514 *
7515 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7516 * voicemail vibration setting.
7517 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7518 */
7519 @Override
7520 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007521 final long identity = Binder.clearCallingIdentity();
7522 try {
7523 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7524 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007525 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007526 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007532 }
7533
Youhan Wange64578a2016-05-02 15:32:42 -07007534 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007535 * Sets the per-account voicemail vibration.
7536 *
7537 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7538 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7539 *
7540 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7541 * voicemail vibration setting.
7542 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7543 * specific PhoneAccount.
7544 */
7545 @Override
7546 public void setVoicemailVibrationEnabled(String callingPackage,
7547 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007548 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007549 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007550 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7551 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007552 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7553 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7554 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007555 }
7556
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 final long identity = Binder.clearCallingIdentity();
7558 try {
7559 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7560 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007561 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 }
7563 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7564 } finally {
7565 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007566 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007567 }
7568
7569 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007570 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7571 *
7572 * @throws SecurityException if the caller does not have the required permission
7573 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007574 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007575 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007576 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007577 }
7578
7579 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007580 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7581 * permission.
7582 *
7583 * @throws SecurityException if the caller does not have the required permission
7584 */
7585 private void enforceSendSmsPermission() {
7586 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7587 }
7588
7589 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007590 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007591 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007592 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007593 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007594 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 final long identity = Binder.clearCallingIdentity();
7596 try {
7597 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007598 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007599 if (componentName == null) {
7600 throw new SecurityException(
7601 "Caller not current active visual voicemail package[null]");
7602 }
7603 String vvmPackage = componentName.getPackageName();
7604 if (!callingPackage.equals(vvmPackage)) {
7605 throw new SecurityException("Caller not current active visual voicemail package["
7606 + vvmPackage + "]");
7607 }
7608 } finally {
7609 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007610 }
7611 }
7612
7613 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007614 * Return the application ID for the app type.
7615 *
7616 * @param subId the subscription ID that this request applies to.
7617 * @param appType the uicc app type.
7618 * @return Application ID for specificied app type, or null if no uicc.
7619 */
7620 @Override
7621 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007622 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007623 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624
7625 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007626 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007627 if (phone == null) {
7628 return null;
7629 }
7630 String aid = null;
7631 try {
7632 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7633 .getApplicationByType(appType).getAid();
7634 } catch (Exception e) {
7635 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7636 }
7637 return aid;
7638 } finally {
7639 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007640 }
Youhan Wange64578a2016-05-02 15:32:42 -07007641 }
7642
Youhan Wang4001d252016-05-11 10:29:41 -07007643 /**
7644 * Return the Electronic Serial Number.
7645 *
7646 * @param subId the subscription ID that this request applies to.
7647 * @return ESN or null if error.
7648 */
7649 @Override
7650 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007651 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007652 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007653
7654 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007655 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007656 if (phone == null) {
7657 return null;
7658 }
7659 String esn = null;
7660 try {
7661 esn = phone.getEsn();
7662 } catch (Exception e) {
7663 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7664 }
7665 return esn;
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007668 }
Youhan Wang4001d252016-05-11 10:29:41 -07007669 }
7670
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007671 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007672 * Return the Preferred Roaming List Version.
7673 *
7674 * @param subId the subscription ID that this request applies to.
7675 * @return PRLVersion or null if error.
7676 */
7677 @Override
7678 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007679 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007680 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007681
7682 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007683 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007684 if (phone == null) {
7685 return null;
7686 }
7687 String cdmaPrlVersion = null;
7688 try {
7689 cdmaPrlVersion = phone.getCdmaPrlVersion();
7690 } catch (Exception e) {
7691 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7692 }
7693 return cdmaPrlVersion;
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007696 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007697 }
7698
7699 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007700 * Get snapshot of Telephony histograms
7701 * @return List of Telephony histograms
7702 * @hide
7703 */
7704 @Override
7705 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007706 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7707 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708
7709 final long identity = Binder.clearCallingIdentity();
7710 try {
7711 return RIL.getTelephonyRILTimingHistograms();
7712 } finally {
7713 Binder.restoreCallingIdentity(identity);
7714 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007715 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007716
7717 /**
7718 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007719 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7720 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007721 * Require system privileges. In the future we may add this to carrier APIs.
7722 *
Michele Berionne482f8202018-11-27 18:57:59 -08007723 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007724 */
7725 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007726 @TelephonyManager.SetCarrierRestrictionResult
7727 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007728 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007729 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007730
Michele Berionne482f8202018-11-27 18:57:59 -08007731 if (carrierRestrictionRules == null) {
7732 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007733 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 final long identity = Binder.clearCallingIdentity();
7736 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007737 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007738 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007739 } finally {
7740 Binder.restoreCallingIdentity(identity);
7741 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007742 }
7743
7744 /**
7745 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007746 * Get the allowed carrier list and the excluded carrier list, including the priority between
7747 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007748 * Require system privileges. In the future we may add this to carrier APIs.
7749 *
Michele Berionne482f8202018-11-27 18:57:59 -08007750 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007751 */
7752 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007753 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007754 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007756
7757 final long identity = Binder.clearCallingIdentity();
7758 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007759 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7760 if (response instanceof CarrierRestrictionRules) {
7761 return (CarrierRestrictionRules) response;
7762 }
7763 // Response is an Exception of some kind,
7764 // which is signalled to the user as a NULL retval
7765 return null;
7766 } catch (Exception e) {
7767 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7768 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007769 } finally {
7770 Binder.restoreCallingIdentity(identity);
7771 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007772 }
7773
fionaxu59545b42016-05-25 15:53:37 -07007774 /**
fionaxu59545b42016-05-25 15:53:37 -07007775 * Action set from carrier signalling broadcast receivers to enable/disable radio
7776 * @param subId the subscription ID that this action applies to.
7777 * @param enabled control enable or disable radio.
7778 * {@hide}
7779 */
7780 @Override
7781 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7782 enforceModifyPermission();
7783 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784
7785 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007786 if (phone == null) {
7787 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7788 return;
7789 }
7790 try {
7791 phone.carrierActionSetRadioEnabled(enabled);
7792 } catch (Exception e) {
7793 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007794 } finally {
7795 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007796 }
7797 }
7798
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007799 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007800 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7801 * network status based on which carrier apps could apply actions accordingly,
7802 * enable/disable default url handler for example.
7803 *
7804 * @param subId the subscription ID that this action applies to.
7805 * @param report control start/stop reporting the default network status.
7806 * {@hide}
7807 */
7808 @Override
7809 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7810 enforceModifyPermission();
7811 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812
7813 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007814 if (phone == null) {
7815 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7816 return;
7817 }
7818 try {
7819 phone.carrierActionReportDefaultNetworkStatus(report);
7820 } catch (Exception e) {
7821 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 } finally {
7823 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007824 }
7825 }
7826
7827 /**
fionaxud9622282017-07-17 17:51:30 -07007828 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7829 * @param subId the subscription ID that this action applies to.
7830 * {@hide}
7831 */
7832 @Override
7833 public void carrierActionResetAll(int subId) {
7834 enforceModifyPermission();
7835 final Phone phone = getPhone(subId);
7836 if (phone == null) {
7837 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7838 return;
7839 }
7840 try {
7841 phone.carrierActionResetAll();
7842 } catch (Exception e) {
7843 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7844 }
7845 }
7846
7847 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007848 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7849 * bug report is being generated.
7850 */
7851 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007852 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007853 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7854 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007855 writer.println("Permission Denial: can't dump Phone from pid="
7856 + Binder.getCallingPid()
7857 + ", uid=" + Binder.getCallingUid()
7858 + "without permission "
7859 + android.Manifest.permission.DUMP);
7860 return;
7861 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007862 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007863 }
Jack Yueb89b242016-06-22 13:27:47 -07007864
Brad Ebingerdac2f002018-04-03 15:17:52 -07007865 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007866 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7867 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7868 @NonNull String[] args) {
7869 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7870 this, in.getFileDescriptor(), out.getFileDescriptor(),
7871 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007872 }
7873
Jack Yueb89b242016-06-22 13:27:47 -07007874 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007875 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007876 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007877 * @param reason the reason the data enable change is taking place
7878 * @param enabled True if enabling the data, otherwise disabling.
7879 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007880 */
7881 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007882 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007883 boolean enabled) {
7884 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7885 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7886 try {
7887 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007888 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007889 } catch (SecurityException se) {
7890 enforceModifyPermission();
7891 }
7892 } else {
7893 enforceModifyPermission();
7894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895
7896 final long identity = Binder.clearCallingIdentity();
7897 try {
7898 Phone phone = getPhone(subId);
7899 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007900 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7901 phone.carrierActionSetMeteredApnsEnabled(enabled);
7902 } else {
7903 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7904 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007905 }
7906 } finally {
7907 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007908 }
7909 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007910
7911 /**
7912 * Get Client request stats
7913 * @return List of Client Request Stats
7914 * @hide
7915 */
7916 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007917 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7918 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007920 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007921 return null;
7922 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007923 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007924
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007925 final long identity = Binder.clearCallingIdentity();
7926 try {
7927 if (phone != null) {
7928 return phone.getClientRequestStats();
7929 }
7930
7931 return null;
7932 } finally {
7933 Binder.restoreCallingIdentity(identity);
7934 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007935 }
7936
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007937 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007938 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007939 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007940 }
Jack Yueb4124c2017-02-16 15:32:43 -08007941
7942 /**
Grace Chen70990072017-03-24 17:21:30 -07007943 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007944 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007945 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007946 * @param state State of SIM (power down, power up, pass through)
7947 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7948 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7949 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007950 *
7951 **/
7952 @Override
Grace Chen70990072017-03-24 17:21:30 -07007953 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007954 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007955 Phone phone = PhoneFactory.getPhone(slotIndex);
7956
vagdeviaf9a5b92018-08-15 16:01:53 -07007957 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7958
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007962 phone.setSimPowerState(state, null, workSource);
7963 }
7964 } finally {
7965 Binder.restoreCallingIdentity(identity);
7966 }
7967 }
7968
7969 /**
7970 * Set SIM card power state.
7971 *
7972 * @param slotIndex SIM slot id.
7973 * @param state State of SIM (power down, power up, pass through)
7974 * @param callback callback to trigger after success or failure
7975 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7976 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7978 *
7979 **/
7980 @Override
7981 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7982 IIntegerConsumer callback) {
7983 enforceModifyPermission();
7984 Phone phone = PhoneFactory.getPhone(slotIndex);
7985
7986 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7987
7988 final long identity = Binder.clearCallingIdentity();
7989 try {
7990 if (phone != null) {
7991 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7992 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007993 }
7994 } finally {
7995 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007996 }
7997 }
Shuo Qiandd210312017-04-12 22:11:33 +00007998
Tyler Gunn65d45c22017-06-05 11:22:26 -07007999 private boolean isUssdApiAllowed(int subId) {
8000 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008001 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008002 if (configManager == null) {
8003 return false;
8004 }
8005 PersistableBundle pb = configManager.getConfigForSubId(subId);
8006 if (pb == null) {
8007 return false;
8008 }
8009 return pb.getBoolean(
8010 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8011 }
8012
Shuo Qiandd210312017-04-12 22:11:33 +00008013 /**
8014 * Check if phone is in emergency callback mode
8015 * @return true if phone is in emergency callback mode
8016 * @param subId sub id
8017 */
goneil9c5f4872017-12-05 14:07:56 -08008018 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008019 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008020 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008021 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008022
8023 final long identity = Binder.clearCallingIdentity();
8024 try {
8025 if (phone != null) {
8026 return phone.isInEcm();
8027 } else {
8028 return false;
8029 }
8030 } finally {
8031 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008032 }
8033 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008034
8035 /**
8036 * Get the current signal strength information for the given subscription.
8037 * Because this information is not updated when the device is in a low power state
8038 * it should not be relied-upon to be current.
8039 * @param subId Subscription index
8040 * @return the most recent cached signal strength info from the modem
8041 */
8042 @Override
8043 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008044 final long identity = Binder.clearCallingIdentity();
8045 try {
8046 Phone p = getPhone(subId);
8047 if (p == null) {
8048 return null;
8049 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008051 return p.getSignalStrength();
8052 } finally {
8053 Binder.restoreCallingIdentity(identity);
8054 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008055 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008056
Pengquan Meng77b7f132018-08-22 14:49:57 -07008057 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008058 * Get the current modem radio state for the given slot.
8059 * @param slotIndex slot index.
8060 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008061 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008062 * @return the current radio power state from the modem
8063 */
8064 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008065 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008066 Phone phone = PhoneFactory.getPhone(slotIndex);
8067 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008068 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8069 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008070 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8071 }
8072
8073 final long identity = Binder.clearCallingIdentity();
8074 try {
8075 return phone.getRadioPowerState();
8076 } finally {
8077 Binder.restoreCallingIdentity(identity);
8078 }
8079 }
8080 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8081 }
8082
8083 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008084 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8085 *
8086 * <p>Requires one of the following permissions:
8087 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8088 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8089 * privileges.
8090 *
8091 * @param subId subscription id
8092 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8093 * {@code false}.
8094 */
8095 @Override
8096 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008097 try {
8098 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8099 null);
8100 } catch (Exception e) {
8101 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8102 mApp, subId, "isDataRoamingEnabled");
8103 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008104
Pengquan Menga1bb6272018-09-06 09:59:22 -07008105 boolean isEnabled = false;
8106 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008107 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008108 Phone phone = getPhone(subId);
8109 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008110 } finally {
8111 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008112 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008113 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008114 }
8115
8116
8117 /**
8118 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8119 *
8120 * <p> Requires permission:
8121 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8122 * privileges.
8123 *
8124 * @param subId subscription id
8125 * @param isEnabled {@code true} means enable, {@code false} means disable.
8126 */
8127 @Override
8128 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008129 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8130 mApp, subId, "setDataRoamingEnabled");
8131
Pengquan Menga1bb6272018-09-06 09:59:22 -07008132 final long identity = Binder.clearCallingIdentity();
8133 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008134 Phone phone = getPhone(subId);
8135 if (phone != null) {
8136 phone.setDataRoamingEnabled(isEnabled);
8137 }
8138 } finally {
8139 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008140 }
8141 }
8142
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008143 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008144 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008145 TelephonyPermissions
8146 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008147 mApp, subId, "isManualNetworkSelectionAllowed");
8148
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008149 boolean isAllowed = true;
8150 final long identity = Binder.clearCallingIdentity();
8151 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008152 Phone phone = getPhone(subId);
8153 if (phone != null) {
8154 isAllowed = phone.isCspPlmnEnabled();
8155 }
8156 } finally {
8157 Binder.restoreCallingIdentity(identity);
8158 }
8159 return isAllowed;
8160 }
8161
8162 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008163 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008164 // Verify that tha callingPackage belongs to the calling UID
8165 mApp.getSystemService(AppOpsManager.class)
8166 .checkPackage(Binder.getCallingUid(), callingPackage);
8167
Jordan Liu1e142fc2019-04-22 15:10:43 -07008168 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008169 try {
8170 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008171 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008172 } catch (SecurityException e) {
8173 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8174 // has carrier privileges on an active UICC
8175 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8176 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008177 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008178 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008179 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008180
8181 final long identity = Binder.clearCallingIdentity();
8182 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008183 UiccController uiccController = UiccController.getInstance();
8184 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008185 if (hasReadPermission) {
8186 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008187 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008188
8189 // Remove private info if the caller doesn't have access
8190 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8191 for (UiccCardInfo cardInfo : cardInfos) {
8192 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8193 // is available
8194 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8195 if (card == null || card.getUiccProfile() == null) {
8196 // assume no access if the card or profile is unavailable
8197 filteredInfos.add(cardInfo.getUnprivileged());
8198 continue;
8199 }
8200 UiccProfile profile = card.getUiccProfile();
8201 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8202 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8203 filteredInfos.add(cardInfo);
8204 } else {
8205 filteredInfos.add(cardInfo.getUnprivileged());
8206 }
8207 }
8208 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 }
8213
8214 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008215 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008216 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8221 if (slots == null) {
8222 Rlog.i(LOG_TAG, "slots is null.");
8223 return null;
8224 }
8225
8226 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8227 for (int i = 0; i < slots.length; i++) {
8228 UiccSlot slot = slots[i];
8229 if (slot == null) {
8230 continue;
8231 }
8232
Jordan Liu7be7e652019-05-06 18:55:02 +00008233 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 UiccCard card = slot.getUiccCard();
8235 if (card != null) {
8236 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008237 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008238 cardId = slot.getEid();
8239 if (TextUtils.isEmpty(cardId)) {
8240 cardId = slot.getIccId();
8241 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 }
8243
Jordan Liu857451f2019-05-09 16:35:35 -07008244 if (cardId != null) {
8245 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8246 // if cardId is an EID, it's all digits so this is fine
8247 cardId = IccUtils.stripTrailingFs(cardId);
8248 }
8249
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008250 int cardState = 0;
8251 switch (slot.getCardState()) {
8252 case CARDSTATE_ABSENT:
8253 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8254 break;
8255 case CARDSTATE_PRESENT:
8256 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8257 break;
8258 case CARDSTATE_ERROR:
8259 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8260 break;
8261 case CARDSTATE_RESTRICTED:
8262 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8263 break;
8264 default:
8265 break;
8266
8267 }
8268
8269 infos[i] = new UiccSlotInfo(
8270 slot.isActive(),
8271 slot.isEuicc(),
8272 cardId,
8273 cardState,
8274 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008275 slot.isExtendedApduSupported(),
8276 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277 }
8278 return infos;
8279 } finally {
8280 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008281 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008282 }
8283
8284 @Override
8285 public boolean switchSlots(int[] physicalSlots) {
8286 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287
8288 final long identity = Binder.clearCallingIdentity();
8289 try {
8290 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8291 } finally {
8292 Binder.restoreCallingIdentity(identity);
8293 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008294 }
Jack Yu4c988042018-02-27 15:30:01 -08008295
8296 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008297 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 return UiccController.getInstance().getCardIdForDefaultEuicc();
8301 } finally {
8302 Binder.restoreCallingIdentity(identity);
8303 }
8304 }
8305
Pengquan Meng85728fb2018-03-12 16:31:21 -07008306 /**
goneil47ffb6e2018-04-06 15:40:58 -07008307 * A test API to reload the UICC profile.
8308 *
8309 * <p>Requires that the calling app has permission
8310 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8311 * @hide
8312 */
8313 @Override
8314 public void refreshUiccProfile(int subId) {
8315 enforceModifyPermission();
8316
8317 final long identity = Binder.clearCallingIdentity();
8318 try {
8319 Phone phone = getPhone(subId);
8320 if (phone == null) {
8321 return;
8322 }
8323 UiccCard uiccCard = phone.getUiccCard();
8324 if (uiccCard == null) {
8325 return;
8326 }
8327 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8328 if (uiccProfile == null) {
8329 return;
8330 }
8331 uiccProfile.refresh();
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
8334 }
8335 }
8336
8337 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008338 * Returns false if the mobile data is disabled by default, otherwise return true.
8339 */
8340 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008341 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008342 }
8343
8344 /**
8345 * Returns true if the data roaming is enabled by default, i.e the system property
8346 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8347 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8348 */
8349 private boolean getDefaultDataRoamingEnabled(int subId) {
8350 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008351 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008352 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008353 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8354 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8355 return isDataRoamingEnabled;
8356 }
8357
8358 /**
8359 * Returns the default network type for the given {@code subId}, if the default network type is
8360 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8361 */
8362 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008363 List<Integer> list = TelephonyProperties.default_network();
8364 int phoneId = mSubscriptionController.getPhoneId(subId);
8365 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8366 return list.get(phoneId);
8367 }
8368 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008369 }
fionaxua13278b2018-03-21 00:08:13 -07008370
8371 @Override
8372 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008373 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008374 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008375
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 final Phone phone = getPhone(subId);
8379 if (phone == null) {
8380 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8381 return;
8382 }
chen xueaba88a2019-03-15 13:15:10 -07008383 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8384 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008385 if (carrierPrivilegeRules == null) {
8386 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8387 } else {
8388 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8389 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390 } finally {
8391 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008392 }
fionaxua13278b2018-03-21 00:08:13 -07008393 }
8394
8395 @Override
8396 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008397 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008398
8399 final long identity = Binder.clearCallingIdentity();
8400 try {
8401 final Phone phone = getPhone(subId);
8402 if (phone == null) {
8403 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8404 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8405 }
8406 return phone.getCarrierIdListVersion();
8407 } finally {
8408 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008409 }
fionaxua13278b2018-03-21 00:08:13 -07008410 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008411
8412 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008413 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8414 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008415 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008416 mApp, subId, callingPackage, callingFeatureId,
8417 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008418 return -1;
8419 }
8420
8421 final long identity = Binder.clearCallingIdentity();
8422 try {
8423 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8424 } finally {
8425 Binder.restoreCallingIdentity(identity);
8426 }
8427 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008428
8429 @Override
8430 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008431 TelephonyPermissions
8432 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008433 mApp, subId, "getCdmaRoamingMode");
8434
8435 final long identity = Binder.clearCallingIdentity();
8436 try {
8437 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8438 } finally {
8439 Binder.restoreCallingIdentity(identity);
8440 }
8441 }
8442
8443 @Override
8444 public boolean setCdmaRoamingMode(int subId, int mode) {
8445 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8446 mApp, subId, "setCdmaRoamingMode");
8447
8448 final long identity = Binder.clearCallingIdentity();
8449 try {
8450 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8451 } finally {
8452 Binder.restoreCallingIdentity(identity);
8453 }
8454 }
8455
8456 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008457 public int getCdmaSubscriptionMode(int subId) {
8458 TelephonyPermissions
8459 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8460 mApp, subId, "getCdmaSubscriptionMode");
8461
8462 final long identity = Binder.clearCallingIdentity();
8463 try {
8464 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8465 } finally {
8466 Binder.restoreCallingIdentity(identity);
8467 }
8468 }
8469
8470 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008471 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8472 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8473 mApp, subId, "setCdmaSubscriptionMode");
8474
8475 final long identity = Binder.clearCallingIdentity();
8476 try {
8477 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8478 } finally {
8479 Binder.restoreCallingIdentity(identity);
8480 }
8481 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008482
sqianc5eccab2018-10-19 18:46:41 -07008483 @Override
sqian8c685422019-02-22 15:55:18 -08008484 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008485 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008486 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008487 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8488 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008489 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8490 }
8491 final long identity = Binder.clearCallingIdentity();
8492 try {
sqian854d44b2018-12-12 16:48:18 -08008493 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8494 for (Phone phone: PhoneFactory.getPhones()) {
8495 if (phone.getEmergencyNumberTracker() != null
8496 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8497 emergencyNumberListInternal.put(
8498 phone.getSubId(),
8499 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8500 }
sqian11b7a0e2018-12-05 18:48:28 -08008501 }
sqian854d44b2018-12-12 16:48:18 -08008502 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
sqianc5eccab2018-10-19 18:46:41 -07008506 }
8507
8508 @Override
sqian8c685422019-02-22 15:55:18 -08008509 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008510 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008511 if (!exactMatch) {
8512 TelephonyPermissions
8513 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008514 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008515 }
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
sqian854d44b2018-12-12 16:48:18 -08008518 for (Phone phone: PhoneFactory.getPhones()) {
8519 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008520 && phone.getEmergencyNumberTracker()
8521 .isEmergencyNumber(number, exactMatch)) {
8522 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008523 }
sqian11b7a0e2018-12-05 18:48:28 -08008524 }
8525 return false;
8526 } finally {
8527 Binder.restoreCallingIdentity(identity);
8528 }
8529 }
8530
sqianf4ca7ed2019-01-15 18:32:07 -08008531 /**
8532 * Update emergency number list for test mode.
8533 */
8534 @Override
8535 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8536 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8537 "updateEmergencyNumberListTestMode");
8538
8539 final long identity = Binder.clearCallingIdentity();
8540 try {
8541 for (Phone phone: PhoneFactory.getPhones()) {
8542 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8543 if (tracker != null) {
8544 tracker.executeEmergencyNumberTestModeCommand(action, num);
8545 }
8546 }
8547 } finally {
8548 Binder.restoreCallingIdentity(identity);
8549 }
8550 }
8551
8552 /**
8553 * Get the full emergency number list for test mode.
8554 */
8555 @Override
8556 public List<String> getEmergencyNumberListTestMode() {
8557 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8558 "getEmergencyNumberListTestMode");
8559
8560 final long identity = Binder.clearCallingIdentity();
8561 try {
8562 Set<String> emergencyNumbers = new HashSet<>();
8563 for (Phone phone: PhoneFactory.getPhones()) {
8564 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8565 if (tracker != null) {
8566 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8567 emergencyNumbers.add(num.getNumber());
8568 }
8569 }
8570 }
8571 return new ArrayList<>(emergencyNumbers);
8572 } finally {
8573 Binder.restoreCallingIdentity(identity);
8574 }
8575 }
8576
chen xud6b45bd2018-10-30 22:27:10 -07008577 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008578 public int getEmergencyNumberDbVersion(int subId) {
8579 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8580
8581 final long identity = Binder.clearCallingIdentity();
8582 try {
8583 final Phone phone = getPhone(subId);
8584 if (phone == null) {
8585 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8586 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8587 }
8588 return phone.getEmergencyNumberDbVersion();
8589 } finally {
8590 Binder.restoreCallingIdentity(identity);
8591 }
8592 }
8593
8594 @Override
8595 public void notifyOtaEmergencyNumberDbInstalled() {
8596 enforceModifyPermission();
8597
8598 final long identity = Binder.clearCallingIdentity();
8599 try {
8600 for (Phone phone: PhoneFactory.getPhones()) {
8601 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8602 if (tracker != null) {
8603 tracker.updateOtaEmergencyNumberDatabase();
8604 }
8605 }
8606 } finally {
8607 Binder.restoreCallingIdentity(identity);
8608 }
8609 }
8610
8611 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008612 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008613 enforceActiveEmergencySessionPermission();
8614
8615 final long identity = Binder.clearCallingIdentity();
8616 try {
8617 for (Phone phone: PhoneFactory.getPhones()) {
8618 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8619 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008620 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8621 }
8622 }
8623 } finally {
8624 Binder.restoreCallingIdentity(identity);
8625 }
8626 }
8627
8628 @Override
8629 public void resetOtaEmergencyNumberDbFilePath() {
8630 enforceActiveEmergencySessionPermission();
8631
8632 final long identity = Binder.clearCallingIdentity();
8633 try {
8634 for (Phone phone: PhoneFactory.getPhones()) {
8635 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8636 if (tracker != null) {
8637 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008638 }
8639 }
8640 } finally {
8641 Binder.restoreCallingIdentity(identity);
8642 }
8643 }
8644
8645 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008646 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8647 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8648 Phone phone = getPhone(subId);
8649 if (phone == null) {
8650 return null;
8651 }
8652 final long identity = Binder.clearCallingIdentity();
8653 try {
8654 UiccProfile profile = UiccController.getInstance()
8655 .getUiccProfileForPhone(phone.getPhoneId());
8656 if (profile != null) {
8657 return profile.getCertsFromCarrierPrivilegeAccessRules();
8658 }
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
8662 return null;
8663 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008664
8665 /**
8666 * Enable or disable a modem stack.
8667 */
8668 @Override
8669 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8670 enforceModifyPermission();
8671
8672 final long identity = Binder.clearCallingIdentity();
8673 try {
8674 Phone phone = PhoneFactory.getPhone(slotIndex);
8675 if (phone == null) {
8676 return false;
8677 } else {
8678 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8679 }
8680 } finally {
8681 Binder.restoreCallingIdentity(identity);
8682 }
8683 }
Michelecea4cf22018-12-21 15:00:11 -08008684
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008685 /**
8686 * Whether a modem stack is enabled or not.
8687 */
8688 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008689 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8690 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008691 Phone phone = PhoneFactory.getPhone(slotIndex);
8692 if (phone == null) return false;
8693
8694 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008695 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8696 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008697 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8698 }
8699
8700 final long identity = Binder.clearCallingIdentity();
8701 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008702 try {
8703 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8704 } catch (NoSuchElementException ex) {
8705 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8706 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008707 } finally {
8708 Binder.restoreCallingIdentity(identity);
8709 }
8710 }
8711
Michelecea4cf22018-12-21 15:00:11 -08008712 @Override
Michele0ea7d782019-03-19 14:58:42 -07008713 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008714 enforceModifyPermission();
8715
8716 final long identity = Binder.clearCallingIdentity();
8717 try {
8718 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008719 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008720 .commit();
8721 } finally {
8722 Binder.restoreCallingIdentity(identity);
8723 }
8724 }
8725
8726 @Override
Michele0ea7d782019-03-19 14:58:42 -07008727 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008728 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008730 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8731 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008732 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008733 }
Michelecea4cf22018-12-21 15:00:11 -08008734
8735 final long identity = Binder.clearCallingIdentity();
8736 try {
Michele0ea7d782019-03-19 14:58:42 -07008737 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008738 } finally {
8739 Binder.restoreCallingIdentity(identity);
8740 }
8741 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008742
Michele0ea7d782019-03-19 14:58:42 -07008743 @TelephonyManager.IsMultiSimSupportedResult
8744 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008745 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8746 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8747 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008748 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008750 }
8751 // Check if the hardware supports multisim functionality. If usage of multisim is not
8752 // supported by the modem, indicate that it is restricted.
8753 PhoneCapability staticCapability =
8754 mPhoneConfigurationManager.getStaticPhoneCapability();
8755 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008756 loge("isMultiSimSupportedInternal: no static configuration available");
8757 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008758 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008759 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008760 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8761 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008762 }
8763 // Check if support of multiple SIMs is restricted by carrier
8764 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008765 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008766 }
8767
Michele0ea7d782019-03-19 14:58:42 -07008768 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008769 }
8770
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008771 /**
8772 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008773 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8774 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8775 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008776 * @param numOfSims number of active sims we want to switch to
8777 */
8778 @Override
8779 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008780 if (numOfSims == 1) {
8781 enforceModifyPermission();
8782 } else {
8783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8784 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8785 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008787
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008788 try {
Michele30b57b22019-03-01 12:01:14 -08008789 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008790 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008791 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8792 return;
8793 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008794 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8795 } finally {
8796 Binder.restoreCallingIdentity(identity);
8797 }
8798 }
8799
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008800 @Override
8801 public boolean isApplicationOnUicc(int subId, int appType) {
8802 enforceReadPrivilegedPermission("isApplicationOnUicc");
8803 Phone phone = getPhone(subId);
8804 if (phone == null) {
8805 return false;
8806 }
8807 final long identity = Binder.clearCallingIdentity();
8808 try {
8809 UiccCard uiccCard = phone.getUiccCard();
8810 if (uiccCard == null) {
8811 return false;
8812 }
8813 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8814 if (uiccProfile == null) {
8815 return false;
8816 }
8817 if (TelephonyManager.APPTYPE_SIM <= appType
8818 && appType <= TelephonyManager.APPTYPE_ISIM) {
8819 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8820 }
8821 return false;
8822 } finally {
8823 Binder.restoreCallingIdentity(identity);
8824 }
8825 }
8826
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008827 /**
chen xub4baa772019-04-03 10:23:41 -07008828 * Get whether making changes to modem configurations will trigger reboot.
8829 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008830 */
8831 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008832 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8833 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008834 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008835 mApp, subId, callingPackage, callingFeatureId,
8836 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008837 return false;
8838 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008839 final long identity = Binder.clearCallingIdentity();
8840 try {
8841 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8842 } finally {
8843 Binder.restoreCallingIdentity(identity);
8844 }
8845 }
8846
Nathan Harold29f5f052019-02-15 13:41:57 -08008847 private void updateModemStateMetrics() {
8848 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8849 // TODO: check the state for each modem if the api is ready.
8850 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8851 }
8852
Pengquan Meng3889a572019-01-23 11:16:29 -08008853 @Override
8854 public int[] getSlotsMapping() {
8855 enforceReadPrivilegedPermission("getSlotsMapping");
8856
8857 final long identity = Binder.clearCallingIdentity();
8858 try {
8859 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8860 // All logical slots should have a mapping to a physical slot.
8861 int[] logicalSlotsMapping = new int[phoneCount];
8862 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8863 for (int i = 0; i < slotInfos.length; i++) {
8864 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8865 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8866 }
8867 }
8868 return logicalSlotsMapping;
8869 } finally {
8870 Binder.restoreCallingIdentity(identity);
8871 }
8872 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008873
8874 /**
8875 * Get the IRadio HAL Version
8876 */
8877 @Override
8878 public int getRadioHalVersion() {
8879 Phone phone = getDefaultPhone();
8880 if (phone == null) return -1;
8881 HalVersion hv = phone.getHalVersion();
8882 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8883 return hv.major * 100 + hv.minor;
8884 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008885
8886 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008887 * Get the current calling package name.
8888 * @return the current calling package name
8889 */
8890 @Override
8891 public String getCurrentPackageName() {
8892 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8893 }
8894
8895 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008896 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8897 * corresponding network requests on a subId.
8898 *
8899 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008900 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008901 * 2) APN is un-metered for this subscription, or
8902 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008903 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008904 *
8905 * @return whether data is allowed for a apn type.
8906 *
8907 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008908 */
8909 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008910 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008911 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8912 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008913
8914 // Now that all security checks passes, perform the operation as ourselves.
8915 final long identity = Binder.clearCallingIdentity();
8916 try {
8917 Phone phone = getPhone(subId);
8918 if (phone == null) return false;
8919
Jack Yu41407ee2019-05-13 16:54:09 -07008920 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008921 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
8924 }
8925 }
8926
8927 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008928 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008929 enforceReadPrivilegedPermission("isApnMetered");
8930
8931 // Now that all security checks passes, perform the operation as ourselves.
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
8934 Phone phone = getPhone(subId);
8935 if (phone == null) return true; // By default return true.
8936
Jack Yu41407ee2019-05-13 16:54:09 -07008937 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008938 } finally {
8939 Binder.restoreCallingIdentity(identity);
8940 }
8941 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008942
8943 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008944 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8945 int subscriptionId, IBooleanConsumer resultCallback) {
8946 enforceModifyPermission();
8947 long token = Binder.clearCallingIdentity();
8948 try {
8949 Phone phone = getPhone(subscriptionId);
8950 if (phone == null) {
8951 try {
8952 if (resultCallback != null) {
8953 resultCallback.accept(false);
8954 }
8955 } catch (RemoteException e) {
8956 // ignore
8957 }
8958 return;
8959 }
8960 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8961 Pair.create(specifiers, (x) -> {
8962 try {
8963 if (resultCallback != null) {
8964 resultCallback.accept(x);
8965 }
8966 } catch (RemoteException e) {
8967 // ignore
8968 }
8969 });
8970 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8971 } finally {
8972 Binder.restoreCallingIdentity(token);
8973 }
8974 }
8975
8976 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008977 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8978 TelephonyPermissions
8979 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8980 mApp, subId, "getSystemSelectionChannels");
8981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8982 final long identity = Binder.clearCallingIdentity();
8983 try {
8984 List<RadioAccessSpecifier> specifiers =
8985 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8986 null, subId, workSource);
8987 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8988 return specifiers;
8989 } finally {
8990 Binder.restoreCallingIdentity(identity);
8991 }
8992 }
8993
8994 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008995 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008996 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008997 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8998 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8999 if (iccRecords == null) {
9000 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9001 return false;
9002 }
9003 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9004 }
9005
9006 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009007 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9008 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009009 if (callingPackage == null) {
9010 callingPackage = getCurrentPackageName();
9011 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009012 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9013 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009014 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9015 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009016 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9017 }
9018 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9019 Intent intent = new Intent();
9020 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9021 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9022 // Bring up choose default SMS subscription dialog right now
9023 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9024 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9025 mApp.startActivity(intent);
9026 }
chen xud5ca2d52019-05-28 15:20:57 -07009027
9028 @Override
9029 public String getMmsUAProfUrl(int subId) {
9030 //TODO investigate if this API should require proper permission check in R b/133791609
9031 final long identity = Binder.clearCallingIdentity();
9032 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009033 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9034 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9035 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9036 return carrierUAProfUrl;
9037 }
chen xud5ca2d52019-05-28 15:20:57 -07009038 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9039 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9040 } finally {
9041 Binder.restoreCallingIdentity(identity);
9042 }
9043 }
9044
9045 @Override
9046 public String getMmsUserAgent(int subId) {
9047 //TODO investigate if this API should require proper permission check in R b/133791609
9048 final long identity = Binder.clearCallingIdentity();
9049 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009050 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9051 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9052 if (!TextUtils.isEmpty(carrierUserAgent)) {
9053 return carrierUserAgent;
9054 }
chen xud5ca2d52019-05-28 15:20:57 -07009055 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9056 .getString(com.android.internal.R.string.config_mms_user_agent);
9057 } finally {
9058 Binder.restoreCallingIdentity(identity);
9059 }
9060 }
Jack Yub07d4972019-05-28 16:12:25 -07009061
9062 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009063 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9064 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9065
9066 final long identity = Binder.clearCallingIdentity();
9067 try {
9068 Phone phone = getPhone(subscriptionId);
9069 if (phone == null) return false;
9070
9071 switch (policy) {
9072 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9073 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9074 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9075 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9076 default:
9077 throw new IllegalArgumentException(policy + " is not a valid policy");
9078 }
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
9082 }
9083
9084 @Override
9085 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9086 boolean enabled) {
9087 enforceModifyPermission();
9088
9089 final long identity = Binder.clearCallingIdentity();
9090 try {
9091 Phone phone = getPhone(subscriptionId);
9092 if (phone == null) return;
9093
9094 switch (policy) {
9095 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9096 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9097 break;
9098 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9099 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9100 break;
9101 default:
9102 throw new IllegalArgumentException(policy + " is not a valid policy");
9103 }
9104 } finally {
9105 Binder.restoreCallingIdentity(identity);
9106 }
9107 }
9108
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009109 /**
Hall Liub48cf452020-09-25 11:13:49 -07009110 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009111 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9112 * otherwise.
9113 */
9114 @Override
9115 public void setCepEnabled(boolean isCepEnabled) {
9116 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9117
9118 final long identity = Binder.clearCallingIdentity();
9119 try {
9120 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9121 for (Phone phone : PhoneFactory.getPhones()) {
9122 Phone defaultPhone = phone.getImsPhone();
9123 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9124 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9125 ImsPhoneCallTracker imsPhoneCallTracker =
9126 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9127 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9128 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9129 + imsPhone.getMsisdn());
9130 }
9131 }
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
allenwtsu46dcc572020-01-08 18:24:03 +08009136
9137 /**
9138 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9139 *
9140 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9141 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9142 * before being read.
9143 */
9144 @Override
9145 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9146 isCompressed) {
9147 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9148 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9150 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9151 }
9152 if (!isImsAvailableOnDevice()) {
9153 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9154 "IMS not available on device.");
9155 }
9156
9157 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009158 try {
Hui Wang068ab862020-10-31 05:12:53 +00009159 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9160 } finally {
9161 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009162 }
9163 }
zoey chenf95ca592019-12-30 16:11:23 +08009164
9165 @Override
9166 public boolean isIccLockEnabled(int subId) {
9167 enforceReadPrivilegedPermission("isIccLockEnabled");
9168
9169 // Now that all security checks passes, perform the operation as ourselves.
9170 final long identity = Binder.clearCallingIdentity();
9171 try {
9172 Phone phone = getPhone(subId);
9173 if (phone != null && phone.getIccCard() != null) {
9174 return phone.getIccCard().getIccLockEnabled();
9175 } else {
9176 return false;
9177 }
9178 } finally {
9179 Binder.restoreCallingIdentity(identity);
9180 }
9181 }
9182
9183 /**
zoey chene02881a2019-12-30 16:11:23 +08009184 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009185 *
zoey chene02881a2019-12-30 16:11:23 +08009186 * @return an integer representing the status of IccLock enabled or disabled in the following
9187 * three cases:
9188 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9189 * successfully.
9190 * - Positive number and zero for remaining password attempts.
9191 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009192 *
9193 */
9194 @Override
9195 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9196 enforceModifyPermission();
9197
9198 Phone phone = getPhone(subId);
9199 if (phone == null) {
9200 return 0;
9201 }
9202 // Now that all security checks passes, perform the operation as ourselves.
9203 final long identity = Binder.clearCallingIdentity();
9204 try {
9205 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9206 new Pair<Boolean, String>(enabled, password), phone, null);
9207 return attemptsRemaining;
9208
9209 } catch (Exception e) {
9210 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9211 } finally {
9212 Binder.restoreCallingIdentity(identity);
9213 }
9214 return 0;
9215 }
9216
9217 /**
9218 * Change the ICC password used in ICC pin lock.
9219 *
zoey chene02881a2019-12-30 16:11:23 +08009220 * @return an integer representing the status of IccLock changed in the following three cases:
9221 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9222 * - Positive number and zero for remaining password attempts.
9223 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009224 *
9225 */
9226 @Override
9227 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9228 enforceModifyPermission();
9229
9230 Phone phone = getPhone(subId);
9231 if (phone == null) {
9232 return 0;
9233 }
9234 // Now that all security checks passes, perform the operation as ourselves.
9235 final long identity = Binder.clearCallingIdentity();
9236 try {
9237 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9238 new Pair<String, String>(oldPassword, newPassword), phone, null);
9239 return attemptsRemaining;
9240
9241 } catch (Exception e) {
9242 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9243 } finally {
9244 Binder.restoreCallingIdentity(identity);
9245 }
9246 return 0;
9247 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009248
Peter Wangdafb9ac2020-01-15 14:13:38 -08009249 /**
9250 * Request for receiving user activity notification
9251 */
9252 @Override
9253 public void requestUserActivityNotification() {
9254 if (!mNotifyUserActivity.get()
9255 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9256 mNotifyUserActivity.set(true);
9257 }
9258 }
9259
9260 /**
9261 * Called when userActivity is signalled in the power manager.
9262 * This is safe to call from any thread, with any window manager locks held or not.
9263 */
9264 @Override
9265 public void userActivity() {
9266 // ***************************************
9267 // * Inherited from PhoneWindowManager *
9268 // ***************************************
9269 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9270 // WITH ITS LOCKS HELD.
9271 //
9272 // This code must be VERY careful about the locks
9273 // it acquires.
9274 // In fact, the current code acquires way too many,
9275 // and probably has lurking deadlocks.
9276
9277 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9278 throw new SecurityException("Only the OS may call notifyUserActivity()");
9279 }
9280
9281 if (mNotifyUserActivity.getAndSet(false)) {
9282 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9283 USER_ACTIVITY_NOTIFICATION_DELAY);
9284 }
9285 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009286
Malcolm Chen884180b2020-04-13 11:59:40 -07009287 @Override
9288 public boolean canConnectTo5GInDsdsMode() {
9289 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9290 }
Jack Yud10cdd42020-09-28 20:28:01 -07009291
9292 @Override
9293 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9294 String callingFeatureId) {
9295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9296 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9297 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9298 }
9299
9300 Phone phone = getPhone(subId);
9301 if (phone == null) {
9302 throw new RuntimeException("phone is not available");
9303 }
9304 // Now that all security checks passes, perform the operation as ourselves.
9305 final long identity = Binder.clearCallingIdentity();
9306 try {
9307 return phone.getEquivalentHomePlmns();
9308 } finally {
9309 Binder.restoreCallingIdentity(identity);
9310 }
9311 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009312
Hui Wang0866fcc2020-10-12 12:14:23 -07009313 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009314 public boolean isRadioInterfaceCapabilitySupported(
9315 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009316 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009317 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9318 if (radioInterfaceCapabilities == null) {
9319 throw new RuntimeException("radio interface capabilities are not available");
9320 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009321 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009322 }
9323 }
9324
9325 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009326 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9327 UaSecurityProtocolIdentifier securityProtocol,
9328 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9329 throws RemoteException {
9330 enforceModifyPermission();
9331 if (DBG) {
9332 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9333 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9334 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9335 }
9336
9337 if (!SubscriptionManager.isValidSubscriptionId(subId)
9338 || appType < TelephonyManager.APPTYPE_UNKNOWN
9339 || appType > TelephonyManager.APPTYPE_ISIM
9340 || nafUrl == null || securityProtocol == null || callback == null) {
9341 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9342 if (callback != null) {
9343 try {
9344 callback.onAuthenticationFailure(
9345 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9346 } catch (RemoteException exception) {
9347 log("Fail to notify onAuthenticationFailure due to " + exception);
9348 }
9349 return;
9350 }
9351 }
9352
9353 final long token = Binder.clearCallingIdentity();
9354 try {
9355 getGbaManager(subId).bootstrapAuthenticationRequest(
9356 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9357 forceBootStrapping, callback));
9358 } finally {
9359 Binder.restoreCallingIdentity(token);
9360 }
9361 }
9362
Jack Nudelman24d51a52020-11-24 12:08:04 -08009363 /**
9364 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9365 * requested radio power state will actually be set. See {@link
9366 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9367 *
9368 * @param subId the subscription ID of the phone requesting to set the radio power state.
9369 * @param enable {@code true} if trying to turn radio on.
9370 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9371 * false}.
9372 */
9373 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9374 Phone phone = getPhone(subId);
9375 if (phone != null) {
9376 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9377 return true;
9378 }
9379 return false;
9380 }
9381
9382 private int handleDataThrottlingRequest(int subId,
9383 DataThrottlingRequest dataThrottlingRequest) {
9384 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9385 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9386 if (!setRadioPowerForThermal(subId, true)) {
9387 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9388 }
9389
9390 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9391
9392 int thermalMitigationResult =
9393 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9394 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9395 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9396 }
9397 return thermalMitigationResult;
9398 }
9399
9400 /**
9401 * Thermal mitigation request to control functionalities at modem.
9402 *
9403 * @param subId the id of the subscription.
9404 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9405 *
9406 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9407 */
9408 @Override
9409 @ThermalMitigationResult
9410 public int sendThermalMitigationRequest(
9411 int subId,
9412 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9413 enforceModifyPermission();
9414
9415 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9416 final long identity = Binder.clearCallingIdentity();
9417
9418 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9419 try {
9420 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9421 switch (thermalMitigationAction) {
9422 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9423 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009424 handleDataThrottlingRequest(subId,
9425 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009426 break;
9427 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9428 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9429 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9430 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9431 }
9432
9433 // Ensure that radio is on. If not able to power on due to phone being
9434 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9435 if (!setRadioPowerForThermal(subId, true)) {
9436 thermalMitigationResult =
9437 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9438 break;
9439 }
9440
9441 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9442 false);
9443 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9444 break;
9445 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9446 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9447 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9448 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9449 }
9450
9451 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9452 if (registry != null) {
9453 TelephonyConnectionService service =
9454 registry.getTelephonyConnectionService();
9455 Phone phone = getPhone(subId);
9456 if (phone == null) {
9457 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009458 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009459 break;
9460 }
9461
9462 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009463 != TelephonyManager.CALL_STATE_IDLE
9464 || phone.isInEmergencySmsMode() || phone.isInEcm()
9465 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009466 String errorMessage = "Phone state is not valid. call state = "
9467 + PhoneConstantConversions.convertCallState(phone.getState())
9468 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9469 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9470 errorMessage += service == null
9471 ? " TelephonyConnectionService is null"
9472 : " isEmergencyCallPending = "
9473 + service.isEmergencyCallPending();
9474 Log.e(LOG_TAG, errorMessage);
9475 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009476 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009477 break;
9478 }
9479 } else {
9480 thermalMitigationResult =
9481 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9482 break;
9483 }
9484
9485 // Turn radio off. If not able to power off due to phone being unavailable,
9486 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9487 if (!setRadioPowerForThermal(subId, false)) {
9488 thermalMitigationResult =
9489 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9490 break;
9491 }
9492 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009493 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009494 break;
9495 default:
9496 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9497 + "not exist. Requested action: " + thermalMitigationAction);
9498 }
9499 } catch (IllegalArgumentException e) {
9500 throw e;
9501 } catch (Exception e) {
9502 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9503 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9504 } finally {
9505 Binder.restoreCallingIdentity(identity);
9506 }
9507
9508 if (DBG) {
9509 log("thermalMitigationRequest returning with thermalMitigationResult: "
9510 + thermalMitigationResult);
9511 }
9512
9513 return thermalMitigationResult;
9514 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009515
9516 /**
9517 * Set the GbaService Package Name that Telephony will bind to.
9518 *
9519 * @param subId The sim that the GbaService is associated with.
9520 * @param packageName The name of the package to be replaced with.
9521 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9522 */
9523 @Override
9524 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9525 enforceModifyPermission();
9526
9527 final long identity = Binder.clearCallingIdentity();
9528 try {
9529 return getGbaManager(subId).overrideServicePackage(packageName);
9530 } finally {
9531 Binder.restoreCallingIdentity(identity);
9532 }
9533 }
9534
9535 /**
9536 * Return the package name of the currently bound GbaService.
9537 *
9538 * @param subId The sim that the GbaService is associated with.
9539 * @return the package name of the GbaService configuration, null if GBA is not supported.
9540 */
9541 @Override
9542 public String getBoundGbaService(int subId) {
9543 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9544
9545 final long identity = Binder.clearCallingIdentity();
9546 try {
9547 return getGbaManager(subId).getServicePackage();
9548 } finally {
9549 Binder.restoreCallingIdentity(identity);
9550 }
9551 }
9552
9553 /**
9554 * Set the release time for telephony to unbind GbaService.
9555 *
9556 * @param subId The sim that the GbaService is associated with.
9557 * @param interval The release time to unbind GbaService by millisecond.
9558 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9559 */
9560 @Override
9561 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9562 enforceModifyPermission();
9563
9564 final long identity = Binder.clearCallingIdentity();
9565 try {
9566 return getGbaManager(subId).overrideReleaseTime(interval);
9567 } finally {
9568 Binder.restoreCallingIdentity(identity);
9569 }
9570 }
9571
9572 /**
9573 * Return the release time for telephony to unbind GbaService.
9574 *
9575 * @param subId The sim that the GbaService is associated with.
9576 * @return The release time to unbind GbaService by millisecond.
9577 */
9578 @Override
9579 public int getGbaReleaseTime(int subId) {
9580 enforceReadPrivilegedPermission("getGbaReleaseTime");
9581
9582 final long identity = Binder.clearCallingIdentity();
9583 try {
9584 return getGbaManager(subId).getReleaseTime();
9585 } finally {
9586 Binder.restoreCallingIdentity(identity);
9587 }
9588 }
9589
9590 private GbaManager getGbaManager(int subId) {
9591 GbaManager instance = GbaManager.getInstance(subId);
9592 if (instance == null) {
9593 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9594 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9595 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9596 }
9597 return instance;
9598 }
Hui Wang068ab862020-10-31 05:12:53 +00009599
9600 /**
9601 * indicate whether the device and the carrier can support
9602 * RCS VoLTE single registration.
9603 */
9604 @Override
9605 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9606 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9607
9608 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9609 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9610 }
9611
9612 final long identity = Binder.clearCallingIdentity();
9613 try {
9614 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9615 if (rpm != null) {
9616 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9617 }
9618 return false;
9619 } finally {
9620 Binder.restoreCallingIdentity(identity);
9621 }
9622 }
9623
9624 /**
9625 * Register RCS provisioning callback.
9626 */
9627 @Override
9628 public void registerRcsProvisioningChangedCallback(int subId,
9629 IRcsConfigCallback callback) {
9630 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9631
9632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9633 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9634 }
9635 if (!isImsAvailableOnDevice()) {
9636 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9637 "IMS not available on device.");
9638 }
9639
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009642 if (!RcsProvisioningMonitor.getInstance()
9643 .registerRcsProvisioningChangedCallback(subId, callback)) {
9644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9645 "Service not available for the subscription.");
9646 }
Hui Wang068ab862020-10-31 05:12:53 +00009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 /**
9653 * Unregister RCS provisioning callback.
9654 */
9655 @Override
9656 public void unregisterRcsProvisioningChangedCallback(int subId,
9657 IRcsConfigCallback callback) {
9658 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9659
9660 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9661 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9662 }
9663 if (!isImsAvailableOnDevice()) {
9664 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9665 "IMS not available on device.");
9666 }
9667
9668 final long identity = Binder.clearCallingIdentity();
9669 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009670 RcsProvisioningMonitor.getInstance()
9671 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
9677 /**
9678 * trigger RCS reconfiguration.
9679 */
9680 public void triggerRcsReconfiguration(int subId) {
9681 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9682 mApp, subId, "triggerRcsReconfiguration");
9683
9684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9685 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9686 }
9687 if (!isImsAvailableOnDevice()) {
9688 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9689 "IMS not available on device.");
9690 }
9691
9692 final long identity = Binder.clearCallingIdentity();
9693 try {
9694 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9695 } finally {
9696 Binder.restoreCallingIdentity(identity);
9697 }
9698 }
9699
9700 /**
9701 * Provide the client configuration parameters of the RCS application.
9702 */
9703 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9704 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9705 mApp, subId, "setRcsClientConfiguration");
9706
9707 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9708 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9709 }
9710 if (!isImsAvailableOnDevice()) {
9711 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9712 "IMS not available on device.");
9713 }
9714
9715 final long identity = Binder.clearCallingIdentity();
9716
9717 try {
9718 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9719 if (configBinder == null) {
9720 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9721 } else {
9722 configBinder.setRcsClientConfiguration(rcc);
9723 }
9724 } catch (RemoteException e) {
9725 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9726 } finally {
9727 Binder.restoreCallingIdentity(identity);
9728 }
9729 }
9730
9731 /**
Hui Wang19a21872021-02-19 20:45:36 -08009732 * Enables or disables the test mode for RCS VoLTE single registration.
9733 */
9734 @Override
9735 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9736 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9737 "setRcsSingleRegistrationTestModeEnabled");
9738
9739 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9740 }
9741
9742 /**
9743 * Gets the test mode for RCS VoLTE single registration.
9744 */
9745 @Override
9746 public boolean getRcsSingleRegistrationTestModeEnabled() {
9747 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9748 "getRcsSingleRegistrationTestModeEnabled");
9749
9750 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9751 }
9752
9753 /**
Hui Wang068ab862020-10-31 05:12:53 +00009754 * Overrides the config of RCS VoLTE single registration enabled for the device.
9755 */
9756 @Override
9757 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9758 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9759 "setDeviceSingleRegistrationEnabledOverride");
9760 enforceModifyPermission();
9761
9762 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9763 : Boolean.parseBoolean(enabledStr);
9764 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009765 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009766 }
9767
9768 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009769 * Sends a device to device communication message. Only usable via shell.
9770 * @param message message to send.
9771 * @param value message value.
9772 */
9773 @Override
9774 public void sendDeviceToDeviceMessage(int message, int value) {
9775 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9776 "setCarrierSingleRegistrationEnabledOverride");
9777 enforceModifyPermission();
9778
9779 final long identity = Binder.clearCallingIdentity();
9780 try {
9781 TelephonyConnectionService service =
9782 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9783 if (service == null) {
9784 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9785 return;
9786 }
9787 service.sendTestDeviceToDeviceMessage(message, value);
9788 } finally {
9789 Binder.restoreCallingIdentity(identity);
9790 }
9791 }
9792
9793
9794 /**
Hui Wang068ab862020-10-31 05:12:53 +00009795 * Gets the config of RCS VoLTE single registration enabled for the device.
9796 */
9797 @Override
9798 public boolean getDeviceSingleRegistrationEnabled() {
9799 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9800 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9801 }
9802
9803 /**
9804 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9805 */
9806 @Override
9807 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9808 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9809 "setCarrierSingleRegistrationEnabledOverride");
9810 enforceModifyPermission();
9811
9812 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9813 : Boolean.parseBoolean(enabledStr);
9814 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9815 subId, enabled);
9816 }
9817
9818 /**
9819 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9820 */
9821 @Override
9822 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9823 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9824 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9825 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009826
9827 /**
9828 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9829 * their mobile plan.
9830 */
9831 @Override
9832 public String getMobileProvisioningUrl() {
9833 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9834 final long identity = Binder.clearCallingIdentity();
9835 try {
9836 return getDefaultPhone().getMobileProvisioningUrl();
9837 } finally {
9838 Binder.restoreCallingIdentity(identity);
9839 }
9840 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009841
James.cf Linbcdf8b32021-01-14 16:44:13 +08009842 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009843 * Get the EAB contact from the EAB database.
9844 */
9845 @Override
9846 public String getContactFromEab(String contact) {
9847 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9848 enforceModifyPermission();
9849 final long identity = Binder.clearCallingIdentity();
9850 try {
9851 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9852 } finally {
9853 Binder.restoreCallingIdentity(identity);
9854 }
9855 }
9856
9857 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009858 * Remove the EAB contacts from the EAB database.
9859 */
9860 @Override
9861 public int removeContactFromEab(int subId, String contacts) {
9862 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9863 enforceModifyPermission();
9864 final long identity = Binder.clearCallingIdentity();
9865 try {
9866 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9867 } finally {
9868 Binder.restoreCallingIdentity(identity);
9869 }
9870 }
9871
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009872 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009873 public boolean getDeviceUceEnabled() {
9874 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9875 final long identity = Binder.clearCallingIdentity();
9876 try {
9877 return mApp.getDeviceUceEnabled();
9878 } finally {
9879 Binder.restoreCallingIdentity(identity);
9880 }
9881 }
9882
9883 @Override
9884 public void setDeviceUceEnabled(boolean isEnabled) {
9885 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9886 final long identity = Binder.clearCallingIdentity();
9887 try {
9888 mApp.setDeviceUceEnabled(isEnabled);
9889 } finally {
9890 Binder.restoreCallingIdentity(identity);
9891 }
9892 }
9893
9894 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009895 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9896 String callingPackage) {
9897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9898 mApp, subId, "setSignalStrengthUpdateRequest");
9899
9900 final int callingUid = Binder.getCallingUid();
9901 // Verify that tha callingPackage belongs to the calling UID
9902 mApp.getSystemService(AppOpsManager.class)
9903 .checkPackage(callingUid, callingPackage);
9904
9905 validateSignalStrengthUpdateRequest(request, callingUid);
9906
9907 final long identity = Binder.clearCallingIdentity();
9908 try {
9909 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9910 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9911
9912 if (result instanceof IllegalStateException) {
9913 throw (IllegalStateException) result;
9914 }
9915 } finally {
9916 Binder.restoreCallingIdentity(identity);
9917 }
9918 }
9919
9920 @Override
9921 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9922 String callingPackage) {
9923 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9924 mApp, subId, "clearSignalStrengthUpdateRequest");
9925
9926 final int callingUid = Binder.getCallingUid();
9927 // Verify that tha callingPackage belongs to the calling UID
9928 mApp.getSystemService(AppOpsManager.class)
9929 .checkPackage(callingUid, callingPackage);
9930
9931 final long identity = Binder.clearCallingIdentity();
9932 try {
9933 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9934 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9935
9936 if (result instanceof IllegalStateException) {
9937 throw (IllegalStateException) result;
9938 }
9939 } finally {
9940 Binder.restoreCallingIdentity(identity);
9941 }
9942 }
9943
9944 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9945 int callingUid) {
9946 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9947 // phone/system process do not have further restriction on request
9948 return;
9949 }
9950
9951 // Applications has restrictions on how to use the request:
9952 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9953 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9954 // This is not system caller which has been checked above
9955 throw new IllegalArgumentException(
9956 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9957 }
9958
9959 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9960 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9961 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9962 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9963 || info.isEnabled()) {
9964 throw new IllegalArgumentException(
9965 "Only system can set hide fields in SignalThresholdInfo");
9966 }
9967
9968 // Thresholds length for each RAN need in range. This has been validated in
9969 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9970 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9971 final int[] thresholds = info.getThresholds();
9972 Objects.requireNonNull(thresholds);
9973 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9974 || thresholds.length
9975 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9976 throw new IllegalArgumentException(
9977 "thresholds length is out of range: " + thresholds.length);
9978 }
9979 }
9980 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009981
9982 /**
9983 * Prepare TelephonyManager for an unattended reboot. The reboot is
9984 * required to be done shortly after the API is invoked.
9985 */
9986 @Override
9987 @TelephonyManager.PrepareUnattendedRebootResult
9988 public int prepareForUnattendedReboot() {
9989 enforceRebootPermission();
9990
9991 final long identity = Binder.clearCallingIdentity();
9992 try {
9993 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
9994 } finally {
9995 Binder.restoreCallingIdentity(identity);
9996 }
9997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009998}