blob: b60a36f729ca06a5427dbcdcbf72f2fa56badecb [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
Brad Ebinger4df7e242021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080055import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080068import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070070import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070071import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080072import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070073import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080074import android.telephony.CellIdentityCdma;
75import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070077import android.telephony.CellInfoGsm;
78import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070079import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080080import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070081import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070082import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070083import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080084import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070085import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080086import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070087import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080088import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080089import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070090import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800191import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700193import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800194import com.android.services.telephony.TelecomAccountRegistry;
195import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800196import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800197
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700198import java.io.FileDescriptor;
199import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800202import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800203import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800204import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100205import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700207import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800208import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800210import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800211import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
213/**
214 * Implementation of the ITelephony interface.
215 */
Santos Cordon117fee72014-05-16 17:56:12 -0700216public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 private static final String LOG_TAG = "PhoneInterfaceManager";
218 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
219 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
222 // Message codes used with mMainThreadHandler
223 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700224 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
225 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 private static final int CMD_OPEN_CHANNEL = 9;
227 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
228 private static final int CMD_CLOSE_CHANNEL = 11;
229 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800230 private static final int CMD_NV_READ_ITEM = 13;
231 private static final int EVENT_NV_READ_ITEM_DONE = 14;
232 private static final int CMD_NV_WRITE_ITEM = 15;
233 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
234 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
235 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700236 private static final int CMD_RESET_MODEM_CONFIG = 19;
237 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800238 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
239 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800240 private static final int CMD_SEND_ENVELOPE = 25;
241 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000242 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
243 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700244 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
245 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
246 private static final int CMD_EXCHANGE_SIM_IO = 31;
247 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800248 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
249 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700250 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
251 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700252 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
253 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700254 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
255 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
256 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
257 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700258 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
259 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
260 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
261 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700262 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800263 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
264 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000265 private static final int CMD_SWITCH_SLOTS = 50;
266 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700267 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
268 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
269 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
270 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
271 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
272 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
273 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
274 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700275 private static final int CMD_GET_ALL_CELL_INFO = 60;
276 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
277 private static final int CMD_GET_CELL_LOCATION = 62;
278 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700279 private static final int CMD_MODEM_REBOOT = 64;
280 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700281 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
282 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800283 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
284 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700285 private static final int CMD_GET_MODEM_STATUS = 70;
286 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700287 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
288 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700289 private static final int CMD_ERASE_MODEM_CONFIG = 74;
290 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800291 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
292 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
293 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
294 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800295 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
296 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800297 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800298 private static final int CMD_GET_CALL_FORWARDING = 83;
299 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
300 private static final int CMD_SET_CALL_FORWARDING = 85;
301 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
302 private static final int CMD_GET_CALL_WAITING = 87;
303 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
304 private static final int CMD_SET_CALL_WAITING = 89;
305 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700306 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
307 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
308 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
309 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700310 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
311 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800312 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
313 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800314 private static final int CMD_SET_DATA_THROTTLING = 99;
315 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800316 private static final int CMD_SET_SIM_POWER = 101;
317 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800318 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
319 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
320 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
321 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800322 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
323 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000324 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800326 // Parameters of select command.
327 private static final int SELECT_COMMAND = 0xA4;
328 private static final int SELECT_P1 = 0x04;
329 private static final int SELECT_P2 = 0;
330 private static final int SELECT_P3 = 0x10;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 /** The singleton instance. */
333 private static PhoneInterfaceManager sInstance;
334
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800337 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700338 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private AppOpsManager mAppOps;
340 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800341 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700343 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 /** User Activity */
346 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
348
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700349 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
350
Derek Tan97ebb422014-09-05 16:55:38 -0700351 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
352 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800353 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800354 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700355
Michelecea4cf22018-12-21 15:00:11 -0800356 // String to store multi SIM allowed
357 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
358
Derek Tan740e1672017-06-27 14:56:27 -0700359 // The AID of ISD-R.
360 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
361
yinxub1bed742017-04-17 11:45:04 -0700362 private NetworkScanRequestTracker mNetworkScanRequestTracker;
363
David Kelly5e06a7f2018-03-12 14:10:59 +0000364 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
365 private static final int MANUFACTURER_CODE_LENGTH = 8;
366
Jack Nudelman24d51a52020-11-24 12:08:04 -0800367 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
368
Derek Tan89e89d42014-07-08 17:00:10 -0700369 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700370 * Experiment flag to enable erase modem config on reset network, default value is false
371 */
372 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
373 "reset_network_erase_modem_config_enabled";
374
Rambo Wang0f050d82021-02-12 11:43:36 -0800375 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
376
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700377 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700378 * A request object to use for transmitting data to an ICC.
379 */
380 private static final class IccAPDUArgument {
381 public int channel, cla, command, p1, p2, p3;
382 public String data;
383
384 public IccAPDUArgument(int channel, int cla, int command,
385 int p1, int p2, int p3, String data) {
386 this.channel = channel;
387 this.cla = cla;
388 this.command = command;
389 this.p1 = p1;
390 this.p2 = p2;
391 this.p3 = p3;
392 this.data = data;
393 }
394 }
395
396 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700397 * A request object to use for transmitting data to an ICC.
398 */
399 private static final class ManualNetworkSelectionArgument {
400 public OperatorInfo operatorInfo;
401 public boolean persistSelection;
402
403 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
404 this.operatorInfo = operatorInfo;
405 this.persistSelection = persistSelection;
406 }
407 }
408
409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
411 * request after sending. The main thread will notify the request when it is complete.
412 */
413 private static final class MainThreadRequest {
414 /** The argument to use for the request */
415 public Object argument;
416 /** The result of the request that is run on the main thread */
417 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800418 // The subscriber id that this request applies to. Defaults to
419 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
420 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Nathan Harold92bed182018-10-12 18:16:49 -0700422 // In cases where subId is unavailable, the caller needs to specify the phone.
423 public Phone phone;
424
vagdeviaf9a5b92018-08-15 16:01:53 -0700425 public WorkSource workSource;
426
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 public MainThreadRequest(Object argument) {
428 this.argument = argument;
429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800430
Nathan Harold92bed182018-10-12 18:16:49 -0700431 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
432 this.argument = argument;
433 if (phone != null) {
434 this.phone = phone;
435 }
436 this.workSource = workSource;
437 }
438
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 if (subId != null) {
442 this.subId = subId;
443 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 }
447
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800448 private static final class IncomingThirdPartyCallArgs {
449 public final ComponentName component;
450 public final String callId;
451 public final String callerDisplayName;
452
453 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
454 String callerDisplayName) {
455 this.component = component;
456 this.callId = callId;
457 this.callerDisplayName = callerDisplayName;
458 }
459 }
460
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 /**
462 * A handler that processes messages on the main thread in the phone process. Since many
463 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
464 * inbound binder threads to the main thread in the phone process. The Binder thread
465 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
466 * on, which will be notified when the operation completes and will contain the result of the
467 * request.
468 *
469 * <p>If a MainThreadRequest object is provided in the msg.obj field,
470 * note that request.result must be set to something non-null for the calling thread to
471 * unblock.
472 */
473 private final class MainThreadHandler extends Handler {
474 @Override
475 public void handleMessage(Message msg) {
476 MainThreadRequest request;
477 Message onCompleted;
478 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800481 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
483 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 case CMD_HANDLE_USSD_REQUEST: {
485 request = (MainThreadRequest) msg.obj;
486 final Phone phone = getPhoneFromRequest(request);
487 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
488 String ussdRequest = ussdObject.first;
489 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700490
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 if (!isUssdApiAllowed(request.subId)) {
492 // Carrier does not support use of this API, return failure.
493 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
494 UssdResponse response = new UssdResponse(ussdRequest, null);
495 Bundle returnData = new Bundle();
496 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
497 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700498
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 request.result = true;
500 notifyRequester(request);
501 return;
502 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 try {
505 request.result = phone != null
506 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
507 } catch (CallStateException cse) {
508 request.result = false;
509 }
510 // Wake up the requesting thread
511 notifyRequester(request);
512 break;
pkanwar32d516d2016-10-14 19:37:38 -0700513 }
514
Yorke Lee716f67e2015-06-17 15:39:16 -0700515 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 final Phone phone = getPhoneFromRequest(request);
518 request.result = phone != null ?
519 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
520 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduLogicalChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
536 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 iccArgument.channel, iccArgument.cla, iccArgument.command,
539 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 break;
543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
549 } else {
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
551 if (ar.result == null) {
552 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800553 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800555 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 } else {
557 loge("iccTransmitApduLogicalChannel: Unknown exception");
558 }
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
565 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 if (uiccCard == null) {
568 loge("iccTransmitApduBasicChannel: No UICC");
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
573 request);
574 uiccCard.iccTransmitApduBasicChannel(
575 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
576 iccArgument.p3, iccArgument.data, onCompleted);
577 }
578 break;
579
580 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
583 if (ar.exception == null && ar.result != null) {
584 request.result = ar.result;
585 } else {
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
587 if (ar.result == null) {
588 loge("iccTransmitApduBasicChannel: Empty response");
589 } else if (ar.exception instanceof CommandException) {
590 loge("iccTransmitApduBasicChannel: CommandException: " +
591 ar.exception);
592 } else {
593 loge("iccTransmitApduBasicChannel: Unknown exception");
594 }
595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 break;
598
599 case CMD_EXCHANGE_SIM_IO:
600 request = (MainThreadRequest) msg.obj;
601 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800602 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 if (uiccCard == null) {
604 loge("iccExchangeSimIO: No UICC");
605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
609 request);
610 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
611 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
612 iccArgument.data, onCompleted);
613 }
614 break;
615
616 case EVENT_EXCHANGE_SIM_IO_DONE:
617 ar = (AsyncResult) msg.obj;
618 request = (MainThreadRequest) ar.userObj;
619 if (ar.exception == null && ar.result != null) {
620 request.result = ar.result;
621 } else {
622 request.result = new IccIoResult(0x6f, 0, (byte[])null);
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 case CMD_SEND_ENVELOPE:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("sendEnvelopeWithStatus: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
636 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
637 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800638 break;
639
640 case EVENT_SEND_ENVELOPE_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("sendEnvelopeWithStatus: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("sendEnvelopeWithStatus: CommandException: " +
651 ar.exception);
652 } else {
653 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
654 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 break;
658
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 case CMD_OPEN_CHANNEL:
660 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800661 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800662 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 if (uiccCard == null) {
664 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800665 request.result = new IccOpenLogicalChannelResponse(-1,
666 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800670 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
671 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
675 case EVENT_OPEN_CHANNEL_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 int[] result = (int[]) ar.result;
681 int channelId = result[0];
682 byte[] selectResponse = null;
683 if (result.length > 1) {
684 selectResponse = new byte[result.length - 1];
685 for (int i = 1; i < result.length; ++i) {
686 selectResponse[i - 1] = (byte) result[i];
687 }
688 }
689 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700690 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.result == null) {
693 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 if (ar.exception != null) {
696 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
697 }
698
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700699 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700700 if (ar.exception instanceof CommandException) {
701 CommandException.Error error =
702 ((CommandException) (ar.exception)).getCommandError();
703 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700705 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 }
708 }
709 openChannelResp = new IccOpenLogicalChannelResponse(
710 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700712 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 break;
715
716 case CMD_CLOSE_CHANNEL:
717 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800718 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 if (uiccCard == null) {
720 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900721 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 } else {
724 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
725 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800730 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
731 break;
732
733 case CMD_NV_READ_ITEM:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
737 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 ar = (AsyncResult) msg.obj;
742 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800743 if (ar.exception == null && ar.result != null) {
744 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800746 request.result = "";
747 if (ar.result == null) {
748 loge("nvReadItem: Empty response");
749 } else if (ar.exception instanceof CommandException) {
750 loge("nvReadItem: CommandException: " +
751 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800753 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 }
755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 break;
758
Jake Hambye994d462014-02-03 13:10:13 -0800759 case CMD_NV_WRITE_ITEM:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
762 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_WRITE_ITEM_DONE:
768 handleNullReturnEvent(msg, "nvWriteItem");
769 break;
770
771 case CMD_NV_WRITE_CDMA_PRL:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
777 case EVENT_NV_WRITE_CDMA_PRL_DONE:
778 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
779 break;
780
chen xu6dac5ab2018-10-26 17:39:23 -0700781 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800782 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700783 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
chen xu6dac5ab2018-10-26 17:39:23 -0700787 case EVENT_RESET_MODEM_CONFIG_DONE:
788 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700791 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
794 request);
795 Phone phone = getPhoneFromRequest(request);
796 if (phone != null) {
797 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
798 } else {
799 loge("isNRDualConnectivityEnabled: No phone object");
800 request.result = false;
801 notifyRequester(request);
802 }
803 break;
804 }
805
806 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 // request.result must be set to something non-null
813 // for the calling thread to unblock
814 if (request.result != null) {
815 request.result = ar.result;
816 } else {
817 request.result = false;
818 }
819 if (ar.result == null) {
820 loge("isNRDualConnectivityEnabled: Empty response");
821 } else if (ar.exception instanceof CommandException) {
822 loge("isNRDualConnectivityEnabled: CommandException: "
823 + ar.exception);
824 } else {
825 loge("isNRDualConnectivityEnabled: Unknown exception");
826 }
827 }
828 notifyRequester(request);
829 break;
830
831 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
834 Phone phone = getPhoneFromRequest(request);
835 if (phone != null) {
836 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
837 request.workSource);
838 } else {
839 loge("enableNrDualConnectivity: No phone object");
840 request.result =
841 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
842 notifyRequester(request);
843 }
844 break;
845 }
846
847 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null) {
851 request.result =
852 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
853 } else {
854 request.result =
855 TelephonyManager
856 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
857 if (ar.exception instanceof CommandException) {
858 CommandException.Error error =
859 ((CommandException) (ar.exception)).getCommandError();
860 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
861 request.result =
862 TelephonyManager
863 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
864 }
865 loge("enableNrDualConnectivity" + ": CommandException: "
866 + ar.exception);
867 } else {
868 loge("enableNrDualConnectivity" + ": Unknown exception");
869 }
870 }
871 notifyRequester(request);
872 break;
873 }
874
SongFerngWang9e060372020-12-21 16:41:52 +0800875 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800877 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
878 request);
879 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 break;
881
SongFerngWang9e060372020-12-21 16:41:52 +0800882 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result; // Integer
887 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530888 // request.result must be set to something non-null
889 // for the calling thread to unblock
890 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800891 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800892 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800894 loge("getAllowedNetworkTypesBitmask: CommandException: "
895 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800897 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 break;
902
SongFerngWang9e060372020-12-21 16:41:52 +0800903 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800905 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
906 request);
907 Pair<Integer, Long> reasonWithNetworkTypes =
908 (Pair<Integer, Long>) request.argument;
909 getPhoneFromRequest(request).setAllowedNetworkTypes(
910 reasonWithNetworkTypes.first,
911 reasonWithNetworkTypes.second,
912 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 break;
914
SongFerngWang9e060372020-12-21 16:41:52 +0800915 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
916 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 break;
918
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000919 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
920 request = (MainThreadRequest)msg.obj;
921 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 break;
924
925 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
926 ar = (AsyncResult)msg.obj;
927 request = (MainThreadRequest)ar.userObj;
928 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000930 break;
931
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800932 case CMD_SET_VOICEMAIL_NUMBER:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
935 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800936 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
937 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800938 break;
939
940 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
941 handleNullReturnEvent(msg, "setVoicemailNumber");
942 break;
943
Stuart Scott54788802015-03-30 13:18:01 -0700944 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
947 request);
948 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
949 break;
950
951 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
952 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
953 break;
954
Shishir Agrawal302c8692015-06-19 13:49:39 -0700955 case CMD_PERFORM_NETWORK_SCAN:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
958 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
959 break;
960
Hall Liua1acea22020-09-18 19:04:59 -0700961 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700964 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
965 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
966 request.argument;
967 int callForwardingReason = args.first;
968 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800969 break;
Hall Liua1acea22020-09-18 19:04:59 -0700970 }
971 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700974 TelephonyManager.CallForwardingInfoCallback callback =
975 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
976 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800977 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700978 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800979 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
980 for (CallForwardInfo callForwardInfo : callForwardInfos) {
981 // Service Class is a bit mask per 3gpp 27.007. Search for
982 // any service for voice call.
983 if ((callForwardInfo.serviceClass
984 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700985 callForwardingInfo = new CallForwardingInfo(true,
986 callForwardInfo.reason,
987 callForwardInfo.number,
988 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800989 break;
990 }
991 }
992 // Didn't find a call forward info for voice call.
993 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700994 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
995 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800996 }
Hall Liua1acea22020-09-18 19:04:59 -0700997 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800998 } else {
999 if (ar.result == null) {
1000 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1001 }
1002 if (ar.exception != null) {
1003 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1004 }
Hall Liuae527aa2020-09-29 17:10:18 -07001005 int errorCode = TelephonyManager
1006 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001007 if (ar.exception instanceof CommandException) {
1008 CommandException.Error error =
1009 ((CommandException) (ar.exception)).getCommandError();
1010 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001011 errorCode = TelephonyManager
1012 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001013 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001014 errorCode = TelephonyManager
1015 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001016 }
1017 }
Hall Liua1acea22020-09-18 19:04:59 -07001018 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001019 }
sqian80370722020-01-29 15:02:51 -08001020 break;
Hall Liua1acea22020-09-18 19:04:59 -07001021 }
sqian80370722020-01-29 15:02:51 -08001022
Hall Liua1acea22020-09-18 19:04:59 -07001023 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001026 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001027 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001028 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1029 request.argument).first;
1030 request.phone.setCallForwardingOption(
1031 callForwardingInfoToSet.isEnabled()
1032 ? CommandsInterface.CF_ACTION_ENABLE
1033 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001034 callForwardingInfoToSet.getReason(),
1035 callForwardingInfoToSet.getNumber(),
1036 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1037 break;
Hall Liua1acea22020-09-18 19:04:59 -07001038 }
sqian80370722020-01-29 15:02:51 -08001039
Hall Liua1acea22020-09-18 19:04:59 -07001040 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001043 Consumer<Integer> callback =
1044 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1045 request.argument).second;
1046 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001047 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001048 int errorCode = TelephonyManager.CallForwardingInfoCallback
1049 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001050 if (ar.exception instanceof CommandException) {
1051 CommandException.Error error =
1052 ((CommandException) (ar.exception)).getCommandError();
1053 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001054 errorCode = TelephonyManager.CallForwardingInfoCallback
1055 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001057 errorCode = TelephonyManager.CallForwardingInfoCallback
1058 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001059 }
1060 }
1061 callback.accept(errorCode);
1062 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001063 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001064 }
sqian80370722020-01-29 15:02:51 -08001065 break;
Hall Liua1acea22020-09-18 19:04:59 -07001066 }
sqian80370722020-01-29 15:02:51 -08001067
Hall Liua1acea22020-09-18 19:04:59 -07001068 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1071 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1072 break;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
sqian80370722020-01-29 15:02:51 -08001074
Hall Liua1acea22020-09-18 19:04:59 -07001075 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001078 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001079 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1080 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001081 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001082 // Service Class is a bit mask per 3gpp 27.007.
1083 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001084 if (callForwardResults.length > 1
1085 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001086 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001087 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001088 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1089 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001090 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001091 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001092 }
1093 } else {
1094 if (ar.result == null) {
1095 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1096 }
1097 if (ar.exception != null) {
1098 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1099 }
1100 if (ar.exception instanceof CommandException) {
1101 CommandException.Error error =
1102 ((CommandException) (ar.exception)).getCommandError();
1103 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 callForwardingStatus =
1105 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1106 }
1107 }
1108 }
Hall Liua1acea22020-09-18 19:04:59 -07001109 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001110 break;
Hall Liua1acea22020-09-18 19:04:59 -07001111 }
sqian80370722020-01-29 15:02:51 -08001112
Hall Liua1acea22020-09-18 19:04:59 -07001113 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001116 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1117 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001118 break;
Hall Liua1acea22020-09-18 19:04:59 -07001119 }
sqian80370722020-01-29 15:02:51 -08001120
Hall Liua1acea22020-09-18 19:04:59 -07001121 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001124 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1125 Consumer<Integer> callback =
1126 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1127 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001128 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001129 if (ar.exception instanceof CommandException) {
1130 CommandException.Error error =
1131 ((CommandException) (ar.exception)).getCommandError();
1132 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1133 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1134 } else {
1135 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1136 }
1137 } else {
1138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1139 }
1140 } else {
1141 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1142 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001143 }
sqian80370722020-01-29 15:02:51 -08001144 break;
Hall Liua1acea22020-09-18 19:04:59 -07001145 }
sqian80370722020-01-29 15:02:51 -08001146
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 CellNetworkScanResult cellScanResult;
1151 if (ar.exception == null && ar.result != null) {
1152 cellScanResult = new CellNetworkScanResult(
1153 CellNetworkScanResult.STATUS_SUCCESS,
1154 (List<OperatorInfo>) ar.result);
1155 } else {
1156 if (ar.result == null) {
1157 loge("getCellNetworkScanResults: Empty response");
1158 }
1159 if (ar.exception != null) {
1160 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1161 }
1162 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1163 if (ar.exception instanceof CommandException) {
1164 CommandException.Error error =
1165 ((CommandException) (ar.exception)).getCommandError();
1166 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1167 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1168 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1169 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1170 }
1171 }
1172 cellScanResult = new CellNetworkScanResult(errorCode, null);
1173 }
1174 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001175 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 break;
1177
1178 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1179 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001180 ManualNetworkSelectionArgument selArg =
1181 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1183 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001184 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1185 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001186 break;
1187
1188 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 if (ar.exception == null) {
1192 request.result = true;
1193 } else {
1194 request.result = false;
1195 loge("setNetworkSelectionModeManual " + ar.exception);
1196 }
1197 notifyRequester(request);
1198 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001201 case CMD_GET_MODEM_ACTIVITY_INFO:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001204 if (defaultPhone != null) {
1205 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001206 } else {
1207 ResultReceiver result = (ResultReceiver) request.argument;
1208 Bundle bundle = new Bundle();
1209 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1210 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1211 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001212 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 break;
1214
1215 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001218 ResultReceiver result = (ResultReceiver) request.argument;
1219
1220 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001221 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001222 // Update the last modem activity info and the result of the request.
1223 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1224 if (isModemActivityInfoValid(info)) {
1225 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1226 int[] txTimeMs = info.getTransmitTimeMillis();
1227 int[] lastModemTxTimeMs = mLastModemActivityInfo
1228 .getTransmitTimeMillis();
1229 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1230 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1231 }
1232 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1233 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1234 + mLastModemActivityInfo.getSleepTimeMillis());
1235 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1236 + mLastModemActivityInfo.getIdleTimeMillis());
1237 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1238 mLastModemActivityInfo.setReceiveTimeMillis(
1239 info.getReceiveTimeMillis()
1240 + mLastModemActivityInfo.getReceiveTimeMillis());
1241 }
1242 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1243 mLastModemActivityInfo.getSleepTimeMillis(),
1244 mLastModemActivityInfo.getIdleTimeMillis(),
1245 mLastModemActivityInfo.getTransmitTimeMillis(),
1246 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001247 } else {
1248 if (ar.result == null) {
1249 loge("queryModemActivityInfo: Empty response");
1250 } else if (ar.exception instanceof CommandException) {
1251 loge("queryModemActivityInfo: CommandException: " +
1252 ar.exception);
1253 } else {
1254 loge("queryModemActivityInfo: Unknown exception");
1255 }
1256 }
sqian1a1be542020-03-05 11:37:28 -08001257 Bundle bundle = new Bundle();
1258 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1259 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001261 break;
1262
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 case CMD_SET_ALLOWED_CARRIERS:
1264 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001265 CarrierRestrictionRules argument =
1266 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001268 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 break;
1270
1271 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1272 ar = (AsyncResult) msg.obj;
1273 request = (MainThreadRequest) ar.userObj;
1274 if (ar.exception == null && ar.result != null) {
1275 request.result = ar.result;
1276 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001277 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 loge("setAllowedCarriers: CommandException: " + ar.exception);
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1283 request.result =
1284 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 } else {
1287 loge("setAllowedCarriers: Unknown exception");
1288 }
1289 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 break;
1292
1293 case CMD_GET_ALLOWED_CARRIERS:
1294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001296 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 break;
1298
1299 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
1302 if (ar.exception == null && ar.result != null) {
1303 request.result = ar.result;
1304 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001305 request.result = new IllegalStateException(
1306 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 if (ar.result == null) {
1308 loge("getAllowedCarriers: Empty response");
1309 } else if (ar.exception instanceof CommandException) {
1310 loge("getAllowedCarriers: CommandException: " +
1311 ar.exception);
1312 } else {
1313 loge("getAllowedCarriers: Unknown exception");
1314 }
1315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001317 break;
1318
Nathan Haroldb3014052017-01-25 15:57:32 -08001319 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
1322 if (ar.exception == null && ar.result != null) {
1323 request.result = ar.result;
1324 } else {
1325 request.result = new IllegalArgumentException(
1326 "Failed to retrieve Forbidden Plmns");
1327 if (ar.result == null) {
1328 loge("getForbiddenPlmns: Empty response");
1329 } else {
1330 loge("getForbiddenPlmns: Unknown exception");
1331 }
1332 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001334 break;
1335
1336 case CMD_GET_FORBIDDEN_PLMNS:
1337 request = (MainThreadRequest) msg.obj;
1338 uiccCard = getUiccCardFromRequest(request);
1339 if (uiccCard == null) {
1340 loge("getForbiddenPlmns() UiccCard is null");
1341 request.result = new IllegalArgumentException(
1342 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001343 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001344 break;
1345 }
1346 Integer appType = (Integer) request.argument;
1347 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1348 if (uiccApp == null) {
1349 loge("getForbiddenPlmns() no app with specified type -- "
1350 + appType);
1351 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001353 break;
1354 } else {
1355 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1356 + " specified type -- " + appType);
1357 }
1358 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1359 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1360 onCompleted);
1361 break;
1362
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001363 case CMD_SWITCH_SLOTS:
1364 request = (MainThreadRequest) msg.obj;
1365 int[] physicalSlots = (int[]) request.argument;
1366 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1367 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1368 break;
1369
1370 case EVENT_SWITCH_SLOTS_DONE:
1371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
1375 break;
1376 case CMD_GET_NETWORK_SELECTION_MODE:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1379 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1380 break;
1381
1382 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 if (ar.exception != null) {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1387 } else {
1388 int mode = ((int[]) ar.result)[0];
1389 if (mode == 0) {
1390 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1391 } else {
1392 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1393 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001394 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001395 notifyRequester(request);
1396 break;
1397 case CMD_GET_CDMA_ROAMING_MODE:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1400 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1401 break;
1402 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 if (ar.exception != null) {
1406 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1407 } else {
1408 request.result = ((int[]) ar.result)[0];
1409 }
1410 notifyRequester(request);
1411 break;
1412 case CMD_SET_CDMA_ROAMING_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1415 int mode = (int) request.argument;
1416 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1417 break;
1418 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 request.result = ar.exception == null;
1422 notifyRequester(request);
1423 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001424 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1425 request = (MainThreadRequest) msg.obj;
1426 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1427 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1428 break;
1429 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 if (ar.exception != null) {
1433 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1434 } else {
1435 request.result = ((int[]) ar.result)[0];
1436 }
1437 notifyRequester(request);
1438 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1442 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001443 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1444 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 break;
1446 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 request.result = ar.exception == null;
1450 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001451 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 case CMD_GET_ALL_CELL_INFO:
1453 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001455 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 case EVENT_GET_ALL_CELL_INFO_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001460 // If a timeout occurs, the response will be null
1461 request.result = (ar.exception == null && ar.result != null)
1462 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 synchronized (request) {
1464 request.notifyAll();
1465 }
1466 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001467 case CMD_REQUEST_CELL_INFO_UPDATE:
1468 request = (MainThreadRequest) msg.obj;
1469 request.phone.requestCellInfoUpdate(request.workSource,
1470 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1471 break;
1472 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1476 try {
1477 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001479 cb.onError(
1480 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1481 ar.exception.getClass().getName(),
1482 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001485 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001486 } else {
1487 // use the result as returned
1488 cb.onCellInfo((List<CellInfo>) ar.result);
1489 }
1490 } catch (RemoteException re) {
1491 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1492 }
1493 break;
Sarah Chincc055732020-11-18 13:39:35 -08001494 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 request = (MainThreadRequest) msg.obj;
1496 WorkSource ws = (WorkSource) request.argument;
1497 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001498 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 break;
Sarah Chincc055732020-11-18 13:39:35 -08001500 }
1501 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 if (ar.exception == null) {
1505 request.result = ar.result;
1506 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001507 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001509 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001510 }
1511
1512 synchronized (request) {
1513 request.notifyAll();
1514 }
1515 break;
Sarah Chincc055732020-11-18 13:39:35 -08001516 }
chen xu6dac5ab2018-10-26 17:39:23 -07001517 case CMD_MODEM_REBOOT:
1518 request = (MainThreadRequest) msg.obj;
1519 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001520 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001521 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001522 case EVENT_CMD_MODEM_REBOOT_DONE:
1523 handleNullReturnEvent(msg, "rebootModem");
1524 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001525 case CMD_REQUEST_ENABLE_MODEM:
1526 request = (MainThreadRequest) msg.obj;
1527 boolean enable = (boolean) request.argument;
1528 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001529 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001530 PhoneConfigurationManager.getInstance()
1531 .enablePhone(request.phone, enable, onCompleted);
1532 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001533 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001537 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001538 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001539 if ((boolean) request.result) {
1540 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1541 updateModemStateMetrics();
1542 } else {
1543 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1544 + ar.exception);
1545 }
1546 notifyRequester(request);
1547 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001548 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001549 case CMD_GET_MODEM_STATUS:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1552 PhoneConfigurationManager.getInstance()
1553 .getPhoneStatusFromModem(request.phone, onCompleted);
1554 break;
1555 case EVENT_GET_MODEM_STATUS_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 int id = request.phone.getPhoneId();
1559 if (ar.exception == null && ar.result != null) {
1560 request.result = ar.result;
1561 //update the cache as modem status has changed
1562 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1563 (boolean) request.result);
1564 } else {
1565 // Return true if modem status cannot be retrieved. For most cases,
1566 // modem status is on. And for older version modems, GET_MODEM_STATUS
1567 // and disable modem are not supported. Modem is always on.
1568 // TODO: this should be fixed in R to support a third
1569 // status UNKNOWN b/131631629
1570 request.result = true;
1571 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1572 + ar.exception);
1573 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001574 notifyRequester(request);
1575 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001576 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1577 request = (MainThreadRequest) msg.obj;
1578 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1579 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1580 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1581 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1582 break;
1583 }
1584 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1588 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1589 args.second.accept(ar.exception == null);
1590 notifyRequester(request);
1591 break;
1592 }
Sarah Chincc055732020-11-18 13:39:35 -08001593 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1594 request = (MainThreadRequest) msg.obj;
1595 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1596 Phone phone = getPhoneFromRequest(request);
1597 if (phone != null) {
1598 phone.getSystemSelectionChannels(onCompleted);
1599 } else {
1600 loge("getSystemSelectionChannels: No phone object");
1601 request.result = new ArrayList<RadioAccessSpecifier>();
1602 notifyRequester(request);
1603 }
1604 break;
1605 }
1606 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
1609 if (ar.exception == null && ar.result != null) {
1610 request.result = ar.result;
1611 } else {
1612 request.result = new IllegalArgumentException(
1613 "Failed to retrieve system selection channels");
1614 if (ar.result == null) {
1615 loge("getSystemSelectionChannels: Empty response");
1616 } else {
1617 loge("getSystemSelectionChannels: Unknown exception");
1618 }
1619 }
1620 notifyRequester(request);
1621 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001622 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = -1;
1629 loge("Failed to set Forbidden Plmns");
1630 if (ar.result == null) {
1631 loge("setForbidenPlmns: Empty response");
1632 } else if (ar.exception != null) {
1633 loge("setForbiddenPlmns: Exception: " + ar.exception);
1634 request.result = -1;
1635 } else {
1636 loge("setForbiddenPlmns: Unknown exception");
1637 }
1638 }
1639 notifyRequester(request);
1640 break;
1641 case CMD_SET_FORBIDDEN_PLMNS:
1642 request = (MainThreadRequest) msg.obj;
1643 uiccCard = getUiccCardFromRequest(request);
1644 if (uiccCard == null) {
1645 loge("setForbiddenPlmns: UiccCard is null");
1646 request.result = -1;
1647 notifyRequester(request);
1648 break;
1649 }
1650 Pair<Integer, List<String>> setFplmnsArgs =
1651 (Pair<Integer, List<String>>) request.argument;
1652 appType = setFplmnsArgs.first;
1653 List<String> fplmns = setFplmnsArgs.second;
1654 uiccApp = uiccCard.getApplicationByType(appType);
1655 if (uiccApp == null) {
1656 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1657 request.result = -1;
1658 loge("Failed to get UICC App");
1659 notifyRequester(request);
1660 } else {
1661 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1662 ((SIMRecords) uiccApp.getIccRecords())
1663 .setForbiddenPlmns(onCompleted, fplmns);
1664 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001665 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001666 case CMD_ERASE_MODEM_CONFIG:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1669 defaultPhone.eraseModemConfig(onCompleted);
1670 break;
1671 case EVENT_ERASE_MODEM_CONFIG_DONE:
1672 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001673 break;
zoey chenf95ca592019-12-30 16:11:23 +08001674
1675 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1678 Pair<String, String> changed = (Pair<String, String>) request.argument;
1679 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1680 changed.first, changed.second, onCompleted);
1681 break;
1682 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception == null) {
1686 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001687 // If the operation is successful, update the PIN storage
1688 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1689 int phoneId = getPhoneFromRequest(request).getPhoneId();
1690 UiccController.getInstance().getPinStorage()
1691 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001692 } else {
1693 request.result = msg.arg1;
1694 }
1695 notifyRequester(request);
1696 break;
1697
Michele Berionned9fbae52020-11-13 02:36:59 +00001698 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1701 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1702 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1703 enabled.first, enabled.second, onCompleted);
1704 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001705 }
zoey chenf95ca592019-12-30 16:11:23 +08001706 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1707 ar = (AsyncResult) msg.obj;
1708 request = (MainThreadRequest) ar.userObj;
1709 if (ar.exception == null) {
1710 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 // If the operation is successful, update the PIN storage
1712 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1713 int phoneId = getPhoneFromRequest(request).getPhoneId();
1714 if (enabled.first) {
1715 UiccController.getInstance().getPinStorage()
1716 .storePin(enabled.second, phoneId);
1717 } else {
1718 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1719 }
zoey chenf95ca592019-12-30 16:11:23 +08001720 } else {
1721 request.result = msg.arg1;
1722 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001723
1724
zoey chenf95ca592019-12-30 16:11:23 +08001725 notifyRequester(request);
1726 break;
1727
Peter Wangdafb9ac2020-01-15 14:13:38 -08001728 case MSG_NOTIFY_USER_ACTIVITY:
1729 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001730 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001731 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1732 getDefaultPhone().getContext().sendBroadcastAsUser(
1733 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1734 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001735
1736 case CMD_SET_DATA_THROTTLING: {
1737 request = (MainThreadRequest) msg.obj;
1738 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1739 DataThrottlingRequest dataThrottlingRequest =
1740 (DataThrottlingRequest) request.argument;
1741 Phone phone = getPhoneFromRequest(request);
1742 if (phone != null) {
1743 phone.setDataThrottling(onCompleted,
1744 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1745 dataThrottlingRequest.getCompletionDurationMillis());
1746 } else {
1747 loge("setDataThrottling: No phone object");
1748 request.result =
1749 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1750 notifyRequester(request);
1751 }
1752
1753 break;
1754 }
1755 case EVENT_SET_DATA_THROTTLING_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758
1759 if (ar.exception == null) {
1760 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1761 } else if (ar.exception instanceof CommandException) {
1762 loge("setDataThrottling: CommandException: " + ar.exception);
1763 CommandException.Error error =
1764 ((CommandException) (ar.exception)).getCommandError();
1765
1766 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1767 request.result = TelephonyManager
1768 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1769 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1770 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1771 } else {
1772 request.result =
1773 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1774 }
1775 } else {
1776 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1777 }
1778 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1779 notifyRequester(request);
1780 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001781
1782 case CMD_SET_SIM_POWER: {
1783 request = (MainThreadRequest) msg.obj;
1784 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1785 request = (MainThreadRequest) msg.obj;
1786 int stateToSet =
1787 ((Pair<Integer, IIntegerConsumer>)
1788 request.argument).first;
1789 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1790 break;
1791 }
1792 case EVENT_SET_SIM_POWER_DONE: {
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 IIntegerConsumer callback =
1796 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1797 if (ar.exception != null) {
1798 loge("setSimPower exception: " + ar.exception);
1799 int errorCode = TelephonyManager.CallForwardingInfoCallback
1800 .RESULT_ERROR_UNKNOWN;
1801 if (ar.exception instanceof CommandException) {
1802 CommandException.Error error =
1803 ((CommandException) (ar.exception)).getCommandError();
1804 if (error == CommandException.Error.SIM_ERR) {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1806 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1808 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1810 } else {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1812 }
1813 }
1814 try {
1815 callback.accept(errorCode);
1816 } catch (RemoteException e) {
1817 // Ignore if the remote process is no longer available to call back.
1818 Log.w(LOG_TAG, "setSimPower: callback not available.");
1819 }
1820 } else {
1821 try {
1822 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1823 } catch (RemoteException e) {
1824 // Ignore if the remote process is no longer available to call back.
1825 Log.w(LOG_TAG, "setSimPower: callback not available.");
1826 }
1827 }
1828 break;
1829 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001830 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1831 request = (MainThreadRequest) msg.obj;
1832
1833 final Phone phone = getPhoneFromRequest(request);
1834 if (phone == null || phone.getServiceStateTracker() == null) {
1835 request.result = new IllegalStateException("Phone or SST is null");
1836 notifyRequester(request);
1837 break;
1838 }
1839
1840 Pair<Integer, SignalStrengthUpdateRequest> pair =
1841 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1842 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1843 request);
1844 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1845 request.subId, pair.first /*callingUid*/,
1846 pair.second /*request*/, onCompleted);
1847 break;
1848 }
1849 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 // request.result will be the exception of ar if present, true otherwise.
1853 // Be cautious not to leave result null which will wait() forever
1854 request.result = ar.exception != null ? ar.exception : true;
1855 notifyRequester(request);
1856 break;
1857 }
1858 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1859 request = (MainThreadRequest) msg.obj;
1860
1861 Phone phone = getPhoneFromRequest(request);
1862 if (phone == null || phone.getServiceStateTracker() == null) {
1863 request.result = new IllegalStateException("Phone or SST is null");
1864 notifyRequester(request);
1865 break;
1866 }
1867
1868 Pair<Integer, SignalStrengthUpdateRequest> pair =
1869 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1870 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1871 request);
1872 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1873 request.subId, pair.first /*callingUid*/,
1874 pair.second /*request*/, onCompleted);
1875 break;
1876 }
1877 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1878 ar = (AsyncResult) msg.obj;
1879 request = (MainThreadRequest) ar.userObj;
1880 request.result = ar.exception != null ? ar.exception : true;
1881 notifyRequester(request);
1882 break;
1883 }
Jordan Liud5366d92020-11-24 14:50:34 -08001884
Michele Berionned9fbae52020-11-13 02:36:59 +00001885 case CMD_PREPARE_UNATTENDED_REBOOT:
1886 request = (MainThreadRequest) msg.obj;
1887 request.result =
1888 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1889 notifyRequester(request);
1890 break;
1891
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 default:
1893 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1894 break;
1895 }
1896 }
Jake Hambye994d462014-02-03 13:10:13 -08001897
Pengquan Menga1bb6272018-09-06 09:59:22 -07001898 private void notifyRequester(MainThreadRequest request) {
1899 synchronized (request) {
1900 request.notifyAll();
1901 }
1902 }
1903
Jake Hambye994d462014-02-03 13:10:13 -08001904 private void handleNullReturnEvent(Message msg, String command) {
1905 AsyncResult ar = (AsyncResult) msg.obj;
1906 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1907 if (ar.exception == null) {
1908 request.result = true;
1909 } else {
1910 request.result = false;
1911 if (ar.exception instanceof CommandException) {
1912 loge(command + ": CommandException: " + ar.exception);
1913 } else {
1914 loge(command + ": Unknown exception");
1915 }
1916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001917 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 /**
1922 * Posts the specified command to be executed on the main thread,
1923 * waits for the request to complete, and returns the result.
1924 * @see #sendRequestAsync
1925 */
1926 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001927 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1928 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001929 }
1930
1931 /**
1932 * Posts the specified command to be executed on the main thread,
1933 * waits for the request to complete, and returns the result.
1934 * @see #sendRequestAsync
1935 */
1936 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1937 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001938 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
1941 /**
1942 * Posts the specified command to be executed on the main thread,
1943 * waits for the request to complete, and returns the result.
1944 * @see #sendRequestAsync
1945 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001946 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001947 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1948 }
1949
1950 /**
1951 * Posts the specified command to be executed on the main thread,
1952 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1953 * if not timeout or null otherwise.
1954 * @see #sendRequestAsync
1955 */
1956 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1957 long timeoutInMs) {
1958 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete, and returns the result.
1964 * @see #sendRequestAsync
1965 */
Nathan Harold92bed182018-10-12 18:16:49 -07001966 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001967 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001968 }
1969
1970 /**
1971 * Posts the specified command to be executed on the main thread,
1972 * waits for the request to complete, and returns the result.
1973 * @see #sendRequestAsync
1974 */
1975 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001976 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1977 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001978 }
1979
1980 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001981 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1982 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1983 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001984 * @see #sendRequestAsync
1985 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001986 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1987 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1989 throw new RuntimeException("This method will deadlock if called from the main thread.");
1990 }
1991
Nathan Harold92bed182018-10-12 18:16:49 -07001992 MainThreadRequest request = null;
1993 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1994 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1995 } else if (phone != null) {
1996 request = new MainThreadRequest(argument, phone, workSource);
1997 } else {
1998 request = new MainThreadRequest(argument, subId, workSource);
1999 }
2000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 Message msg = mMainThreadHandler.obtainMessage(command, request);
2002 msg.sendToTarget();
2003
Rambo Wang0f050d82021-02-12 11:43:36 -08002004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002006 if (timeoutInMs >= 0) {
2007 // Wait for at least timeoutInMs before returning null request result
2008 long now = SystemClock.elapsedRealtime();
2009 long deadline = now + timeoutInMs;
2010 while (request == null && now < deadline) {
2011 try {
2012 request.wait(deadline - now);
2013 } catch (InterruptedException e) {
2014 // Do nothing, go back and check if request is completed or timeout
2015 } finally {
2016 now = SystemClock.elapsedRealtime();
2017 }
2018 }
2019 } else {
2020 // Wait for the request to complete
2021 while (request.result == null) {
2022 try {
2023 request.wait();
2024 } catch (InterruptedException e) {
2025 // Do nothing, go back and wait until the request is complete
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028 }
2029 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 if (request.result == null) {
2031 Log.wtf(LOG_TAG,
2032 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 return request.result;
2035 }
2036
2037 /**
2038 * Asynchronous ("fire and forget") version of sendRequest():
2039 * Posts the specified command to be executed on the main thread, and
2040 * returns immediately.
2041 * @see #sendRequest
2042 */
2043 private void sendRequestAsync(int command) {
2044 mMainThreadHandler.sendEmptyMessage(command);
2045 }
2046
2047 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002048 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002049 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002050 */
2051 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002052 sendRequestAsync(command, argument, null, null);
2053 }
2054
2055 /**
2056 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2057 * @see {@link #sendRequest(int,Object)}
2058 */
2059 private void sendRequestAsync(
2060 int command, Object argument, Phone phone, WorkSource workSource) {
2061 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002062 Message msg = mMainThreadHandler.obtainMessage(command, request);
2063 msg.sendToTarget();
2064 }
2065
2066 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 * Initialize the singleton PhoneInterfaceManager instance.
2068 * This is only done once, at startup, from PhoneApp.onCreate().
2069 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002070 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 synchronized (PhoneInterfaceManager.class) {
2072 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002073 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 } else {
2075 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2076 }
2077 return sInstance;
2078 }
2079 }
2080
2081 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002082 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002085 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002086 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2088 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002089 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mTelephonySharedPreferences =
2091 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002092 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002093 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002094 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002095
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 publish();
2097 }
2098
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002099 private Phone getDefaultPhone() {
2100 Phone thePhone = getPhone(getDefaultSubscription());
2101 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2102 }
2103
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 private void publish() {
2105 if (DBG) log("publish: " + this);
2106
Peter Wangc035ce42020-01-08 21:00:22 -08002107 TelephonyFrameworkInitializer
2108 .getTelephonyServiceManager()
2109 .getTelephonyServiceRegisterer()
2110 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Stuart Scott584921c2015-01-15 17:10:34 -08002113 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002114 if (request.phone != null) {
2115 return request.phone;
2116 } else {
2117 return getPhoneFromSubId(request.subId);
2118 }
2119 }
2120
2121 private Phone getPhoneFromSubId(int subId) {
2122 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2123 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002124 }
2125
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002126 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2127 Phone phone = getPhoneFromRequest(request);
2128 return phone == null ? null :
2129 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2130 }
2131
Wink Saville36469e72014-06-11 15:17:00 -07002132 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002134 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002137 private void sendEraseModemConfig(Phone phone) {
2138 if (phone != null) {
2139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2140 mApp, phone.getSubId(), "eraseModemConfig");
2141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2144 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
2147 }
2148 }
2149 }
2150
Peter Wang050bb052020-01-13 23:33:09 -08002151 private boolean isImsAvailableOnDevice() {
2152 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2153 if (pm == null) {
2154 // For some reason package manger is not available.. This will fail internally anyway,
2155 // so do not throw error and allow.
2156 return true;
2157 }
2158 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2159 }
2160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002162 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
Wink Savilleb564aae2014-10-23 10:18:09 -07002165 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 if (DBG) log("dial: " + number);
2167 // No permission check needed here: This is just a wrapper around the
2168 // ACTION_DIAL intent, which is available to any app since it puts up
2169 // the UI before it does anything.
2170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 String url = createTelUrl(number);
2174 if (url == null) {
2175 return;
2176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 // PENDING: should we just silently fail if phone is offhook or ringing?
2179 PhoneConstants.State state = mCM.getState(subId);
2180 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2181 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2182 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2183 mApp.startActivity(intent);
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188 }
2189
2190 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002191 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 if (DBG) log("call: " + number);
2196
2197 // This is just a wrapper around the ACTION_CALL intent, but we still
2198 // need to do a permission check since we're calling startActivity()
2199 // from the context of the phone app.
2200 enforceCallPermission();
2201
Jordan Liu1617b712019-07-10 15:06:26 -07002202 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 != AppOpsManager.MODE_ALLOWED) {
2204 return;
2205 }
2206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 String url = createTelUrl(number);
2210 if (url == null) {
2211 return;
2212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 boolean isValid = false;
2215 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2216 if (slist != null) {
2217 for (SubscriptionInfo subInfoRecord : slist) {
2218 if (subInfoRecord.getSubscriptionId() == subId) {
2219 isValid = true;
2220 break;
2221 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002222 }
Wink Saville08874612014-08-31 19:19:58 -07002223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 if (!isValid) {
2225 return;
2226 }
Wink Saville08874612014-08-31 19:19:58 -07002227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2229 intent.putExtra(SUBSCRIPTION_KEY, subId);
2230 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2231 mApp.startActivity(intent);
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002238 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002239 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2240 }
2241
Wink Savilleb564aae2014-10-23 10:18:09 -07002242 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002244 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2245 }
2246
Wink Savilleb564aae2014-10-23 10:18:09 -07002247 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249
2250 final long identity = Binder.clearCallingIdentity();
2251 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002252 Phone phone = getPhone(subId);
2253 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 checkSimPin.start();
2255 return checkSimPin.unlockSim(null, pin);
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Wink Savilleb564aae2014-10-23 10:18:09 -07002261 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002266 Phone phone = getPhone(subId);
2267 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 checkSimPuk.start();
2269 return checkSimPuk.unlockSim(puk, pin);
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002276 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 * a synchronous one.
2278 */
2279 private static class UnlockSim extends Thread {
2280
2281 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002282 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283
2284 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002285 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2286 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287
2288 // For replies from SimCard interface
2289 private Handler mHandler;
2290
2291 // For async handler to identify request type
2292 private static final int SUPPLY_PIN_COMPLETE = 100;
2293
Michele Berionned9fbae52020-11-13 02:36:59 +00002294 UnlockSim(int phoneId, IccCard simCard) {
2295 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 mSimCard = simCard;
2297 }
2298
2299 @Override
2300 public void run() {
2301 Looper.prepare();
2302 synchronized (UnlockSim.this) {
2303 mHandler = new Handler() {
2304 @Override
2305 public void handleMessage(Message msg) {
2306 AsyncResult ar = (AsyncResult) msg.obj;
2307 switch (msg.what) {
2308 case SUPPLY_PIN_COMPLETE:
2309 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2310 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002311 mRetryCount = msg.arg1;
2312 if (ar.exception != null) {
2313 if (ar.exception instanceof CommandException &&
2314 ((CommandException)(ar.exception)).getCommandError()
2315 == CommandException.Error.PASSWORD_INCORRECT) {
2316 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002317 } //When UiccCardApp dispose,handle message and return exception
2318 else if (ar.exception instanceof CommandException &&
2319 ((CommandException) (ar.exception)).getCommandError()
2320 == CommandException.Error.ABORTED) {
2321 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002322 } else {
2323 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2324 }
2325 } else {
2326 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mDone = true;
2329 UnlockSim.this.notifyAll();
2330 }
2331 break;
2332 }
2333 }
2334 };
2335 UnlockSim.this.notifyAll();
2336 }
2337 Looper.loop();
2338 }
2339
2340 /*
2341 * Use PIN or PUK to unlock SIM card
2342 *
2343 * If PUK is null, unlock SIM card with PIN
2344 *
2345 * If PUK is not null, unlock SIM card with PUK and set PIN code
2346 */
Wink Saville9de0f752013-10-22 19:04:03 -07002347 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348
2349 while (mHandler == null) {
2350 try {
2351 wait();
2352 } catch (InterruptedException e) {
2353 Thread.currentThread().interrupt();
2354 }
2355 }
2356 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2357
2358 if (puk == null) {
2359 mSimCard.supplyPin(pin, callback);
2360 } else {
2361 mSimCard.supplyPuk(puk, pin, callback);
2362 }
2363
2364 while (!mDone) {
2365 try {
2366 Log.d(LOG_TAG, "wait for done");
2367 wait();
2368 } catch (InterruptedException e) {
2369 // Restore the interrupted status
2370 Thread.currentThread().interrupt();
2371 }
2372 }
2373 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002374 int[] resultArray = new int[2];
2375 resultArray[0] = mResult;
2376 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002377
2378 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2379 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2380 }
2381
Wink Saville9de0f752013-10-22 19:04:03 -07002382 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
2384 }
2385
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002386 /**
2387 * This method has been removed due to privacy and stability concerns.
2388 */
2389 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002391 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2392 return;
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Nathan Harold1f889d82020-06-04 17:05:26 -07002395 @Override
2396 public void updateServiceLocationWithPackageName(String callingPackage) {
2397 mApp.getSystemService(AppOpsManager.class)
2398 .checkPackage(Binder.getCallingUid(), callingPackage);
2399
Nathan Haroldf096d982020-11-18 17:18:06 -08002400 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002401 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2402 // Callers targeting S have no business invoking this method.
2403 return;
2404 }
2405
2406 LocationAccessPolicy.LocationPermissionResult locationResult =
2407 LocationAccessPolicy.checkLocationPermission(mApp,
2408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2409 .setCallingPackage(callingPackage)
2410 .setCallingFeatureId(null)
2411 .setCallingPid(Binder.getCallingPid())
2412 .setCallingUid(Binder.getCallingUid())
2413 .setMethod("updateServiceLocation")
2414 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2415 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2416 .build());
2417 // Apps that lack location permission have no business calling this method;
2418 // however, because no permission was declared in the public API, denials must
2419 // all be "soft".
2420 switch (locationResult) {
2421 case DENIED_HARD: /* fall through */
2422 case DENIED_SOFT:
2423 return;
2424 }
2425
2426 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002429 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002431 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002438 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
2440 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002444
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002446 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2447 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2448 callingFeatureId);
2449 }
2450
2451 @Deprecated
2452 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2455 }
2456
2457 @Override
2458 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2459 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002461 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 return false;
2463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 return isRadioOnForSubscriber(subId);
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 }
2472
2473 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2479 } else {
2480 return false;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002488 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
Wink Saville36469e72014-06-11 15:17:00 -07002490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 final Phone phone = getPhone(subId);
2497 if (phone != null) {
2498 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 }
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
2505 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002506 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone == null) {
2516 return false;
2517 }
2518 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2519 toggleRadioOnOffForSubscriber(subId);
2520 }
2521 return true;
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
Wink Saville36469e72014-06-11 15:17:00 -07002526
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002527 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002528 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002529 /*
2530 * If any of the Radios are available, it will need to be
2531 * shutdown. So return true if any Radio is available.
2532 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2536 Phone phone = PhoneFactory.getPhone(i);
2537 if (phone != null && phone.isRadioAvailable()) return true;
2538 }
2539 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2540 return false;
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002544 }
2545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 enforceModifyPermission();
2549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2553 logv("Shutting down Phone " + i);
2554 shutdownRadioUsingPhoneId(i);
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002558 }
2559 }
2560
2561 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 Phone phone = PhoneFactory.getPhone(phoneId);
2563 if (phone != null && phone.isRadioAvailable()) {
2564 phone.shutdownRadio();
2565 }
2566 }
2567
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2574 if (defaultPhone != null) {
2575 defaultPhone.setRadioPower(turnOn);
2576 return true;
2577 } else {
2578 loge("There's no default phone.");
2579 return false;
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002583 }
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Wink Savilleb564aae2014-10-23 10:18:09 -07002586 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 final Phone phone = getPhone(subId);
2592 if (phone != null) {
2593 phone.setRadioPower(turnOn);
2594 return true;
2595 } else {
2596 return false;
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 }
2602
Wink Saville36469e72014-06-11 15:17:00 -07002603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 public boolean enableDataConnectivity() {
2606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 int subId = mSubscriptionController.getDefaultDataSubId();
2611 final Phone phone = getPhone(subId);
2612 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002613 phone.getDataEnabledSettings().setDataEnabled(
2614 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 return true;
2616 } else {
2617 return false;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
Wink Saville36469e72014-06-11 15:17:00 -07002624 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002625 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 public boolean disableDataConnectivity() {
2627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 int subId = mSubscriptionController.getDefaultDataSubId();
2632 final Phone phone = getPhone(subId);
2633 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002634 phone.getDataEnabledSettings().setDataEnabled(
2635 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 return true;
2637 } else {
2638 return false;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
Sanket Padawe356d7632015-06-22 14:03:32 -07002645 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002646 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002651 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } else {
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002662 }
2663
pkanwarae03a6b2016-11-06 20:37:09 -08002664 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 enforceCallPermission();
2666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2670 return;
2671 }
2672 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2673 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
pkanwar32d516d2016-10-14 19:37:38 -07002677 };
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2685 return false;
2686 }
2687 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002694 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002697 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 Phone phone = PhoneFactory.getPhone(slotIndex);
2701 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2702 PhoneConstantConversions.convertCallState(phone.getState());
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002709 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002710 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2711 }
2712
2713 @Override
2714 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 if (phone != null) {
2719 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2720 } else {
2721 return PhoneConstantConversions.convertDataState(
2722 PhoneConstants.DataState.DISCONNECTED);
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002730 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002731 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2732 }
2733
2734 @Override
2735 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (phone != null) {
2740 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2741 } else {
2742 return TelephonyManager.DATA_ACTIVITY_NONE;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
2749 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002750 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002752 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002753
2754 LocationAccessPolicy.LocationPermissionResult locationResult =
2755 LocationAccessPolicy.checkLocationPermission(mApp,
2756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2757 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002759 .setCallingPid(Binder.getCallingPid())
2760 .setCallingUid(Binder.getCallingUid())
2761 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002762 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002763 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2764 .build());
2765 switch (locationResult) {
2766 case DENIED_HARD:
2767 throw new SecurityException("Not allowed to access cell location");
2768 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002769 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2770 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002773 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002777 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002778 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Svetoslav64fad262015-04-14 14:35:21 -07002782 }
2783
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 @Override
Jack Yu01425032020-02-22 19:38:58 -08002785 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002786 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2787 // registered cell info, so return a NULL country instead.
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002790 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2791 // Get default phone in this case.
2792 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2793 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002794 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002796 if (phone == null) return "";
2797 ServiceStateTracker sst = phone.getServiceStateTracker();
2798 if (sst == null) return "";
2799 LocaleTracker lt = sst.getLocaleTracker();
2800 if (lt == null) return "";
Shuo Qian9418a922021-03-09 11:21:16 -08002801 return lt.getCurrentCountry();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002802 } finally {
2803 Binder.restoreCallingIdentity(identity);
2804 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002805 }
2806
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002807 /**
2808 * This method was removed due to potential issues caused by performing partial
2809 * updates of service state, and lack of a credible use case.
2810 *
2811 * This has the ability to break the telephony implementation by disabling notification of
2812 * changes in device connectivity. DO NOT USE THIS!
2813 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002814 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002815 public void enableLocationUpdates() {
2816 mApp.enforceCallingOrSelfPermission(
2817 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002818 }
2819
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002820 /**
2821 * This method was removed due to potential issues caused by performing partial
2822 * updates of service state, and lack of a credible use case.
2823 *
2824 * This has the ability to break the telephony implementation by disabling notification of
2825 * changes in device connectivity. DO NOT USE THIS!
2826 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002827 @Override
2828 public void disableLocationUpdates() {
2829 mApp.enforceCallingOrSelfPermission(
2830 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002831 }
2832
2833 @Override
2834 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002835 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2836 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002837 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002838 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2839 throw new SecurityException(
2840 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2841 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002842
Jordan Liu1617b712019-07-10 15:06:26 -07002843 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002844 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2845 return null;
2846 }
Svetoslav64fad262015-04-14 14:35:21 -07002847
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002848 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002849
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002850 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002851 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002852
Nathan Haroldf180aac2018-06-01 18:43:55 -07002853 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2854 for (CellInfo ci : info) {
2855 if (ci instanceof CellInfoGsm) {
2856 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2857 } else if (ci instanceof CellInfoWcdma) {
2858 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2859 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002860 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002861 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
2863
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002864 private List<CellInfo> getCachedCellInfo() {
2865 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2866 for (Phone phone : PhoneFactory.getPhones()) {
2867 List<CellInfo> info = phone.getAllCellInfo();
2868 if (info != null) cellInfos.addAll(info);
2869 }
2870 return cellInfos;
2871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872
2873 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002874 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002875 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002876 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002877
2878 LocationAccessPolicy.LocationPermissionResult locationResult =
2879 LocationAccessPolicy.checkLocationPermission(mApp,
2880 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2881 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002882 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002883 .setCallingPid(Binder.getCallingPid())
2884 .setCallingUid(Binder.getCallingUid())
2885 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002886 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002887 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2888 .build());
2889 switch (locationResult) {
2890 case DENIED_HARD:
2891 throw new SecurityException("Not allowed to access cell info");
2892 case DENIED_SOFT:
2893 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002894 }
2895
Nathan Haroldf096d982020-11-18 17:18:06 -08002896 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002897 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2898 return getCachedCellInfo();
2899 }
2900
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002901 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002902 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903 final long identity = Binder.clearCallingIdentity();
2904 try {
2905 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2906 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002907 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002908 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 if (info != null) cellInfos.addAll(info);
2910 }
2911 return cellInfos;
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002914 }
2915 }
2916
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002917 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002918 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2919 String callingFeatureId) {
2920 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2921 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002922 }
2923
2924 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2926 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002927 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002928 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002931 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2932 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002933 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002934 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002935
2936 LocationAccessPolicy.LocationPermissionResult locationResult =
2937 LocationAccessPolicy.checkLocationPermission(mApp,
2938 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2939 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002940 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002941 .setCallingPid(Binder.getCallingPid())
2942 .setCallingUid(Binder.getCallingUid())
2943 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002944 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2945 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002946 .build());
2947 switch (locationResult) {
2948 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002949 if (TelephonyPermissions
2950 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002951 // Safetynet logging for b/154934934
2952 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2953 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002954 throw new SecurityException("Not allowed to access cell info");
2955 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002956 if (TelephonyPermissions
2957 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002958 // Safetynet logging for b/154934934
2959 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2960 }
Nathan Harold5320c422019-05-09 10:26:08 -07002961 try {
2962 cb.onCellInfo(new ArrayList<CellInfo>());
2963 } catch (RemoteException re) {
2964 // Drop without consequences
2965 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002966 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002967 }
2968
Nathan Harolda939a962019-05-09 10:13:47 -07002969
2970 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002971 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2972
2973 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2974 }
2975
2976 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002977 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002978 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002979 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002983 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002987 }
2988
Shishir Agrawala9f32182016-04-12 12:00:16 -07002989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002990 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002991 Phone phone = PhoneFactory.getPhone(slotIndex);
2992 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002993 return null;
2994 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002995 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002996 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002998 return null;
2999 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003000
3001 final long identity = Binder.clearCallingIdentity();
3002 try {
3003 return phone.getImei();
3004 } finally {
3005 Binder.restoreCallingIdentity(identity);
3006 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003007 }
3008
3009 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003010 public String getTypeAllocationCodeForSlot(int slotIndex) {
3011 Phone phone = PhoneFactory.getPhone(slotIndex);
3012 String tac = null;
3013 if (phone != null) {
3014 String imei = phone.getImei();
3015 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3016 }
3017 return tac;
3018 }
3019
3020 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003021 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003022 Phone phone = PhoneFactory.getPhone(slotIndex);
3023 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003024 return null;
3025 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003026
Jeff Davidson913390f2018-02-23 17:11:49 -08003027 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003028 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003029 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003030 return null;
3031 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 return phone.getMeid();
3036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Jack Yu2af8d712017-03-15 17:14:14 -07003039 }
3040
3041 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003042 public String getManufacturerCodeForSlot(int slotIndex) {
3043 Phone phone = PhoneFactory.getPhone(slotIndex);
3044 String manufacturerCode = null;
3045 if (phone != null) {
3046 String meid = phone.getMeid();
3047 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3048 }
3049 return manufacturerCode;
3050 }
3051
3052 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003053 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3054 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003055 Phone phone = PhoneFactory.getPhone(slotIndex);
3056 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003057 return null;
3058 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003059 int subId = phone.getSubId();
3060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003061 mApp, subId, callingPackage, callingFeatureId,
3062 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003063 return null;
3064 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065
3066 final long identity = Binder.clearCallingIdentity();
3067 try {
3068 return phone.getDeviceSvn();
3069 } finally {
3070 Binder.restoreCallingIdentity(identity);
3071 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003072 }
3073
fionaxu43304da2017-11-27 22:51:16 -08003074 @Override
3075 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003076 final long identity = Binder.clearCallingIdentity();
3077 try {
3078 final Phone phone = getPhone(subId);
3079 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3080 } finally {
3081 Binder.restoreCallingIdentity(identity);
3082 }
fionaxu43304da2017-11-27 22:51:16 -08003083 }
3084
3085 @Override
3086 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087 final long identity = Binder.clearCallingIdentity();
3088 try {
3089 final Phone phone = getPhone(subId);
3090 return phone == null ? null : phone.getCarrierName();
3091 } finally {
3092 Binder.restoreCallingIdentity(identity);
3093 }
fionaxu43304da2017-11-27 22:51:16 -08003094 }
3095
calvinpanffe225e2018-11-01 19:43:06 +08003096 @Override
chen xu0026ca62019-03-06 15:28:50 -08003097 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003098 final long identity = Binder.clearCallingIdentity();
3099 try {
3100 final Phone phone = getPhone(subId);
3101 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003102 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003103 } finally {
3104 Binder.restoreCallingIdentity(identity);
3105 }
3106 }
3107
3108 @Override
chen xu0026ca62019-03-06 15:28:50 -08003109 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003110 final long identity = Binder.clearCallingIdentity();
3111 try {
3112 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003113 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003114 } finally {
3115 Binder.restoreCallingIdentity(identity);
3116 }
3117 }
3118
chen xu651eec72018-11-11 19:03:44 -08003119 @Override
chen xu864e11c2018-12-06 22:10:03 -08003120 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3121 if (!isSubscriptionMccMnc) {
3122 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3123 }
chen xu651eec72018-11-11 19:03:44 -08003124 final Phone phone = PhoneFactory.getPhone(slotIndex);
3125 if (phone == null) {
3126 return TelephonyManager.UNKNOWN_CARRIER_ID;
3127 }
3128 final long identity = Binder.clearCallingIdentity();
3129 try {
3130 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
3133 }
3134 }
3135
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003136 //
3137 // Internal helper methods.
3138 //
3139
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003140 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003141 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3142 *
3143 * @throws SecurityException if the caller does not have the required permission
3144 */
3145 private void enforceModifyPermission() {
3146 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3147 }
3148
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003149 /**
3150 * Make sure the caller is system.
3151 *
3152 * @throws SecurityException if the caller is not system.
3153 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003154 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003155 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3156 throw new SecurityException("Caller must be system");
3157 }
3158 }
3159
Shuo Qianf2b2df42019-11-13 17:43:31 -08003160 private void enforceActiveEmergencySessionPermission() {
3161 mApp.enforceCallingOrSelfPermission(
3162 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3163 }
3164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003165 /**
3166 * Make sure the caller has the CALL_PHONE permission.
3167 *
3168 * @throws SecurityException if the caller does not have the required permission
3169 */
3170 private void enforceCallPermission() {
3171 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3172 }
3173
paulhu423b5f22019-08-23 19:17:33 +08003174 private void enforceSettingsPermission() {
3175 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003176 }
3177
Michele Berionned9fbae52020-11-13 02:36:59 +00003178 private void enforceRebootPermission() {
3179 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3180 }
3181
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003182 private String createTelUrl(String number) {
3183 if (TextUtils.isEmpty(number)) {
3184 return null;
3185 }
3186
Jake Hambye994d462014-02-03 13:10:13 -08003187 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 }
3189
Ihab Awadf9e92732013-12-05 18:02:52 -08003190 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003191 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3192 }
3193
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003194 private static void logv(String msg) {
3195 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3196 }
3197
Ihab Awadf9e92732013-12-05 18:02:52 -08003198 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003199 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3200 }
3201
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003202 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003203 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003204 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003205 }
3206
Sanket Padawe356d7632015-06-22 14:03:32 -07003207 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003208 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003209 final long identity = Binder.clearCallingIdentity();
3210 try {
3211 final Phone phone = PhoneFactory.getPhone(slotIndex);
3212 if (phone == null) {
3213 return PhoneConstants.PHONE_TYPE_NONE;
3214 } else {
3215 return phone.getPhoneType();
3216 }
3217 } finally {
3218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003220 }
3221
3222 /**
3223 * Returns the CDMA ERI icon index to display
3224 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003225 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003226 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3227 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3228 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003229 }
3230
Sanket Padawe356d7632015-06-22 14:03:32 -07003231 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003232 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3233 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003234 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003235 mApp, subId, callingPackage, callingFeatureId,
3236 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003237 return -1;
3238 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003239
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 final Phone phone = getPhone(subId);
3243 if (phone != null) {
3244 return phone.getCdmaEriIconIndex();
3245 } else {
3246 return -1;
3247 }
3248 } finally {
3249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003251 }
3252
3253 /**
3254 * Returns the CDMA ERI icon mode,
3255 * 0 - ON
3256 * 1 - FLASHING
3257 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003258 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003259 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3260 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3261 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003262 }
3263
Sanket Padawe356d7632015-06-22 14:03:32 -07003264 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003265 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3266 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003267 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003268 mApp, subId, callingPackage, callingFeatureId,
3269 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003270 return -1;
3271 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003272
3273 final long identity = Binder.clearCallingIdentity();
3274 try {
3275 final Phone phone = getPhone(subId);
3276 if (phone != null) {
3277 return phone.getCdmaEriIconMode();
3278 } else {
3279 return -1;
3280 }
3281 } finally {
3282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003284 }
3285
3286 /**
3287 * Returns the CDMA ERI text,
3288 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003290 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3291 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3292 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003293 }
3294
Sanket Padawe356d7632015-06-22 14:03:32 -07003295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3297 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003298 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003299 mApp, subId, callingPackage, callingFeatureId,
3300 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003301 return null;
3302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003303
3304 final long identity = Binder.clearCallingIdentity();
3305 try {
3306 final Phone phone = getPhone(subId);
3307 if (phone != null) {
3308 return phone.getCdmaEriText();
3309 } else {
3310 return null;
3311 }
3312 } finally {
3313 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003314 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003315 }
3316
3317 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003318 * Returns the CDMA MDN.
3319 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003320 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003321 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003322 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3323 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003324
3325 final long identity = Binder.clearCallingIdentity();
3326 try {
3327 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003328 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003329 return phone.getLine1Number();
3330 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003331 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003332 return null;
3333 }
3334 } finally {
3335 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003336 }
3337 }
3338
3339 /**
3340 * Returns the CDMA MIN.
3341 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003342 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003343 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3345 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003346
3347 final long identity = Binder.clearCallingIdentity();
3348 try {
3349 final Phone phone = getPhone(subId);
3350 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3351 return phone.getCdmaMin();
3352 } else {
3353 return null;
3354 }
3355 } finally {
3356 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003357 }
3358 }
3359
Hall Liud892bec2018-11-30 14:51:45 -08003360 @Override
3361 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3362 INumberVerificationCallback callback, String callingPackage) {
3363 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3364 != PERMISSION_GRANTED) {
3365 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3366 }
3367 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3368
3369 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3370 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003371 throw new SecurityException("Calling package must be configured in the device config: "
3372 + "calling package: " + callingPackage
3373 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003374 }
3375
3376 if (range == null) {
3377 throw new NullPointerException("Range must be non-null");
3378 }
3379
3380 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003381 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003382
3383 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3384 }
3385
Junda Liuca05d5d2014-08-14 22:36:34 -07003386 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003387 * Returns true if CDMA provisioning needs to run.
3388 */
3389 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 final long identity = Binder.clearCallingIdentity();
3391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003392 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003393 } finally {
3394 Binder.restoreCallingIdentity(identity);
3395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003396 }
3397
3398 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003399 * Sets the voice mail number of a given subId.
3400 */
3401 @Override
3402 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003403 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3404 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003405
3406 final long identity = Binder.clearCallingIdentity();
3407 try {
3408 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3409 new Pair<String, String>(alphaTag, number), new Integer(subId));
3410 return success;
3411 } finally {
3412 Binder.restoreCallingIdentity(identity);
3413 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003414 }
3415
Ta-wei Yen87c49842016-05-13 21:19:52 -07003416 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003417 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3418 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003419 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3420 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003421 if (!TextUtils.equals(callingPackage, systemDialer)) {
3422 throw new SecurityException("caller must be system dialer");
3423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003424
3425 final long identity = Binder.clearCallingIdentity();
3426 try {
3427 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3428 if (phoneAccountHandle == null) {
3429 return null;
3430 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003431 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003432 } finally {
3433 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003434 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003435 }
3436
3437 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003438 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3439 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003440 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003441 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003442 mApp, subId, callingPackage, callingFeatureId,
3443 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003444 return null;
3445 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003446
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003447 final long identity = Binder.clearCallingIdentity();
3448 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003449 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003450 } finally {
3451 Binder.restoreCallingIdentity(identity);
3452 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003453 }
3454
3455 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003456 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3457 VisualVoicemailSmsFilterSettings settings) {
3458 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003459
3460 final long identity = Binder.clearCallingIdentity();
3461 try {
3462 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003463 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003464 } finally {
3465 Binder.restoreCallingIdentity(identity);
3466 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003467 }
3468
3469 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003470 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472
3473 final long identity = Binder.clearCallingIdentity();
3474 try {
3475 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003476 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003477 } finally {
3478 Binder.restoreCallingIdentity(identity);
3479 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003480 }
3481
3482 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003483 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3484 String callingPackage, int subId) {
3485 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003490 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 } finally {
3492 Binder.restoreCallingIdentity(identity);
3493 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003494 }
3495
3496 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003497 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003498 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003499
3500 final long identity = Binder.clearCallingIdentity();
3501 try {
3502 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003503 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003504 } finally {
3505 Binder.restoreCallingIdentity(identity);
3506 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003507 }
3508
3509 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003510 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3511 String callingAttributionTag, int subId, String number, int port, String text,
3512 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003513 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003514 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003516 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003517 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3518 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003519 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003520
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003521 /**
fionaxu0152e512016-11-14 13:36:14 -08003522 * Sets the voice activation state of a given subId.
3523 */
3524 @Override
3525 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3527 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003528
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 final Phone phone = getPhone(subId);
3532 if (phone != null) {
3533 phone.setVoiceActivationState(activationState);
3534 } else {
3535 loge("setVoiceActivationState fails with invalid subId: " + subId);
3536 }
3537 } finally {
3538 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003539 }
3540 }
3541
3542 /**
3543 * Sets the data activation state of a given subId.
3544 */
3545 @Override
3546 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003547 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3548 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549
3550 final long identity = Binder.clearCallingIdentity();
3551 try {
3552 final Phone phone = getPhone(subId);
3553 if (phone != null) {
3554 phone.setDataActivationState(activationState);
3555 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003556 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003557 }
3558 } finally {
3559 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003560 }
3561 }
3562
3563 /**
3564 * Returns the voice activation state of a given subId.
3565 */
3566 @Override
3567 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003569
fionaxu0152e512016-11-14 13:36:14 -08003570 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571 final long identity = Binder.clearCallingIdentity();
3572 try {
3573 if (phone != null) {
3574 return phone.getVoiceActivationState();
3575 } else {
3576 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3577 }
3578 } finally {
3579 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003580 }
3581 }
3582
3583 /**
3584 * Returns the data activation state of a given subId.
3585 */
3586 @Override
3587 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003589
fionaxu0152e512016-11-14 13:36:14 -08003590 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 if (phone != null) {
3594 return phone.getDataActivationState();
3595 } else {
3596 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3597 }
3598 } finally {
3599 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003600 }
3601 }
3602
3603 /**
Wink Saville36469e72014-06-11 15:17:00 -07003604 * Returns the unread count of voicemails for a subId
3605 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003606 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003607 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3608 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003610 mApp, subId, callingPackage, callingFeatureId,
3611 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003612 return 0;
3613 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003614 final long identity = Binder.clearCallingIdentity();
3615 try {
3616 final Phone phone = getPhone(subId);
3617 if (phone != null) {
3618 return phone.getVoiceMessageCount();
3619 } else {
3620 return 0;
3621 }
3622 } finally {
3623 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003624 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003625 }
3626
3627 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003628 * returns true, if the device is in a state where both voice and data
3629 * are supported simultaneously. This can change based on location or network condition.
3630 */
3631 @Override
3632 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 final Phone phone = getPhone(subId);
3636 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3637 } finally {
3638 Binder.restoreCallingIdentity(identity);
3639 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003640 }
3641
3642 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003643 * Send the dialer code if called from the current default dialer or the caller has
3644 * carrier privilege.
3645 * @param inputCode The dialer code to send
3646 */
3647 @Override
3648 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003649 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003650 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003651 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3652 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003653 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003654 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003655 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003656 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003657
3658 final long identity = Binder.clearCallingIdentity();
3659 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003660 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003661 } finally {
3662 Binder.restoreCallingIdentity(identity);
3663 }
fionaxu235cc5e2017-03-06 22:25:57 -08003664 }
3665
Pengquan Menga1bb6272018-09-06 09:59:22 -07003666 @Override
3667 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003668 TelephonyPermissions
3669 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3670 mApp, subId, "getNetworkSelectionMode");
3671 final long identity = Binder.clearCallingIdentity();
3672 try {
3673 if (!isActiveSubscription(subId)) {
3674 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3675 }
3676 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3677 } finally {
3678 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003679 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003680 }
3681
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003683 public boolean isInEmergencySmsMode() {
3684 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 for (Phone phone : PhoneFactory.getPhones()) {
3688 if (phone.isInEmergencySmsMode()) {
3689 return true;
3690 }
3691 }
3692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 return false;
3696 }
3697
shilu366312e2019-12-17 09:28:10 -08003698 /**
3699 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3700 * @param subId The subscription to use to check the configuration.
3701 * @param c The callback that will be used to send the result.
3702 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003703 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003704 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3705 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003706 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3707 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003708
Brad Ebinger77b832e2019-10-17 17:03:22 -07003709 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3710 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3711 "IMS not available on device.");
3712 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 final long token = Binder.clearCallingIdentity();
3714 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003715 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003716 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003718 } catch (ImsException e) {
3719 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 } finally {
3721 Binder.restoreCallingIdentity(token);
3722 }
3723 }
3724
shilu366312e2019-12-17 09:28:10 -08003725 /**
3726 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3727 * @param subId The subscription to use to check the configuration.
3728 * @param c The callback that will be used to send the result.
3729 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003730 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003731 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003732 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3733 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003734 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3735 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3736 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003737 final long token = Binder.clearCallingIdentity();
3738 try {
3739 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3740 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3741 .removeRegistrationCallbackForSubscription(c, subId);
3742 } catch (ImsException e) {
3743 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3744 + "is inactive, ignoring unregister.");
3745 // If the subscription is no longer active, just return, since the callback
3746 // will already have been removed internally.
3747 } finally {
3748 Binder.restoreCallingIdentity(token);
3749 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003750 }
3751
Brad Ebinger774ba362019-10-22 17:36:18 -07003752 /**
3753 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3754 */
3755 @Override
3756 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3757 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3758 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3759 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3760 "IMS not available on device.");
3761 }
3762 final long token = Binder.clearCallingIdentity();
3763 try {
3764 Phone phone = getPhone(subId);
3765 if (phone == null) {
3766 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3767 + subId + "'");
3768 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3769 }
3770 phone.getImsRegistrationState(regState -> {
3771 try {
3772 consumer.accept((regState == null)
3773 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3774 } catch (RemoteException e) {
3775 // Ignore if the remote process is no longer available to call back.
3776 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3777 }
3778 });
3779 } finally {
3780 Binder.restoreCallingIdentity(token);
3781 }
3782 }
3783
3784 /**
3785 * Get the transport type for the IMS service registration state.
3786 */
3787 @Override
3788 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003789 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3790 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003791 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3792 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3793 "IMS not available on device.");
3794 }
3795 final long token = Binder.clearCallingIdentity();
3796 try {
3797 Phone phone = getPhone(subId);
3798 if (phone == null) {
3799 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3800 + subId + "'");
3801 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3802 }
3803 phone.getImsRegistrationTech(regTech -> {
3804 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3805 int regTechConverted = (regTech == null)
3806 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3807 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3808 regTechConverted);
3809 try {
3810 consumer.accept(regTechConverted);
3811 } catch (RemoteException e) {
3812 // Ignore if the remote process is no longer available to call back.
3813 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3814 }
3815 });
3816 } finally {
3817 Binder.restoreCallingIdentity(token);
3818 }
3819 }
3820
shilu366312e2019-12-17 09:28:10 -08003821 /**
3822 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3823 * @param subId The subscription to use to check the configuration.
3824 * @param c The callback that will be used to send the result.
3825 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003826 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003827 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3828 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003829 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3830 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003831 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3832 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3833 "IMS not available on device.");
3834 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3836 final long token = Binder.clearCallingIdentity();
3837 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003838 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003839 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003840 } catch (ImsException e) {
3841 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 } finally {
3843 Binder.restoreCallingIdentity(token);
3844 }
3845 }
3846
shilu366312e2019-12-17 09:28:10 -08003847 /**
3848 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3849 * @param subId The subscription to use to check the configuration.
3850 * @param c The callback that will be used to send the result.
3851 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003854 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3855 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003856 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3857 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3858 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003859
3860 final long token = Binder.clearCallingIdentity();
3861 try {
3862 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3863 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003864 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003865 } catch (ImsException e) {
3866 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3867 + "is inactive, ignoring unregister.");
3868 // If the subscription is no longer active, just return, since the callback
3869 // will already have been removed internally.
3870 } finally {
3871 Binder.restoreCallingIdentity(token);
3872 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003873 }
3874
3875 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003876 public boolean isCapable(int subId, int capability, int regTech) {
3877 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003878 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3879 final long token = Binder.clearCallingIdentity();
3880 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003881 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003882 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003883 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3885 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003886 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003887 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3888 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 } finally {
3890 Binder.restoreCallingIdentity(token);
3891 }
3892 }
3893
3894 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003895 public boolean isAvailable(int subId, int capability, int regTech) {
3896 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003897 final long token = Binder.clearCallingIdentity();
3898 try {
3899 Phone phone = getPhone(subId);
3900 if (phone == null) return false;
3901 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003902 } catch (com.android.ims.ImsException e) {
3903 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3904 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003905 } finally {
3906 Binder.restoreCallingIdentity(token);
3907 }
3908 }
3909
Brad Ebinger77b832e2019-10-17 17:03:22 -07003910 /**
3911 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3912 * subscription.
3913 * @param subId The subscription to use to check the configuration.
3914 * @param callback The callback that will be used to send the result.
3915 * @param capability The MmTelFeature capability that will be used to send the result.
3916 * @param transportType The transport type of the MmTelFeature capability.
3917 */
3918 @Override
3919 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3920 int transportType) {
3921 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3922 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3923 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3924 "IMS not available on device.");
3925 }
3926 final long token = Binder.clearCallingIdentity();
3927 try {
3928 int slotId = getSlotIndex(subId);
3929 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3930 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3931 + subId + "'");
3932 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3933 }
3934 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3935 transportType, aBoolean -> {
3936 try {
3937 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3938 } catch (RemoteException e) {
3939 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3940 + "running. Ignore");
3941 }
3942 });
3943 } finally {
3944 Binder.restoreCallingIdentity(token);
3945 }
3946 }
3947
shilu366312e2019-12-17 09:28:10 -08003948 /**
3949 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3950 * @param subId The subscription to use to check the configuration.
3951 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003952 @Override
3953 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003954 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3955 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003956
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3958 final long token = Binder.clearCallingIdentity();
3959 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003960 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003961 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003962 } catch (ImsException e) {
3963 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 } finally {
3965 Binder.restoreCallingIdentity(token);
3966 }
3967 }
3968
3969 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003970 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003971 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003972 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003976 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003978 } catch (ImsException e) {
3979 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003980 } finally {
3981 Binder.restoreCallingIdentity(identity);
3982 }
3983 }
3984
shilu366312e2019-12-17 09:28:10 -08003985 /**
3986 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3987 * @param subId The subscription to use to check the configuration.
3988 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003990 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003991 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3992 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003993 final long identity = Binder.clearCallingIdentity();
3994 try {
3995 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003996 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3997 } catch (ImsException e) {
3998 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 } finally {
4000 Binder.restoreCallingIdentity(identity);
4001 }
4002 }
4003
4004 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004005 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004006 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004007 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 final long identity = Binder.clearCallingIdentity();
4009 try {
4010 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004011 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004012 } catch (ImsException e) {
4013 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 } finally {
4015 Binder.restoreCallingIdentity(identity);
4016 }
4017 }
4018
shilu366312e2019-12-17 09:28:10 -08004019 /**
4020 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4021 * @param subId The subscription to use to check the configuration.
4022 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 @Override
4024 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004025 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4026 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 final long identity = Binder.clearCallingIdentity();
4028 try {
4029 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004030 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004031 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004032 } catch (ImsException e) {
4033 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 } finally {
4035 Binder.restoreCallingIdentity(identity);
4036 }
4037 }
4038
4039 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004040 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004042 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 final long identity = Binder.clearCallingIdentity();
4044 try {
4045 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004046 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004047 } catch (ImsException e) {
4048 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 } finally {
4050 Binder.restoreCallingIdentity(identity);
4051 }
4052 }
4053
shilu366312e2019-12-17 09:28:10 -08004054 /**
4055 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4056 * @param subId The subscription to use to check the configuration.
4057 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 @Override
4059 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004060 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4061 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004062 final long identity = Binder.clearCallingIdentity();
4063 try {
4064 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004065 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004066 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004067 } catch (ImsException e) {
4068 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004069 } finally {
4070 Binder.restoreCallingIdentity(identity);
4071 }
4072 }
4073
4074 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004075 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004077 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 final long identity = Binder.clearCallingIdentity();
4079 try {
4080 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004081 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004083 } catch (ImsException e) {
4084 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004085 } finally {
4086 Binder.restoreCallingIdentity(identity);
4087 }
4088 }
4089
4090 @Override
4091 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4092 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4093 "setVoWiFiNonPersistent");
4094 final long identity = Binder.clearCallingIdentity();
4095 try {
4096 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004097 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004098 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004099 } catch (ImsException e) {
4100 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
shilu366312e2019-12-17 09:28:10 -08004106 /**
4107 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4108 * @param subId The subscription to use to check the configuration.
4109 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 @Override
4111 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004112 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4113 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004114 final long identity = Binder.clearCallingIdentity();
4115 try {
4116 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004117 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004118 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004119 } catch (ImsException e) {
4120 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004121 } finally {
4122 Binder.restoreCallingIdentity(identity);
4123 }
4124 }
4125
4126 @Override
4127 public void setVoWiFiModeSetting(int subId, int mode) {
4128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4129 "setVoWiFiModeSetting");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004133 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004134 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004135 } catch (ImsException e) {
4136 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004137 } finally {
4138 Binder.restoreCallingIdentity(identity);
4139 }
4140 }
4141
4142 @Override
4143 public int getVoWiFiRoamingModeSetting(int subId) {
4144 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4145 final long identity = Binder.clearCallingIdentity();
4146 try {
4147 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004148 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004149 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004150 } catch (ImsException e) {
4151 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004152 } finally {
4153 Binder.restoreCallingIdentity(identity);
4154 }
4155 }
4156
4157 @Override
4158 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4160 "setVoWiFiRoamingModeSetting");
4161 final long identity = Binder.clearCallingIdentity();
4162 try {
4163 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004164 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004165 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004166 } catch (ImsException e) {
4167 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004168 } finally {
4169 Binder.restoreCallingIdentity(identity);
4170 }
4171 }
4172
4173 @Override
4174 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4175 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4176 "setRttCapabilityEnabled");
4177 final long identity = Binder.clearCallingIdentity();
4178 try {
4179 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004180 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4181 } catch (ImsException e) {
4182 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
shilu366312e2019-12-17 09:28:10 -08004188 /**
4189 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4190 * @param subId The subscription to use to check the configuration.
4191 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004192 @Override
4193 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004194 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4195 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004196 final long identity = Binder.clearCallingIdentity();
4197 try {
4198 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004199 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004200 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004201 } catch (ImsException e) {
4202 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004203 } finally {
4204 Binder.restoreCallingIdentity(identity);
4205 }
4206 }
4207
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004208 @Override
4209 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4210 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4211 final long identity = Binder.clearCallingIdentity();
4212 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004213 if (!isImsAvailableOnDevice()) {
4214 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4215 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004216 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004217 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004218 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004219 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 } catch (ImsException e) {
4221 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004222 } finally {
4223 Binder.restoreCallingIdentity(identity);
4224 }
4225 }
4226
4227 @Override
4228 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4229 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4230 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004231 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4232 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4233 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004234 try {
4235 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004236 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004237 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004239 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4240 + "is inactive, ignoring unregister.");
4241 // If the subscription is no longer active, just return, since the callback will already
4242 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004243 } finally {
4244 Binder.restoreCallingIdentity(identity);
4245 }
4246 }
4247
allenwtsu99c623b2020-01-03 18:24:23 +08004248
4249 private void checkModifyPhoneStatePermission(int subId, String message) {
4250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4251 message);
4252 }
4253
4254 private boolean isImsProvisioningRequired(int subId, int capability,
4255 boolean isMmtelCapability) {
4256 Phone phone = getPhone(subId);
4257 if (phone == null) {
4258 loge("phone instance null for subid " + subId);
4259 return false;
4260 }
4261 if (isMmtelCapability) {
4262 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4263 return false;
4264 }
4265 } else {
4266 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4267 return false;
4268 }
4269 }
4270 return true;
4271 }
4272
4273 @Override
4274 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4275 boolean isProvisioned) {
4276 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4277
4278 final long identity = Binder.clearCallingIdentity();
4279 try {
4280 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4281 if (!isImsProvisioningRequired(subId, capability, false)) {
4282 return;
4283 }
4284
4285 // this capability requires provisioning, route to the correct API.
4286 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4287 switch (capability) {
4288 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4289 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4290 ims.setEabProvisioned(isProvisioned);
4291 break;
4292 default: {
4293 throw new IllegalArgumentException("Tried to set provisioning for "
4294 + "rcs capability '" + capability + "', which does not require "
4295 + "provisioning.");
4296 }
4297 }
4298 } finally {
4299 Binder.restoreCallingIdentity(identity);
4300 }
4301
4302 }
4303
4304
4305 @Override
4306 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4307 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4308 final long identity = Binder.clearCallingIdentity();
4309 try {
4310 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4311 if (!isImsProvisioningRequired(subId, capability, false)) {
4312 return true;
4313 }
4314
4315 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4316 switch (capability) {
4317 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4318 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4319 return ims.isEabProvisionedOnDevice();
4320
4321 default: {
4322 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4323 + "capability '" + capability + "', which does not require "
4324 + "provisioning.");
4325 }
4326 }
4327
4328 } finally {
4329 Binder.restoreCallingIdentity(identity);
4330 }
4331 }
4332
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004333 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4335 boolean isProvisioned) {
4336 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4337 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4338 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4339 }
allenwtsu99c623b2020-01-03 18:24:23 +08004340 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004341 final long identity = Binder.clearCallingIdentity();
4342 try {
4343 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004344 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004345 return;
4346 }
4347
4348 // this capability requires provisioning, route to the correct API.
4349 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4350 switch (capability) {
4351 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4352 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4353 ims.setVolteProvisioned(isProvisioned);
4354 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4355 ims.setWfcProvisioned(isProvisioned);
4356 }
4357 break;
4358 }
4359 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4360 // There is currently no difference in VT provisioning type.
4361 ims.setVtProvisioned(isProvisioned);
4362 break;
4363 }
4364 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4365 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4366 // change the capability of the feature instead if needed.
4367 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4368 == isProvisioned) {
4369 // No change in provisioning.
4370 return;
4371 }
4372 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4373 try {
4374 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004375 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004376 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4377 + ", Exception" + e.getMessage());
4378 }
4379 break;
4380 }
4381 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004382 throw new IllegalArgumentException("Tried to set provisioning for "
4383 + "MmTel capability '" + capability + "', which does not require "
4384 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004385 }
4386 }
4387
4388 } finally {
4389 Binder.restoreCallingIdentity(identity);
4390 }
4391 }
4392
4393 @Override
4394 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4395 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4396 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4397 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4398 }
4399 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4400 final long identity = Binder.clearCallingIdentity();
4401 try {
4402 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004403 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004404 return true;
4405 }
4406
4407 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4408 switch (capability) {
4409 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4410 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4411 return ims.isVolteProvisionedOnDevice();
4412 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4413 return ims.isWfcProvisionedOnDevice();
4414 }
4415 // This should never happen, since we are checking tech above to make sure it
4416 // is either LTE or IWLAN.
4417 throw new IllegalArgumentException("Invalid radio technology for voice "
4418 + "capability.");
4419 }
4420 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4421 // There is currently no difference in VT provisioning type.
4422 return ims.isVtProvisionedOnDevice();
4423 }
4424 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4425 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4426 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4427 }
4428 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004429 throw new IllegalArgumentException(
4430 "Tried to get provisioning for MmTel capability '" + capability
4431 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004432 }
4433 }
4434
4435 } finally {
4436 Binder.restoreCallingIdentity(identity);
4437 }
4438 }
4439
4440 @Override
4441 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4442 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4443 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4444 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4445 }
4446 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4447 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4448 return (provisionedBits & capability) > 0;
4449 }
4450
4451 @Override
4452 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4453 boolean isProvisioned) {
4454 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4455 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4456 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4457 }
4458 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4459 "setProvisioningStatusForCapability");
4460 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4461 // If the current provisioning status for capability already matches isProvisioned,
4462 // do nothing.
4463 if (((provisionedBits & capability) > 0) == isProvisioned) {
4464 return;
4465 }
4466 if (isProvisioned) {
4467 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4468 } else {
4469 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4470 }
4471 }
4472
4473 /**
4474 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4475 * technology. The bitfield should mirror the bitfield defined by
4476 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4477 */
4478 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4479 String key = getMmTelProvisioningKey(subId, tech);
4480 // Default is no capabilities are provisioned.
4481 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4482 }
4483
4484 /**
4485 * Sets the MmTel capability provisioning bitfield (defined by
4486 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4487 * technology specified.
4488 *
4489 * Note: This is a synchronous command and should not be called on UI thread.
4490 */
4491 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4492 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4493 String key = getMmTelProvisioningKey(subId, tech);
4494 editor.putInt(key, newField);
4495 editor.commit();
4496 }
4497
4498 private static String getMmTelProvisioningKey(int subId, int tech) {
4499 // resulting key is provision_ims_mmtel_{subId}_{tech}
4500 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4501 }
4502
4503 /**
4504 * Query CarrierConfig to see if the specified capability requires provisioning for the
4505 * carrier associated with the subscription id.
4506 */
4507 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4508 int capability) {
4509 CarrierConfigManager configManager = new CarrierConfigManager(context);
4510 PersistableBundle c = configManager.getConfigForSubId(subId);
4511 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004512 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004513 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4514 false);
4515 boolean requireVoiceVtProvisioning = c.getBoolean(
4516 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4517
4518 // First check to make sure that the capability requires provisioning.
4519 switch (capability) {
4520 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4521 // intentional fallthrough
4522 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4523 if (requireVoiceVtProvisioning) {
4524 // Voice and Video requires provisioning
4525 return true;
4526 }
4527 break;
4528 }
4529 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4530 if (requireUtProvisioning) {
4531 // UT requires provisioning
4532 return true;
4533 }
4534 break;
4535 }
4536 }
4537 return false;
4538 }
4539
allenwtsu99c623b2020-01-03 18:24:23 +08004540 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4541 int capability) {
4542 CarrierConfigManager configManager = new CarrierConfigManager(context);
4543 PersistableBundle c = configManager.getConfigForSubId(subId);
4544
4545 boolean requireRcsProvisioning = c.getBoolean(
4546 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4547
4548 // First check to make sure that the capability requires provisioning.
4549 switch (capability) {
4550 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4551 // intentional fallthrough
4552 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4553 if (requireRcsProvisioning) {
4554 // OPTION or PRESENCE requires provisioning
4555 return true;
4556 }
4557 break;
4558 }
4559 }
4560 return false;
4561 }
4562
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004563 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004564 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4566 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4567 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004568 enforceReadPrivilegedPermission("getImsProvisioningInt");
4569 final long identity = Binder.clearCallingIdentity();
4570 try {
4571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004572 int slotId = getSlotIndex(subId);
4573 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4574 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4575 + subId + "' for key:" + key);
4576 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4577 }
4578 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004579 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004580 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4581 + subId + "' for key:" + key);
4582 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004583 } finally {
4584 Binder.restoreCallingIdentity(identity);
4585 }
4586 }
4587
4588 @Override
4589 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004590 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4591 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4592 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004593 enforceReadPrivilegedPermission("getImsProvisioningString");
4594 final long identity = Binder.clearCallingIdentity();
4595 try {
4596 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004597 int slotId = getSlotIndex(subId);
4598 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4599 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4600 + subId + "' for key:" + key);
4601 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4602 }
4603 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004604 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004605 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4606 + subId + "' for key:" + key);
4607 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004608 } finally {
4609 Binder.restoreCallingIdentity(identity);
4610 }
4611 }
4612
4613 @Override
4614 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4616 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4617 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004618 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4619 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004623 int slotId = getSlotIndex(subId);
4624 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4625 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4626 + subId + "' for key:" + key);
4627 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4628 }
4629 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004630 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004631 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4632 + "' for key:" + key);
4633 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004634 } finally {
4635 Binder.restoreCallingIdentity(identity);
4636 }
4637 }
4638
4639 @Override
4640 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4642 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4643 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004644 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4645 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004646 final long identity = Binder.clearCallingIdentity();
4647 try {
4648 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004649 int slotId = getSlotIndex(subId);
4650 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4651 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4652 + subId + "' for key:" + key);
4653 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4654 }
4655 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004656 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004657 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4658 + "' for key:" + key);
4659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004660 } finally {
4661 Binder.restoreCallingIdentity(identity);
4662 }
4663 }
4664
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004665 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004666 int slotId = SubscriptionManager.getSlotIndex(subId);
4667 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004668 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4669 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004670 }
4671 return slotId;
4672 }
4673
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004674 private int getSlotIndex(int subId) {
4675 int slotId = SubscriptionManager.getSlotIndex(subId);
4676 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4677 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4678 }
4679 return slotId;
4680 }
4681
Wink Saville36469e72014-06-11 15:17:00 -07004682 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004683 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004684 */
4685 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004686 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4687 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004688 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004689 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004690 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004691 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004692 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004693 mApp, subId, callingPackage, callingFeatureId,
4694 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004695 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4696 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004697
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 final Phone phone = getPhone(subId);
4701 if (phone != null) {
4702 return phone.getServiceState().getDataNetworkType();
4703 } else {
4704 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4705 }
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004709 }
4710
4711 /**
4712 * Returns the data network type
4713 */
4714 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4716 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4717 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004718 }
4719
4720 /**
4721 * Returns the data network type for a subId
4722 */
4723 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004724 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4725 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004726 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004727 mApp, subId, callingPackage, callingFeatureId,
4728 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004729 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4730 }
4731
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004732 final long identity = Binder.clearCallingIdentity();
4733 try {
4734 final Phone phone = getPhone(subId);
4735 if (phone != null) {
4736 return phone.getServiceState().getDataNetworkType();
4737 } else {
4738 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4739 }
4740 } finally {
4741 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004742 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004743 }
4744
4745 /**
Wink Saville36469e72014-06-11 15:17:00 -07004746 * Returns the Voice network type for a subId
4747 */
4748 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004749 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4750 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004751 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 mApp, subId, callingPackage, callingFeatureId,
4753 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004754 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4755 }
4756
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004757 final long identity = Binder.clearCallingIdentity();
4758 try {
4759 final Phone phone = getPhone(subId);
4760 if (phone != null) {
4761 return phone.getServiceState().getVoiceNetworkType();
4762 } else {
4763 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4764 }
4765 } finally {
4766 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004767 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004768 }
4769
4770 /**
4771 * @return true if a ICC card is present
4772 */
4773 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004774 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004775 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4776 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004777 }
4778
4779 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004780 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004781 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004782 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004783 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004784 final long identity = Binder.clearCallingIdentity();
4785 try {
4786 final Phone phone = PhoneFactory.getPhone(slotIndex);
4787 if (phone != null) {
4788 return phone.getIccCard().hasIccCard();
4789 } else {
4790 return false;
4791 }
4792 } finally {
4793 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004795 }
4796
4797 /**
4798 * Return if the current radio is LTE on CDMA. This
4799 * is a tri-state return value as for a period of time
4800 * the mode may be unknown.
4801 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004802 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004803 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004804 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004805 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004807 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4808 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4809 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004810 }
4811
Sanket Padawe356d7632015-06-22 14:03:32 -07004812 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004813 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4814 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004815 try {
4816 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4817 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004818 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4819 }
4820
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 final Phone phone = getPhone(subId);
4824 if (phone == null) {
4825 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4826 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004827 return TelephonyProperties.lte_on_cdma_device()
4828 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829 }
4830 } finally {
4831 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004832 }
Wink Saville36469e72014-06-11 15:17:00 -07004833 }
4834
Wink Saville36469e72014-06-11 15:17:00 -07004835 /**
4836 * {@hide}
4837 * Returns Default subId, 0 in the case of single standby.
4838 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004839 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004840 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004841 }
4842
Shishir Agrawala9f32182016-04-12 12:00:16 -07004843 private int getSlotForDefaultSubscription() {
4844 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4845 }
4846
Wink Savilleb564aae2014-10-23 10:18:09 -07004847 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004848 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004849 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004850
Pengquan Menge92a50d2018-09-21 15:54:48 -07004851 private boolean isActiveSubscription(int subId) {
4852 return mSubscriptionController.isActiveSubId(subId);
4853 }
4854
Ihab Awadf2177b72013-11-25 13:33:23 -08004855 /**
4856 * @see android.telephony.TelephonyManager.WifiCallingChoices
4857 */
4858 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004859 final long identity = Binder.clearCallingIdentity();
4860 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004861 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004862 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4863 getWhenToMakeWifiCallsDefaultPreference());
4864 } finally {
4865 Binder.restoreCallingIdentity(identity);
4866 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004867 }
4868
4869 /**
4870 * @see android.telephony.TelephonyManager.WifiCallingChoices
4871 */
4872 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004873 final long identity = Binder.clearCallingIdentity();
4874 try {
4875 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004876 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004877 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4878 } finally {
4879 Binder.restoreCallingIdentity(identity);
4880 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004881 }
4882
Sailesh Nepald1e68152013-12-12 19:08:02 -08004883 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004884 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004885 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004886 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004887
Jordan Liu4c733742019-02-28 12:03:40 -08004888 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4889 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4890 if (phoneId == -1) {
4891 throw new IllegalArgumentException("Given slot index: " + slotIndex
4892 + " does not correspond to an active phone");
4893 }
4894 return PhoneFactory.getPhone(phoneId);
4895 }
4896
Shishir Agrawal566b7612013-10-28 14:41:00 -07004897 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004898 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4899 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4901 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004903 if (DBG) {
4904 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4905 }
4906 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4907 p2);
4908 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004909
Jordan Liu4c733742019-02-28 12:03:40 -08004910
4911 @Override
4912 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4913 int slotIndex, String callingPackage, String aid, int p2) {
4914 enforceModifyPermission();
4915 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4916 if (DBG) {
4917 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4918 }
4919 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4920 callingPackage, aid, p2);
4921 }
4922
4923 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4924 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004925 final long identity = Binder.clearCallingIdentity();
4926 try {
4927 if (TextUtils.equals(ISDR_AID, aid)) {
4928 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4930 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 if (bestComponent == null
4932 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4933 loge("The calling package is not allowed to access ISD-R.");
4934 throw new SecurityException(
4935 "The calling package is not allowed to access ISD-R.");
4936 }
Derek Tan740e1672017-06-27 14:56:27 -07004937 }
Derek Tan740e1672017-06-27 14:56:27 -07004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004940 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 return response;
4944 } finally {
4945 Binder.restoreCallingIdentity(identity);
4946 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004947 }
4948
4949 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004950 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004951 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4952 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004953 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4954 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4955 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004956
Jordan Liu4c733742019-02-28 12:03:40 -08004957 @Override
4958 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4959 enforceModifyPermission();
4960 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4961 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4962 channel);
4963 }
4964
4965 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004966 final long identity = Binder.clearCallingIdentity();
4967 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 if (channel < 0) {
4969 return false;
4970 }
Jordan Liu4c733742019-02-28 12:03:40 -08004971 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4972 null /* workSource */);
4973 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 return success;
4975 } finally {
4976 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004977 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978 }
4979
4980 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004981 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004982 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004983 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4984 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004985 if (DBG) {
4986 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4987 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4988 + p3 + " data=" + data);
4989 }
4990 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4991 command, p1, p2, p3, data);
4992 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004993
Jordan Liu4c733742019-02-28 12:03:40 -08004994 @Override
4995 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4996 int command, int p1, int p2, int p3, String data) {
4997 enforceModifyPermission();
4998 if (DBG) {
4999 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5000 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5001 + p3 + " data=" + data);
5002 }
5003 return iccTransmitApduLogicalChannelWithPermission(
5004 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5005 data);
5006 }
5007
5008 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5009 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 final long identity = Binder.clearCallingIdentity();
5011 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005012 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005013 return "";
5014 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005015
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005017 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5018 null /* workSource */);
5019 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005020
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005021 // Append the returned status code to the end of the response payload.
5022 String s = Integer.toHexString(
5023 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5024 if (response.payload != null) {
5025 s = IccUtils.bytesToHexString(response.payload) + s;
5026 }
5027 return s;
5028 } finally {
5029 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005030 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005031 }
Jake Hambye994d462014-02-03 13:10:13 -08005032
Evan Charltonc66da362014-05-16 14:06:40 -07005033 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005034 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5035 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005036 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5037 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005039 if (DBG) {
5040 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5041 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5042 }
5043 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5044 cla, command, p1, p2, p3, data);
5045 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005046
Jordan Liu4c733742019-02-28 12:03:40 -08005047 @Override
5048 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5049 int command, int p1, int p2, int p3, String data) {
5050 enforceModifyPermission();
5051 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5052 if (DBG) {
5053 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5054 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5055 + " data=" + data);
5056 }
5057
5058 return iccTransmitApduBasicChannelWithPermission(
5059 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5060 p2, p3, data);
5061 }
5062
5063 // open APDU basic channel assuming the caller has sufficient permissions
5064 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5065 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 final long identity = Binder.clearCallingIdentity();
5067 try {
5068 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5069 && TextUtils.equals(ISDR_AID, data)) {
5070 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005071 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5072 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073 if (bestComponent == null
5074 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5075 loge("The calling package is not allowed to select ISD-R.");
5076 throw new SecurityException(
5077 "The calling package is not allowed to select ISD-R.");
5078 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005079 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005082 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5083 null /* workSource */);
5084 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005085
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005086 // Append the returned status code to the end of the response payload.
5087 String s = Integer.toHexString(
5088 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5089 if (response.payload != null) {
5090 s = IccUtils.bytesToHexString(response.payload) + s;
5091 }
5092 return s;
5093 } finally {
5094 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005095 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005096 }
5097
5098 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005099 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005100 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 if (DBG) {
5107 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5108 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5109 }
5110
5111 IccIoResult response =
5112 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5113 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5114 subId);
5115
5116 if (DBG) {
5117 log("Exchange SIM_IO [R]" + response);
5118 }
5119
5120 byte[] result = null;
5121 int length = 2;
5122 if (response.payload != null) {
5123 length = 2 + response.payload.length;
5124 result = new byte[length];
5125 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5126 } else {
5127 result = new byte[length];
5128 }
5129
5130 result[length - 1] = (byte) response.sw2;
5131 result[length - 2] = (byte) response.sw1;
5132 return result;
5133 } finally {
5134 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005135 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005136 }
5137
Nathan Haroldb3014052017-01-25 15:57:32 -08005138 /**
5139 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5140 * on a particular subscription
5141 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005142 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5143 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005145 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005146 return null;
5147 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005148
5149 final long identity = Binder.clearCallingIdentity();
5150 try {
5151 if (appType != TelephonyManager.APPTYPE_USIM
5152 && appType != TelephonyManager.APPTYPE_SIM) {
5153 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5154 return null;
5155 }
5156 Object response = sendRequest(
5157 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5158 if (response instanceof String[]) {
5159 return (String[]) response;
5160 }
yincheng zhaod698b842019-09-06 17:06:54 -07005161 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005162 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005163 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 } finally {
5165 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005166 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005167 }
5168
yincheng zhaod698b842019-09-06 17:06:54 -07005169 /**
5170 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5171 * subscription.
5172 *
5173 * @param subId the id of the subscription.
5174 * @param appType the uicc app type, must be USIM or SIM.
5175 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5176 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005177 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005178 * @return number of fplmns that is successfully written to the SIM.
5179 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005180 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5181 String callingFeatureId) {
5182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5183 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005184 if (DBG) logv("no permissions for setForbiddenplmns");
5185 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5186 }
5187 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5188 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5189 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5190 }
5191 if (fplmns == null) {
5192 throw new IllegalArgumentException("Fplmn List provided is null");
5193 }
5194 for (String fplmn : fplmns) {
5195 if (!CellIdentity.isValidPlmn(fplmn)) {
5196 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5197 }
5198 }
5199 final long identity = Binder.clearCallingIdentity();
5200 try {
5201 Object response = sendRequest(
5202 CMD_SET_FORBIDDEN_PLMNS,
5203 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5204 subId);
5205 return (int) response;
5206 } finally {
5207 Binder.restoreCallingIdentity(identity);
5208 }
5209 }
5210
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005211 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005212 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005213 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5214 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005215
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 final long identity = Binder.clearCallingIdentity();
5217 try {
5218 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5219 if (response.payload == null) {
5220 return "";
5221 }
Evan Charltonc66da362014-05-16 14:06:40 -07005222
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005223 // Append the returned status code to the end of the response payload.
5224 String s = Integer.toHexString(
5225 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5226 s = IccUtils.bytesToHexString(response.payload) + s;
5227 return s;
5228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Evan Charltonc66da362014-05-16 14:06:40 -07005231 }
5232
Jake Hambye994d462014-02-03 13:10:13 -08005233 /**
5234 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5235 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5236 *
5237 * @param itemID the ID of the item to read
5238 * @return the NV item as a String, or null on error.
5239 */
5240 @Override
5241 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005242 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005243 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5244 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005245
5246 final long identity = Binder.clearCallingIdentity();
5247 try {
5248 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005249 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005250 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5251 return value;
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Jake Hambye994d462014-02-03 13:10:13 -08005255 }
5256
5257 /**
5258 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5259 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5260 *
5261 * @param itemID the ID of the item to read
5262 * @param itemValue the value to write, as a String
5263 * @return true on success; false on any failure
5264 */
5265 @Override
5266 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005267 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005268 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5269 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005270
5271 final long identity = Binder.clearCallingIdentity();
5272 try {
5273 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5274 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005275 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5277 return success;
5278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
Jake Hambye994d462014-02-03 13:10:13 -08005281 }
5282
5283 /**
5284 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5285 * Used for device configuration by some CDMA operators.
5286 *
5287 * @param preferredRoamingList byte array containing the new PRL
5288 * @return true on success; false on any failure
5289 */
5290 @Override
5291 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005292 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5293 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005294
5295 final long identity = Binder.clearCallingIdentity();
5296 try {
5297 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5298 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5299 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5300 return success;
5301 } finally {
5302 Binder.restoreCallingIdentity(identity);
5303 }
Jake Hambye994d462014-02-03 13:10:13 -08005304 }
5305
5306 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005307 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005308 * Used for device configuration by some CDMA operators.
5309 *
chen xu6dac5ab2018-10-26 17:39:23 -07005310 * @param slotIndex - device slot.
5311 *
Jake Hambye994d462014-02-03 13:10:13 -08005312 * @return true on success; false on any failure
5313 */
5314 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005315 public boolean resetModemConfig(int slotIndex) {
5316 Phone phone = PhoneFactory.getPhone(slotIndex);
5317 if (phone != null) {
5318 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5319 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320
chen xu6dac5ab2018-10-26 17:39:23 -07005321 final long identity = Binder.clearCallingIdentity();
5322 try {
5323 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5324 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5325 return success;
5326 } finally {
5327 Binder.restoreCallingIdentity(identity);
5328 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 }
chen xu6dac5ab2018-10-26 17:39:23 -07005330 return false;
5331 }
5332
5333 /**
5334 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5335 *
5336 * @param slotIndex - device slot.
5337 *
5338 * @return true on success; false on any failure
5339 */
5340 @Override
5341 public boolean rebootModem(int slotIndex) {
5342 Phone phone = PhoneFactory.getPhone(slotIndex);
5343 if (phone != null) {
5344 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5345 mApp, phone.getSubId(), "rebootModem");
5346
5347 final long identity = Binder.clearCallingIdentity();
5348 try {
5349 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5350 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5351 return success;
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005357 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005358
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005359 public String[] getPcscfAddress(String apnType, String callingPackage,
5360 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005361 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005362 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5363 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005364 return new String[0];
5365 }
5366
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005367 final long identity = Binder.clearCallingIdentity();
5368 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005369 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005370 } finally {
5371 Binder.restoreCallingIdentity(identity);
5372 }
Wink Saville36469e72014-06-11 15:17:00 -07005373 }
5374
Brad Ebinger51f743a2017-01-23 13:50:20 -08005375 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005376 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5377 * {@link #disableIms(int)}.
5378 * @param slotIndex device slot.
5379 */
5380 public void resetIms(int slotIndex) {
5381 enforceModifyPermission();
5382
5383 final long identity = Binder.clearCallingIdentity();
5384 try {
5385 if (mImsResolver == null) {
5386 // may happen if the does not support IMS.
5387 return;
5388 }
5389 mImsResolver.disableIms(slotIndex);
5390 mImsResolver.enableIms(slotIndex);
5391 } finally {
5392 Binder.restoreCallingIdentity(identity);
5393 }
5394 }
5395
5396 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005397 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5398 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005399 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005400 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005401 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005402
5403 final long identity = Binder.clearCallingIdentity();
5404 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005405 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005406 // may happen if the device does not support IMS.
5407 return;
5408 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005409 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005410 } finally {
5411 Binder.restoreCallingIdentity(identity);
5412 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005413 }
5414
5415 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005416 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5417 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005418 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005419 public void disableIms(int slotId) {
5420 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421
5422 final long identity = Binder.clearCallingIdentity();
5423 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005424 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005425 // may happen if the device does not support IMS.
5426 return;
5427 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005428 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005432 }
5433
5434 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005435 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5436 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005437 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005438 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005439 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005440 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441
5442 final long identity = Binder.clearCallingIdentity();
5443 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005444 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005445 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5446 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005447 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005448 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005452 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005453 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005454 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5455 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005456 @Override
5457 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005458 enforceModifyPermission();
5459
5460 final long identity = Binder.clearCallingIdentity();
5461 try {
5462 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005463 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005464 } finally {
5465 Binder.restoreCallingIdentity(identity);
5466 }
5467 }
5468
5469 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005470 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005471 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005472 */
5473 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5474 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005475
5476 final long identity = Binder.clearCallingIdentity();
5477 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005478 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005479 // may happen if the device does not support IMS.
5480 return null;
5481 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005482 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005486 }
5487
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005488 /**
5489 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005490 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005491 */
5492 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5493 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494
5495 final long identity = Binder.clearCallingIdentity();
5496 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005497 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005498 // may happen if the device does not support IMS.
5499 return null;
5500 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005501 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005505 }
5506
Brad Ebinger884c07b2018-02-15 16:17:40 -08005507 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005508 * Sets the ImsService Package Name that Telephony will bind to.
5509 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005510 * @param slotIndex the slot ID that the ImsService should bind for.
5511 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005512 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005513 * @param featureTypes An integer array of feature types associated with a packageName.
5514 * @param packageName The name of the package that the current configuration will be replaced
5515 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005516 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005517 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005518 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5519 int[] featureTypes, String packageName) {
5520 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5521 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005522 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5523 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005524 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005525
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005526 final long identity = Binder.clearCallingIdentity();
5527 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005528 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005529 // may happen if the device does not support IMS.
5530 return false;
5531 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 Map<Integer, String> featureConfig = new HashMap<>();
5533 for (int featureType : featureTypes) {
5534 featureConfig.put(featureType, packageName);
5535 }
5536 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5537 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005538 } finally {
5539 Binder.restoreCallingIdentity(identity);
5540 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005541 }
5542
5543 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005544 * Clears any carrier ImsService overrides for the slot index specified that were previously
5545 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5546 *
5547 * This should only be used for testing.
5548 *
5549 * @param slotIndex the slot ID that the ImsService should bind for.
5550 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5551 */
5552 @Override
5553 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5554 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5555 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5556 "clearCarrierImsServiceOverride");
5557 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5558 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5559 "clearCarrierImsServiceOverride");
5560
5561 final long identity = Binder.clearCallingIdentity();
5562 try {
5563 if (mImsResolver == null) {
5564 // may happen if the device does not support IMS.
5565 return false;
5566 }
5567 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5568 } finally {
5569 Binder.restoreCallingIdentity(identity);
5570 }
5571 }
5572
5573 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005574 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005575 *
5576 * @param slotId The slot that the ImsService is associated with.
5577 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5578 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005579 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005580 * @return the package name of the ImsService configuration.
5581 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005582 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5583 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005584 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005585 TelephonyPermissions
5586 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5587 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5588 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005590 final long identity = Binder.clearCallingIdentity();
5591 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005592 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005593 // may happen if the device does not support IMS.
5594 return "";
5595 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005596 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005597 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5598 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005599 } finally {
5600 Binder.restoreCallingIdentity(identity);
5601 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005602 }
5603
Brad Ebinger77b832e2019-10-17 17:03:22 -07005604 /**
5605 * Get the MmTelFeature state associated with the requested subscription id.
5606 * @param subId The subscription that the MmTelFeature is associated with.
5607 * @param callback A callback with an integer containing the
5608 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5609 */
5610 @Override
5611 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5612 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5613 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5614 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5615 "IMS not available on device.");
5616 }
5617 final long token = Binder.clearCallingIdentity();
5618 try {
5619 int slotId = getSlotIndex(subId);
5620 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5621 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5622 + subId + "'");
5623 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5624 }
5625 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5626 try {
5627 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5628 } catch (RemoteException e) {
5629 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5630 + "Ignore");
5631 }
5632 });
5633 } finally {
5634 Binder.restoreCallingIdentity(token);
5635 }
5636 }
5637
Daniel Brightbb5840b2021-01-12 15:48:18 -08005638 /**
5639 * Sets the ims registration state on all valid {@link Phone}s.
5640 */
5641 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005642 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005643
5644 final long identity = Binder.clearCallingIdentity();
5645 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005646 // NOTE: Before S, this method only set the default phone.
5647 for (final Phone phone : PhoneFactory.getPhones()) {
5648 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5649 phone.setImsRegistrationState(registered);
5650 }
5651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005652 } finally {
5653 Binder.restoreCallingIdentity(identity);
5654 }
Wink Saville36469e72014-06-11 15:17:00 -07005655 }
5656
5657 /**
Stuart Scott54788802015-03-30 13:18:01 -07005658 * Set the network selection mode to automatic.
5659 *
5660 */
5661 @Override
5662 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005663 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5664 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005665
5666 final long identity = Binder.clearCallingIdentity();
5667 try {
shilufc958392020-01-20 11:36:01 -08005668 if (!isActiveSubscription(subId)) {
5669 return;
5670 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005672 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5673 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
Stuart Scott54788802015-03-30 13:18:01 -07005677 }
5678
Jack Yud10cdd42020-09-28 20:28:01 -07005679 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005680 * Ask the radio to connect to the input network and change selection mode to manual.
5681 *
5682 * @param subId the id of the subscription.
5683 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5684 * the operator to attach to.
5685 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5686 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5687 * normal network selection next time.
5688 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005689 */
5690 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005691 public boolean setNetworkSelectionModeManual(
5692 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005695
5696 if (!isActiveSubscription(subId)) {
5697 return false;
5698 }
5699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 final long identity = Binder.clearCallingIdentity();
5701 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005702 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005703 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005704 if (DBG) {
5705 log("setNetworkSelectionModeManual: subId: " + subId
5706 + " operator: " + operatorInfo);
5707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005712 }
shilu84f6e8b2019-12-19 13:58:01 -08005713 /**
5714 * Get the manual network selection
5715 *
5716 * @param subId the id of the subscription.
5717 *
5718 * @return the previously saved user selected PLMN
5719 */
5720 @Override
5721 public String getManualNetworkSelectionPlmn(int subId) {
5722 TelephonyPermissions
5723 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5724 mApp, subId, "getManualNetworkSelectionPlmn");
5725
5726 final long identity = Binder.clearCallingIdentity();
5727 try {
5728 if (!isActiveSubscription(subId)) {
5729 return "";
5730 }
5731
5732 final Phone phone = getPhone(subId);
5733 if (phone == null) {
5734 return "";
5735 }
5736 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5737 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5738 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5739 } finally {
5740 Binder.restoreCallingIdentity(identity);
5741 }
5742 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005743
5744 /**
5745 * Scans for available networks.
5746 */
5747 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005748 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5749 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5751 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005752 LocationAccessPolicy.LocationPermissionResult locationResult =
5753 LocationAccessPolicy.checkLocationPermission(mApp,
5754 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5755 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005756 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005757 .setCallingPid(Binder.getCallingPid())
5758 .setCallingUid(Binder.getCallingUid())
5759 .setMethod("getCellNetworkScanResults")
5760 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5761 .build());
5762 switch (locationResult) {
5763 case DENIED_HARD:
5764 throw new SecurityException("Not allowed to access scan results -- location");
5765 case DENIED_SOFT:
5766 return null;
5767 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005768
Pengquan Menga1bb6272018-09-06 09:59:22 -07005769 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770 try {
5771 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005772 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005773 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774 } finally {
5775 Binder.restoreCallingIdentity(identity);
5776 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005777 }
5778
5779 /**
sqian80370722020-01-29 15:02:51 -08005780 * Get the call forwarding info, given the call forwarding reason.
5781 */
5782 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005783 public void getCallForwarding(int subId, int callForwardingReason,
5784 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005785 enforceReadPrivilegedPermission("getCallForwarding");
5786 long identity = Binder.clearCallingIdentity();
5787 try {
5788 if (DBG) {
5789 log("getCallForwarding: subId " + subId
5790 + " callForwardingReason" + callForwardingReason);
5791 }
Hall Liua1acea22020-09-18 19:04:59 -07005792
5793 Phone phone = getPhone(subId);
5794 if (phone == null) {
5795 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005796 callback.onError(
5797 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005798 } catch (RemoteException e) {
5799 // ignore
5800 }
5801 return;
5802 }
5803
5804 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5805 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5806 @Override
5807 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5808 try {
5809 callback.onCallForwardingInfoAvailable(info);
5810 } catch (RemoteException e) {
5811 // ignore
5812 }
5813 }
5814
5815 @Override
5816 public void onError(int error) {
5817 try {
5818 callback.onError(error);
5819 } catch (RemoteException e) {
5820 // ignore
5821 }
5822 }
5823 });
5824 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005825 } finally {
5826 Binder.restoreCallingIdentity(identity);
5827 }
5828 }
5829
5830 /**
5831 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5832 * reason, the number to forward, and the timeout before the forwarding is attempted.
5833 */
5834 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005835 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5836 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005837 enforceModifyPermission();
5838 long identity = Binder.clearCallingIdentity();
5839 try {
5840 if (DBG) {
5841 log("setCallForwarding: subId " + subId
5842 + " callForwardingInfo" + callForwardingInfo);
5843 }
Hall Liua1acea22020-09-18 19:04:59 -07005844
5845 Phone phone = getPhone(subId);
5846 if (phone == null) {
5847 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005848 callback.accept(
5849 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005850 } catch (RemoteException e) {
5851 // ignore
5852 }
5853 return;
5854 }
5855
5856 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5857 FunctionalUtils.ignoreRemoteException(callback::accept));
5858
5859 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005860 } finally {
5861 Binder.restoreCallingIdentity(identity);
5862 }
5863 }
5864
5865 /**
Hall Liua1acea22020-09-18 19:04:59 -07005866 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005867 */
5868 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005869 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005870 enforceReadPrivilegedPermission("getCallForwarding");
5871 long identity = Binder.clearCallingIdentity();
5872 try {
Hall Liua1acea22020-09-18 19:04:59 -07005873
5874 Phone phone = getPhone(subId);
5875 if (phone == null) {
5876 try {
5877 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5878 } catch (RemoteException e) {
5879 // ignore
5880 }
5881 return;
5882 }
5883
5884 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5885
sqian80370722020-01-29 15:02:51 -08005886 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005887 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005888 } finally {
5889 Binder.restoreCallingIdentity(identity);
5890 }
5891 }
5892
5893 /**
Hall Liua1acea22020-09-18 19:04:59 -07005894 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005895 */
5896 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005897 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005898 enforceModifyPermission();
5899 long identity = Binder.clearCallingIdentity();
5900 try {
Hall Liua1acea22020-09-18 19:04:59 -07005901 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5902
5903 Phone phone = getPhone(subId);
5904 if (phone == null) {
5905 try {
5906 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5907 } catch (RemoteException e) {
5908 // ignore
5909 }
5910 return;
5911 }
5912
5913 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5914 FunctionalUtils.ignoreRemoteException(callback::accept));
5915
5916 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005917 } finally {
5918 Binder.restoreCallingIdentity(identity);
5919 }
5920 }
5921
5922 /**
yinxub1bed742017-04-17 11:45:04 -07005923 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005924 *
yinxub1bed742017-04-17 11:45:04 -07005925 * @param subId id of the subscription
5926 * @param request contains the radio access networks with bands/channels to scan
5927 * @param messenger callback messenger for scan results or errors
5928 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005929 * @return the id of the requested scan which can be used to stop the scan.
5930 */
5931 @Override
5932 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005933 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5935 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005936 LocationAccessPolicy.LocationPermissionResult locationResult =
5937 LocationAccessPolicy.checkLocationPermission(mApp,
5938 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5939 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005940 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005941 .setCallingPid(Binder.getCallingPid())
5942 .setCallingUid(Binder.getCallingUid())
5943 .setMethod("requestNetworkScan")
5944 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5945 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005946 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005947 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5948 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005949 if (e != null) {
5950 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5951 throw e;
5952 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005953 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005954 return TelephonyScanManager.INVALID_SCAN_ID;
5955 }
5956 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005957 }
Hall Liu912dfd32019-04-25 14:02:26 -07005958 int callingUid = Binder.getCallingUid();
5959 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005960 final long identity = Binder.clearCallingIdentity();
5961 try {
5962 return mNetworkScanRequestTracker.startNetworkScan(
5963 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005964 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005965 } finally {
5966 Binder.restoreCallingIdentity(identity);
5967 }
yinxu504e1392017-04-12 16:03:22 -07005968 }
5969
Hall Liub2ac8ef2019-02-28 15:56:23 -08005970 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005971 NetworkScanRequest request, int subId, String callingPackage) {
5972 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005973 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5974 boolean hasNetworkScanPermission =
5975 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5976 == PERMISSION_GRANTED;
5977
5978 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5979 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5980 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005981 }
5982
5983 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5984 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005985 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5986 return new SecurityException("Specific channels must not be"
5987 + " scanned without location access.");
5988 }
5989 }
5990 }
5991
Hall Liub2ac8ef2019-02-28 15:56:23 -08005992 return null;
5993 }
5994
yinxu504e1392017-04-12 16:03:22 -07005995 /**
5996 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005997 *
5998 * @param subId id of the subscription
5999 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006000 */
6001 @Override
6002 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6004 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005
Hall Liu912dfd32019-04-25 14:02:26 -07006006 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007 final long identity = Binder.clearCallingIdentity();
6008 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006009 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006010 } finally {
6011 Binder.restoreCallingIdentity(identity);
6012 }
yinxu504e1392017-04-12 16:03:22 -07006013 }
6014
6015 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006016 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006017 *
SongFerngWang9e060372020-12-21 16:41:52 +08006018 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006019 */
6020 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006021 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006022 TelephonyPermissions
6023 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006024 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006025
6026 final long identity = Binder.clearCallingIdentity();
6027 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006028 if (DBG) log("getAllowedNetworkTypesBitmask");
6029 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6030 int networkTypesBitmask = (result != null ? result[0] : -1);
6031 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6032 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 } finally {
6034 Binder.restoreCallingIdentity(identity);
6035 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006036 }
6037
6038 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006039 * Get the allowed network types for certain reason.
6040 *
6041 * @param subId the id of the subscription.
6042 * @param reason the reason the allowed network type change is taking place
6043 * @return the allowed network types.
6044 */
6045 @Override
6046 public long getAllowedNetworkTypesForReason(int subId,
6047 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6048 TelephonyPermissions
6049 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6050 mApp, subId, "getAllowedNetworkTypesForReason");
6051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6054 } finally {
6055 Binder.restoreCallingIdentity(identity);
6056 }
6057 }
6058
6059 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006060 * Enable/Disable E-UTRA-NR Dual Connectivity
6061 * @param subId subscription id of the sim card
6062 * @param nrDualConnectivityState expected NR dual connectivity state
6063 * This can be passed following states
6064 * <ol>
6065 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6066 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6067 * <li>Disable NR dual connectivity and force secondary cell to be released
6068 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6069 * </ol>
6070 * @return operation result.
6071 */
6072 @Override
6073 public int setNrDualConnectivityState(int subId,
6074 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6076 mApp, subId, "enableNRDualConnectivity");
6077 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6078 final long identity = Binder.clearCallingIdentity();
6079 try {
6080 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6081 nrDualConnectivityState, subId,
6082 workSource);
6083 if (DBG) log("enableNRDualConnectivity result: " + result);
6084 return result;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
6087 }
6088 }
6089
6090 /**
6091 * Is E-UTRA-NR Dual Connectivity enabled
6092 * @return true if dual connectivity is enabled else false
6093 */
6094 @Override
6095 public boolean isNrDualConnectivityEnabled(int subId) {
6096 TelephonyPermissions
6097 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6098 mApp, subId, "isNRDualConnectivityEnabled");
6099 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6100 final long identity = Binder.clearCallingIdentity();
6101 try {
6102 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6103 null, subId, workSource);
6104 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6105 return isEnabled;
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
6109 }
6110
6111 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006112 * get carrier bandwidth per primary and secondary carrier
6113 * @param subId subscription id of the sim card
6114 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6115 */
6116 @Override
6117 public CarrierBandwidth getCarrierBandwidth(int subId) {
6118 TelephonyPermissions
6119 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6120 mApp, subId, "isNRDualConnectivityEnabled");
6121 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6122 final long identity = Binder.clearCallingIdentity();
6123 try {
6124 CarrierBandwidth carrierBandwidth =
6125 getPhoneFromSubId(subId).getCarrierBandwidth();
6126 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6127 return carrierBandwidth;
6128 } finally {
6129 Binder.restoreCallingIdentity(identity);
6130 }
6131 }
6132
6133 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006134 * Set the allowed network types of the device and
6135 * provide the reason triggering the allowed network change.
6136 *
6137 * @param subId the id of the subscription.
6138 * @param reason the reason the allowed network type change is taking place
6139 * @param allowedNetworkTypes the allowed network types.
6140 * @return true on success; false on any failure.
6141 */
6142 @Override
6143 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006144 @TelephonyManager.AllowedNetworkTypesReason int reason,
6145 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006146 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6147 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006148 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6149 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6150 return false;
6151 }
6152
6153 if (DBG) {
6154 log("setAllowedNetworkTypesForReason: " + reason
6155 + " value: " + allowedNetworkTypes);
6156 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006157 final long identity = Binder.clearCallingIdentity();
6158 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006159 Boolean success = (Boolean) sendRequest(
6160 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6161 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6162
6163 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6164 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006165 } finally {
6166 Binder.restoreCallingIdentity(identity);
6167 }
6168 }
6169
6170 /**
Miaoa84611c2019-03-15 09:21:10 +08006171 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006172 *
Miaoa84611c2019-03-15 09:21:10 +08006173 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006174 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006175 * @hide
6176 */
6177 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006178 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006179 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006180 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006181 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 try {
Miaoa84611c2019-03-15 09:21:10 +08006183 if (phone != null) {
6184 return phone.hasMatchedTetherApnSetting();
6185 } else {
6186 return false;
6187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 } finally {
6189 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006190 }
Junda Liu475951f2014-11-07 16:45:03 -08006191 }
6192
6193 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006194 * Enable or disable always reporting signal strength changes from radio.
6195 *
6196 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6197 */
6198 @Override
6199 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6200 enforceModifyPermission();
6201 enforceSystemCaller();
6202
6203 final long identity = Binder.clearCallingIdentity();
6204 final Phone phone = getPhone(subId);
6205 try {
6206 if (phone != null) {
6207 if (DBG) {
6208 log("setAlwaysReportSignalStrength: subId=" + subId
6209 + " isEnable=" + isEnable);
6210 }
6211 phone.setAlwaysReportSignalStrength(isEnable);
6212 } else {
6213 loge("setAlwaysReportSignalStrength: no phone found for subId="
6214 + subId);
6215 }
6216 } finally {
6217 Binder.restoreCallingIdentity(identity);
6218 }
6219 }
6220
6221 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006222 * Get the user enabled state of Mobile Data.
6223 *
6224 * TODO: remove and use isUserDataEnabled.
6225 * This can't be removed now because some vendor codes
6226 * calls through ITelephony directly while they should
6227 * use TelephonyManager.
6228 *
6229 * @return true on enabled
6230 */
6231 @Override
6232 public boolean getDataEnabled(int subId) {
6233 return isUserDataEnabled(subId);
6234 }
6235
6236 /**
6237 * Get whether mobile data is enabled per user setting.
6238 *
6239 * There are other factors deciding whether mobile data is actually enabled, but they are
6240 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006241 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006242 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006243 *
6244 * @return {@code true} if data is enabled else {@code false}
6245 */
6246 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006247 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006248 try {
6249 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6250 null);
6251 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6253 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006254 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006255
6256 final long identity = Binder.clearCallingIdentity();
6257 try {
6258 int phoneId = mSubscriptionController.getPhoneId(subId);
6259 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6260 Phone phone = PhoneFactory.getPhone(phoneId);
6261 if (phone != null) {
6262 boolean retVal = phone.isUserDataEnabled();
6263 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6264 return retVal;
6265 } else {
6266 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6267 return false;
6268 }
6269 } finally {
6270 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006271 }
6272 }
6273
6274 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006275 * Checks if the device is capable of mobile data by considering whether whether the
6276 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6277 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006278 *
Shuo Qian985d1232020-01-08 14:30:06 -08006279 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006280 */
6281 @Override
6282 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006283 try {
6284 try {
6285 mApp.enforceCallingOrSelfPermission(
6286 android.Manifest.permission.ACCESS_NETWORK_STATE,
6287 null);
6288 } catch (Exception e) {
6289 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6290 "isDataEnabled");
6291 }
6292 } catch (Exception e) {
6293 enforceReadPrivilegedPermission("isDataEnabled");
6294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006295
6296 final long identity = Binder.clearCallingIdentity();
6297 try {
6298 int phoneId = mSubscriptionController.getPhoneId(subId);
6299 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6300 Phone phone = PhoneFactory.getPhone(phoneId);
6301 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006302 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6304 return retVal;
6305 } else {
6306 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6307 return false;
6308 }
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006311 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006312 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006313
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006314 /**
6315 * Check if data is enabled for a specific reason
6316 * @param subId Subscription index
6317 * @param reason the reason the data enable change is taking place
6318 * @return {@code true} if the overall data is enabled; {@code false} if not.
6319 */
6320 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006321 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006322 @TelephonyManager.DataEnabledReason int reason) {
6323 try {
6324 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6325 null);
6326 } catch (Exception e) {
6327 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006328 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006329 }
6330
6331
6332 final long identity = Binder.clearCallingIdentity();
6333 try {
6334 int phoneId = mSubscriptionController.getPhoneId(subId);
6335 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006336 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006337 + " reason=" + reason);
6338 }
6339 Phone phone = PhoneFactory.getPhone(phoneId);
6340 if (phone != null) {
6341 boolean retVal;
6342 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6343 retVal = phone.isUserDataEnabled();
6344 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006345 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006346 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006347 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006348 return retVal;
6349 } else {
6350 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006351 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006352 + subId + " retVal=false");
6353 }
6354 return false;
6355 }
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
6359 }
6360
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006361 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006362 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006363 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6364 // Skip the check if it's one of these special uids
6365 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6366 }
6367
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006368 //load access rules from carrier configs, and check those as well: b/139133814
6369 SubscriptionController subController = SubscriptionController.getInstance();
6370 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6371 || subController == null) return privilegeFromSim;
6372
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006373 PackageManager pkgMgr = phone.getContext().getPackageManager();
6374 String[] packages = pkgMgr.getPackagesForUid(uid);
6375
6376 final long identity = Binder.clearCallingIdentity();
6377 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006378 int subId = phone.getSubId();
6379 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6380 // A test override is in place for the privileges for this subId, so don't try to
6381 // read the subscription privileges.
6382 return privilegeFromSim;
6383 }
6384 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006385 SubscriptionManager subManager = (SubscriptionManager)
6386 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6387 for (String pkg : packages) {
6388 if (subManager.canManageSubscription(subInfo, pkg)) {
6389 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6390 }
6391 }
6392 return privilegeFromSim;
6393 } finally {
6394 Binder.restoreCallingIdentity(identity);
6395 }
6396 }
6397
6398 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6399 String pkgName) {
6400 //load access rules from carrier configs, and check those as well: b/139133814
6401 SubscriptionController subController = SubscriptionController.getInstance();
6402 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6403 || subController == null) return privilegeFromSim;
6404
6405 final long identity = Binder.clearCallingIdentity();
6406 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006407 int subId = phone.getSubId();
6408 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6409 // A test override is in place for the privileges for this subId, so don't try to
6410 // read the subscription privileges.
6411 return privilegeFromSim;
6412 }
6413 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006414 SubscriptionManager subManager = (SubscriptionManager)
6415 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6416 return subManager.canManageSubscription(subInfo, pkgName)
6417 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
6421 }
6422
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006423 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006424 public int getCarrierPrivilegeStatus(int subId) {
6425 final Phone phone = getPhone(subId);
6426 if (phone == null) {
6427 loge("getCarrierPrivilegeStatus: Invalid subId");
6428 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6429 }
6430 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006431 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006432 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006433 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6434 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006435
6436 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6437 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006438 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006439 }
Junda Liu29340342014-07-10 15:23:27 -07006440
6441 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006442 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006443 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006444 final Phone phone = getPhone(subId);
6445 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006446 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006447 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6448 }
6449 UiccProfile profile =
6450 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6451 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006452 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6454 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006455 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006456 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006457 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 }
6459
6460 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006461 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6462 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006463 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006464 }
6465
6466 int phoneId = SubscriptionManager.getPhoneId(subId);
6467 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006468 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006469 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006470 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6471 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006472 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6473 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6474 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006475 }
6476
6477 @Override
6478 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006479 if (TextUtils.isEmpty(pkgName))
6480 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006481 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6482 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6483 UiccCard card = UiccController.getInstance().getUiccCard(i);
6484 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006485 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006486 continue;
6487 }
6488
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006489 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6490 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6491 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006492 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6493 break;
6494 }
6495 }
6496
6497 return result;
Junda Liu29340342014-07-10 15:23:27 -07006498 }
Derek Tan89e89d42014-07-08 17:00:10 -07006499
6500 @Override
Junda Liue64de782015-04-16 17:19:16 -07006501 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6502 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6503 loge("phoneId " + phoneId + " is not valid.");
6504 return null;
6505 }
6506 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006507 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006508 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006509 return null ;
6510 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006511 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006512 }
6513
Amith Yamasani6e118872016-02-19 12:53:51 -08006514 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006515 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006516 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006517 List<String> privilegedPackages = new ArrayList<>();
6518 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006519 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6520 // has UICC in that slot.
6521 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006522 if (card.hasCarrierPrivilegeRules()) {
6523 if (packages == null) {
6524 // Only check packages in user 0 for now
6525 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006526 PackageManager.MATCH_DISABLED_COMPONENTS
6527 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006528 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006529 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006530 }
6531 for (int p = packages.size() - 1; p >= 0; p--) {
6532 PackageInfo pkgInfo = packages.get(p);
6533 if (pkgInfo != null && pkgInfo.packageName != null
6534 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006535 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006536 privilegedPackages.add(pkgInfo.packageName);
6537 }
6538 }
6539 }
6540 }
6541 return privilegedPackages;
6542 }
6543
chen xuf7e9fe82019-05-09 19:31:02 -07006544 @Override
6545 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006546 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6547
6548 final long identity = Binder.clearCallingIdentity();
6549
chen xuf7e9fe82019-05-09 19:31:02 -07006550 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006551 try {
6552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6553 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6554 }
6555 } finally {
6556 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006557 }
6558 return privilegedPackages;
6559 }
6560
Wink Savilleb564aae2014-10-23 10:18:09 -07006561 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006562 final Phone phone = getPhone(subId);
6563 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006564 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006565 return null;
6566 }
6567 String iccId = card.getIccId();
6568 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006569 return null;
6570 }
6571 return iccId;
6572 }
6573
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006574 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006575 public void setCallComposerStatus(int subId, int status) {
6576 enforceModifyPermission();
6577
6578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 Phone phone = getPhone(subId);
6581 if (phone != null) {
6582 Phone defaultPhone = phone.getImsPhone();
6583 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6584 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6585 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006586 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6587 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006588 }
6589 }
Shuo Qiand8782462020-12-22 19:10:14 -08006590 } catch (ImsException e) {
6591 throw new ServiceSpecificException(e.getCode());
6592 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006593 Binder.restoreCallingIdentity(identity);
6594 }
6595 }
6596
6597 @Override
6598 public int getCallComposerStatus(int subId) {
6599 enforceReadPrivilegedPermission("getCallComposerStatus");
6600
6601 final long identity = Binder.clearCallingIdentity();
6602 try {
6603 Phone phone = getPhone(subId);
6604 if (phone != null) {
6605 Phone defaultPhone = phone.getImsPhone();
6606 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6607 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6608 return imsPhone.getCallComposerStatus();
6609 }
6610 }
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
6613 }
6614 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6615 }
6616
6617 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006618 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6619 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006620 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006621 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006622
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006623 final long identity = Binder.clearCallingIdentity();
6624 try {
6625 final String iccId = getIccId(subId);
6626 final Phone phone = getPhone(subId);
6627 if (phone == null) {
6628 return false;
6629 }
6630 final String subscriberId = phone.getSubscriberId();
6631
6632 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006633 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 + subscriberId + " to " + number);
6635 }
6636
6637 if (TextUtils.isEmpty(iccId)) {
6638 return false;
6639 }
6640
6641 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6642
6643 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6644 if (alphaTag == null) {
6645 editor.remove(alphaTagPrefKey);
6646 } else {
6647 editor.putString(alphaTagPrefKey, alphaTag);
6648 }
6649
6650 // Record both the line number and IMSI for this ICCID, since we need to
6651 // track all merged IMSIs based on line number
6652 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6653 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6654 if (number == null) {
6655 editor.remove(numberPrefKey);
6656 editor.remove(subscriberPrefKey);
6657 } else {
6658 editor.putString(numberPrefKey, number);
6659 editor.putString(subscriberPrefKey, subscriberId);
6660 }
6661
6662 editor.commit();
6663 return true;
6664 } finally {
6665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006666 }
Derek Tan7226c842014-07-02 17:42:23 -07006667 }
6668
6669 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006670 public String getLine1NumberForDisplay(int subId, String callingPackage,
6671 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006672 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006673 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006674 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006675 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006676 return null;
6677 }
Derek Tan97ebb422014-09-05 16:55:38 -07006678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006679 final long identity = Binder.clearCallingIdentity();
6680 try {
6681 String iccId = getIccId(subId);
6682 if (iccId != null) {
6683 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6684 if (DBG_MERGE) {
6685 log("getLine1NumberForDisplay returning "
6686 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6687 }
6688 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006689 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6691 return null;
6692 } finally {
6693 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006694 }
Derek Tan7226c842014-07-02 17:42:23 -07006695 }
6696
6697 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006698 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6699 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006700 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006701 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006702 return null;
6703 }
Derek Tan97ebb422014-09-05 16:55:38 -07006704
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006705 final long identity = Binder.clearCallingIdentity();
6706 try {
6707 String iccId = getIccId(subId);
6708 if (iccId != null) {
6709 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6710 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6711 }
6712 return null;
6713 } finally {
6714 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006715 }
Derek Tan7226c842014-07-02 17:42:23 -07006716 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006717
6718 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006719 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6720 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006721 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6722 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006723 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006724 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006725 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006726 return null;
6727 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006728
Jordan Liub49b04b2019-05-06 14:45:15 -07006729 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6730 // the process, where TelephonyManager was instantiated.
6731 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006732 final long identity = Binder.clearCallingIdentity();
6733 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006734 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 final TelephonyManager tele = TelephonyManager.from(context);
6736 final SubscriptionManager sub = SubscriptionManager.from(context);
6737
6738 // Figure out what subscribers are currently active
6739 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006740
Jordan Liub49b04b2019-05-06 14:45:15 -07006741 // Only consider subs which match the current subId
6742 // This logic can be simplified. See b/131189269 for progress.
6743 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006744 activeSubscriberIds.add(tele.getSubscriberId(subId));
6745 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746
6747 // First pass, find a number override for an active subscriber
6748 String mergeNumber = null;
6749 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6750 for (String key : prefs.keySet()) {
6751 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6752 final String subscriberId = (String) prefs.get(key);
6753 if (activeSubscriberIds.contains(subscriberId)) {
6754 final String iccId = key.substring(
6755 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6756 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6757 mergeNumber = (String) prefs.get(numberKey);
6758 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006759 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 + " for active subscriber " + subscriberId);
6761 }
6762 if (!TextUtils.isEmpty(mergeNumber)) {
6763 break;
6764 }
6765 }
6766 }
6767 }
6768
6769 // Shortcut when no active merged subscribers
6770 if (TextUtils.isEmpty(mergeNumber)) {
6771 return null;
6772 }
6773
6774 // Second pass, find all subscribers under that line override
6775 final ArraySet<String> result = new ArraySet<>();
6776 for (String key : prefs.keySet()) {
6777 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6778 final String number = (String) prefs.get(key);
6779 if (mergeNumber.equals(number)) {
6780 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6781 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6782 final String subscriberId = (String) prefs.get(subscriberKey);
6783 if (!TextUtils.isEmpty(subscriberId)) {
6784 result.add(subscriberId);
6785 }
6786 }
6787 }
6788 }
6789
6790 final String[] resultArray = result.toArray(new String[result.size()]);
6791 Arrays.sort(resultArray);
6792 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006793 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006794 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6795 }
6796 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006797 } finally {
6798 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006799 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006800 }
6801
6802 @Override
zoey chen38003472019-12-13 17:16:31 +08006803 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6804 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006805
6806 final long identity = Binder.clearCallingIdentity();
6807 try {
6808 final TelephonyManager telephonyManager = mApp.getSystemService(
6809 TelephonyManager.class);
6810 String subscriberId = telephonyManager.getSubscriberId(subId);
6811 if (subscriberId == null) {
6812 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006813 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006814 + subId);
6815 }
6816 return null;
6817 }
6818
6819 final SubscriptionInfo info = SubscriptionController.getInstance()
6820 .getSubscriptionInfo(subId);
6821 final ParcelUuid groupUuid = info.getGroupUuid();
6822 // If it doesn't belong to any group, return just subscriberId of itself.
6823 if (groupUuid == null) {
6824 return new String[]{subscriberId};
6825 }
6826
6827 // Get all subscriberIds from the group.
6828 final List<String> mergedSubscriberIds = new ArrayList<>();
6829 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006830 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006831 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006832 for (SubscriptionInfo subInfo : groupInfos) {
6833 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6834 if (subscriberId != null) {
6835 mergedSubscriberIds.add(subscriberId);
6836 }
6837 }
6838
6839 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6840 } finally {
6841 Binder.restoreCallingIdentity(identity);
6842
6843 }
6844 }
6845
6846 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006847 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006848 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006849 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006850
6851 final long identity = Binder.clearCallingIdentity();
6852 try {
6853 final Phone phone = getPhone(subId);
6854 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006858 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006859
6860 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006861 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006862 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6863 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006864 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6865 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006866
6867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 final Phone phone = getPhone(subId);
6870 if (phone == null) {
6871 return false;
6872 }
6873 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6874 cdmaNonRoamingList);
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006877 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006878 }
6879
6880 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006881 @Deprecated
6882 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6883 enforceModifyPermission();
6884
6885 int returnValue = 0;
6886 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006887 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006888 if(result.exception == null) {
6889 if (result.result != null) {
6890 byte[] responseData = (byte[])(result.result);
6891 if(responseData.length > oemResp.length) {
6892 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6893 responseData.length + "bytes. Buffer Size is " +
6894 oemResp.length + "bytes.");
6895 }
6896 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6897 returnValue = responseData.length;
6898 }
6899 } else {
6900 CommandException ex = (CommandException) result.exception;
6901 returnValue = ex.getCommandError().ordinal();
6902 if(returnValue > 0) returnValue *= -1;
6903 }
6904 } catch (RuntimeException e) {
6905 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6906 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6907 if(returnValue > 0) returnValue *= -1;
6908 }
6909
6910 return returnValue;
6911 }
6912
6913 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006914 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006915 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006916 try {
6917 TelephonyPermissions
6918 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6919 mApp, phone.getSubId(), "getRadioAccessFamily");
6920 } catch (SecurityException e) {
6921 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6922 throw e;
6923 }
chen xub97461a2018-10-26 14:17:57 -07006924 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006925 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006926 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006927 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928 final long identity = Binder.clearCallingIdentity();
6929 try {
chen xub97461a2018-10-26 14:17:57 -07006930 TelephonyPermissions
6931 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6932 mApp, phone.getSubId(), "getRadioAccessFamily");
6933 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 } finally {
6935 Binder.restoreCallingIdentity(identity);
6936 }
chen xub97461a2018-10-26 14:17:57 -07006937 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006938 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006939
6940 @Override
6941 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006942 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006943 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006944
6945 final long identity = Binder.clearCallingIdentity();
6946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006947 ImsManager.getInstance(defaultPhone.getContext(),
6948 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006952 }
6953
6954 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006955 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006956 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006957 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6958 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006959 return false;
6960 }
Svet Ganovb320e182015-04-16 12:30:10 -07006961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006962 final long identity = Binder.clearCallingIdentity();
6963 try {
6964 // Check the user preference and the system-level IMS setting. Even if the user has
6965 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6966 // In the long run, we may instead need to check if there exists a connection service
6967 // which can support video calling.
6968 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006969 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 return imsManager.isVtEnabledByPlatform()
6971 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6972 && imsManager.isVtEnabledByUser();
6973 } finally {
6974 Binder.restoreCallingIdentity(identity);
6975 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006976 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006977
Andrew Leea1239f22015-03-02 17:44:07 -08006978 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006979 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6980 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006982 mApp, subId, callingPackage, callingFeatureId,
6983 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 return false;
6985 }
6986
6987 final long identity = Binder.clearCallingIdentity();
6988 try {
6989 CarrierConfigManager configManager =
6990 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006991 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6993 } finally {
6994 Binder.restoreCallingIdentity(identity);
6995 }
Andrew Leea1239f22015-03-02 17:44:07 -08006996 }
6997
6998 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006999 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007001 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 return false;
7003 }
7004
7005 final long identity = Binder.clearCallingIdentity();
7006 try {
7007 CarrierConfigManager configManager =
7008 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007009 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
7013 }
Andrew Leea1239f22015-03-02 17:44:07 -08007014 }
7015
Andrew Lee9431b832015-03-09 18:46:45 -07007016 @Override
7017 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007018 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007019 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007020 }
7021
7022 @Override
7023 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007024 final long identity = Binder.clearCallingIdentity();
7025 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007026 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027 } finally {
7028 Binder.restoreCallingIdentity(identity);
7029 }
Andrew Lee9431b832015-03-09 18:46:45 -07007030 }
7031
Hall Liuf6668912018-10-31 17:05:23 -07007032 /**
7033 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7034 * support for the feature and device firmware support.
7035 *
7036 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7037 */
7038 @Override
7039 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007040 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007041 final Phone phone = getPhone(subscriptionId);
7042 if (phone == null) {
7043 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7044 return false;
7045 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7049 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007050 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 return isCarrierSupported && isDeviceSupported;
7052 } finally {
7053 Binder.restoreCallingIdentity(identity);
7054 }
Hall Liu98187582018-01-22 19:15:32 -08007055 }
7056
Hall Liuf6668912018-10-31 17:05:23 -07007057 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007058 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7059 * RTT setting, will return true if the device and carrier both support RTT.
7060 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007061 */
7062 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 final long identity = Binder.clearCallingIdentity();
7064 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007065 boolean isRttSupported = isRttSupported(subscriptionId);
7066 boolean isUserRttSettingOn = Settings.Secure.getInt(
7067 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7068 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7069 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7070 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 } finally {
7072 Binder.restoreCallingIdentity(identity);
7073 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007074 }
7075
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007076 @Deprecated
7077 @Override
7078 public String getDeviceId(String callingPackage) {
7079 return getDeviceIdWithFeature(callingPackage, null);
7080 }
7081
Sanket Padawe7310cc72015-01-14 09:53:20 -08007082 /**
7083 * Returns the unique device ID of phone, for example, the IMEI for
7084 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7085 *
7086 * <p>Requires Permission:
7087 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7088 */
7089 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007090 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007091 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007092 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007093 return null;
7094 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007095 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007096 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007097 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007098 return null;
7099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007100
7101 final long identity = Binder.clearCallingIdentity();
7102 try {
7103 return phone.getDeviceId();
7104 } finally {
7105 Binder.restoreCallingIdentity(identity);
7106 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007107 }
7108
Ping Sunc67b7c22016-03-02 19:16:45 +08007109 /**
7110 * {@hide}
7111 * Returns the IMS Registration Status on a particular subid
7112 *
7113 * @param subId
7114 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007115 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007116 Phone phone = getPhone(subId);
7117 if (phone != null) {
7118 return phone.isImsRegistered();
7119 } else {
7120 return false;
7121 }
7122 }
7123
Santos Cordon7a1885b2015-02-03 11:15:19 -08007124 @Override
7125 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 final long identity = Binder.clearCallingIdentity();
7127 try {
7128 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7129 } finally {
7130 Binder.restoreCallingIdentity(identity);
7131 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007132 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007133
Tyler Gunnf70ed162019-04-03 15:28:53 -07007134 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007135 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007136 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007137 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007138 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007139 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7140 }
7141 final long identity = Binder.clearCallingIdentity();
7142 try {
7143 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7144 } finally {
7145 Binder.restoreCallingIdentity(identity);
7146 }
7147 }
7148
7149 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007150 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007151 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7152 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007153 final long identity = Binder.clearCallingIdentity();
7154 try {
7155 Phone phone = getPhone(subscriptionId);
7156 if (phone == null) {
7157 return null;
7158 }
7159 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7160 } finally {
7161 Binder.restoreCallingIdentity(identity);
7162 }
7163 }
7164
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007165 /**
7166 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007167 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007168 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007169 final long identity = Binder.clearCallingIdentity();
7170 try {
7171 Phone phone = getPhone(subId);
7172 if (phone != null) {
7173 return phone.isWifiCallingEnabled();
7174 } else {
7175 return false;
7176 }
7177 } finally {
7178 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007179 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007180 }
7181
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007182 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007183 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007184 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007186 final long identity = Binder.clearCallingIdentity();
7187 try {
7188 Phone phone = getPhone(subId);
7189 if (phone != null) {
7190 return phone.isVideoEnabled();
7191 } else {
7192 return false;
7193 }
7194 } finally {
7195 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007196 }
7197 }
7198
7199 /**
7200 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7201 * defined in {@link ImsRegistrationImplBase}.
7202 */
7203 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 final long identity = Binder.clearCallingIdentity();
7205 try {
7206 Phone phone = getPhone(subId);
7207 if (phone != null) {
7208 return phone.getImsRegistrationTech();
7209 } else {
7210 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7211 }
7212 } finally {
7213 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007214 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007215 }
7216
Stuart Scott8eef64f2015-04-08 15:13:54 -07007217 @Override
7218 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007219 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007220 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7221 return;
7222 }
7223
Svet Ganovcc087f82015-05-12 20:35:54 -07007224 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225
Svet Ganovcc087f82015-05-12 20:35:54 -07007226 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007227 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7228 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007229 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007230 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007231 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007232 setAllowedNetworkTypesForReason(subId,
7233 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7234 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7235 setAllowedNetworkTypesForReason(subId,
7236 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7237 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7238 setAllowedNetworkTypesForReason(subId,
7239 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7240 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007241 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7242 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007243 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007244 // There has been issues when Sms raw table somehow stores orphan
7245 // fragments. They lead to garbled message when new fragments come
7246 // in and combined with those stale ones. In case this happens again,
7247 // user can reset all network settings which will clean up this table.
7248 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007249 // Clean up IMS settings as well here.
7250 int slotId = getSlotIndex(subId);
7251 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7252 ImsManager.getInstance(mApp, slotId).factoryReset();
7253 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007254
7255 // Erase modem config if erase modem on network setting is enabled.
7256 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7257 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7258 if (configValue != null && Boolean.parseBoolean(configValue)) {
7259 sendEraseModemConfig(getDefaultPhone());
7260 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007261 } finally {
7262 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007263 }
7264 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007265
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007266 private void cleanUpSmsRawTable(Context context) {
7267 ContentResolver resolver = context.getContentResolver();
7268 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7269 resolver.delete(uri, null, null);
7270 }
7271
Narayan Kamath1c496c22015-04-16 14:40:19 +01007272 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007273 public String getSimLocaleForSubscriber(int subId) {
7274 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7275 final Phone phone = getPhone(subId);
7276 if (phone == null) {
7277 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007278 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007279 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 final long identity = Binder.clearCallingIdentity();
7281 try {
chen xu5d3637b2019-01-21 23:31:38 -08007282 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007283 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007284 if (info == null) {
7285 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7286 return null;
7287 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007288 // Try and fetch the locale from the carrier properties or from the SIM language
7289 // preferences (EF-PL and EF-LI)...
7290 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007292 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7293 if (localeFromDefaultSim != null) {
7294 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7295 if (DBG) log("Using locale from subId: " + subId + " locale: "
7296 + localeFromDefaultSim);
7297 return localeFromDefaultSim.toLanguageTag();
7298 } else {
7299 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007300 }
7301 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007303 // The SIM language preferences only store a language (e.g. fr = French), not an
7304 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7305 // the SIM and carrier preferences does not include a country we add the country
7306 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007307 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007308 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007309 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 return mccLocale.toLanguageTag();
7311 }
7312
7313 if (DBG) log("No locale found - returning null");
7314 return null;
7315 } finally {
7316 Binder.restoreCallingIdentity(identity);
7317 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007318 }
7319
7320 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007321 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007322 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007323 }
7324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 /**
7326 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7327 */
7328 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007329 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007330 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007331 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007332
Chenjie Yu1ba97252018-01-11 18:16:20 -08007333 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007334 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007335
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007336 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007337 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7338 * representing the state of the modem.
7339 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007340 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7341 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007342 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007343 */
7344 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007345 public void requestModemActivityInfo(ResultReceiver result) {
7346 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007347 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007348
7349 final long identity = Binder.clearCallingIdentity();
7350 try {
sqian1a1be542020-03-05 11:37:28 -08007351 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007352 } finally {
7353 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007354 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007355 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007356
Siddharth Rayb8114062018-06-17 15:02:38 -07007357 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7358 // less than total activity duration.
7359 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7360 if (info == null) {
7361 return false;
7362 }
7363 int activityDurationMs =
7364 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7365 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007366 int[] txTimeMs = info.getTransmitTimeMillis();
7367 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7368 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007369 }
7370 return (info.isValid()
7371 && (info.getSleepTimeMillis() <= activityDurationMs)
7372 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007373 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007374 && (totalTxTimeMs <= activityDurationMs));
7375 }
7376
Jack Yu85bd38a2015-11-09 11:34:32 -08007377 /**
7378 * {@hide}
7379 * Returns the service state information on specified subscription.
7380 */
7381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007382 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7383 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007384 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007385 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007386 return null;
7387 }
7388
Hall Liuf19c44f2018-11-27 14:38:17 -08007389 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7390 LocationAccessPolicy.checkLocationPermission(mApp,
7391 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7392 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007394 .setCallingPid(Binder.getCallingPid())
7395 .setCallingUid(Binder.getCallingUid())
7396 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007397 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007398 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7399 .build());
7400
7401 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7402 LocationAccessPolicy.checkLocationPermission(mApp,
7403 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7404 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007405 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007406 .setCallingPid(Binder.getCallingPid())
7407 .setCallingUid(Binder.getCallingUid())
7408 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007409 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007410 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7411 .build());
7412 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7413 boolean hasFinePermission =
7414 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7415 boolean hasCoarsePermission =
7416 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7417
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007418 final long identity = Binder.clearCallingIdentity();
7419 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007420 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7421 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7422 Rlog.d(LOG_TAG,
7423 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7424 return null;
7425 }
7426
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 final Phone phone = getPhone(subId);
7428 if (phone == null) {
7429 return null;
7430 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007431
Hall Liuf19c44f2018-11-27 14:38:17 -08007432 ServiceState ss = phone.getServiceState();
7433
7434 // Scrub out the location info in ServiceState depending on what level of access
7435 // the caller has.
7436 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007437 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7438 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007439 } finally {
7440 Binder.restoreCallingIdentity(identity);
7441 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007442 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007443
7444 /**
7445 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7446 *
7447 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7448 * voicemail ringtone.
7449 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7450 * PhoneAccount.
7451 */
7452 @Override
7453 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007454 final long identity = Binder.clearCallingIdentity();
7455 try {
7456 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7457 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007458 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007459 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007460
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7462 } finally {
7463 Binder.restoreCallingIdentity(identity);
7464 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007465 }
7466
7467 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007468 * Sets the per-account voicemail ringtone.
7469 *
7470 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7471 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7472 *
7473 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7474 * voicemail ringtone.
7475 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7476 * PhoneAccount.
7477 */
7478 @Override
7479 public void setVoicemailRingtoneUri(String callingPackage,
7480 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007481 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007482 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007483 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7484 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007485 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7486 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7487 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007489
7490 final long identity = Binder.clearCallingIdentity();
7491 try {
7492 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7493 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007494 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495 }
7496 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7497 } finally {
7498 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007499 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007500 }
7501
7502 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007503 * Returns whether vibration is set for voicemail notification in Phone settings.
7504 *
7505 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7506 * voicemail vibration setting.
7507 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7508 */
7509 @Override
7510 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007511 final long identity = Binder.clearCallingIdentity();
7512 try {
7513 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7514 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007515 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007516 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007517
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7519 } finally {
7520 Binder.restoreCallingIdentity(identity);
7521 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007522 }
7523
Youhan Wange64578a2016-05-02 15:32:42 -07007524 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007525 * Sets the per-account voicemail vibration.
7526 *
7527 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7528 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7529 *
7530 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7531 * voicemail vibration setting.
7532 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7533 * specific PhoneAccount.
7534 */
7535 @Override
7536 public void setVoicemailVibrationEnabled(String callingPackage,
7537 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007538 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007539 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007540 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7541 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7543 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7544 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007545 }
7546
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007547 final long identity = Binder.clearCallingIdentity();
7548 try {
7549 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7550 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007551 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552 }
7553 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7554 } finally {
7555 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007556 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007557 }
7558
7559 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007560 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7561 *
7562 * @throws SecurityException if the caller does not have the required permission
7563 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007564 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007565 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007566 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007567 }
7568
7569 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007570 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7571 * permission.
7572 *
7573 * @throws SecurityException if the caller does not have the required permission
7574 */
7575 private void enforceSendSmsPermission() {
7576 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7577 }
7578
7579 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007580 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007581 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007582 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007583 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007584 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 final long identity = Binder.clearCallingIdentity();
7586 try {
7587 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007588 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007589 if (componentName == null) {
7590 throw new SecurityException(
7591 "Caller not current active visual voicemail package[null]");
7592 }
7593 String vvmPackage = componentName.getPackageName();
7594 if (!callingPackage.equals(vvmPackage)) {
7595 throw new SecurityException("Caller not current active visual voicemail package["
7596 + vvmPackage + "]");
7597 }
7598 } finally {
7599 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007600 }
7601 }
7602
7603 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007604 * Return the application ID for the app type.
7605 *
7606 * @param subId the subscription ID that this request applies to.
7607 * @param appType the uicc app type.
7608 * @return Application ID for specificied app type, or null if no uicc.
7609 */
7610 @Override
7611 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007612 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007613 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007614
7615 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007616 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 if (phone == null) {
7618 return null;
7619 }
7620 String aid = null;
7621 try {
7622 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7623 .getApplicationByType(appType).getAid();
7624 } catch (Exception e) {
7625 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7626 }
7627 return aid;
7628 } finally {
7629 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007630 }
Youhan Wange64578a2016-05-02 15:32:42 -07007631 }
7632
Youhan Wang4001d252016-05-11 10:29:41 -07007633 /**
7634 * Return the Electronic Serial Number.
7635 *
7636 * @param subId the subscription ID that this request applies to.
7637 * @return ESN or null if error.
7638 */
7639 @Override
7640 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007641 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007642 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007643
7644 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007645 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007646 if (phone == null) {
7647 return null;
7648 }
7649 String esn = null;
7650 try {
7651 esn = phone.getEsn();
7652 } catch (Exception e) {
7653 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7654 }
7655 return esn;
7656 } finally {
7657 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007658 }
Youhan Wang4001d252016-05-11 10:29:41 -07007659 }
7660
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007661 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007662 * Return the Preferred Roaming List Version.
7663 *
7664 * @param subId the subscription ID that this request applies to.
7665 * @return PRLVersion or null if error.
7666 */
7667 @Override
7668 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007669 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007670 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007671
7672 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007673 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007674 if (phone == null) {
7675 return null;
7676 }
7677 String cdmaPrlVersion = null;
7678 try {
7679 cdmaPrlVersion = phone.getCdmaPrlVersion();
7680 } catch (Exception e) {
7681 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7682 }
7683 return cdmaPrlVersion;
7684 } finally {
7685 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007686 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007687 }
7688
7689 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007690 * Get snapshot of Telephony histograms
7691 * @return List of Telephony histograms
7692 * @hide
7693 */
7694 @Override
7695 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7697 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 return RIL.getTelephonyRILTimingHistograms();
7702 } finally {
7703 Binder.restoreCallingIdentity(identity);
7704 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007705 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007706
7707 /**
7708 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007709 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7710 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007711 * Require system privileges. In the future we may add this to carrier APIs.
7712 *
Michele Berionne482f8202018-11-27 18:57:59 -08007713 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007714 */
7715 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007716 @TelephonyManager.SetCarrierRestrictionResult
7717 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007718 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007719 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007720
Michele Berionne482f8202018-11-27 18:57:59 -08007721 if (carrierRestrictionRules == null) {
7722 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007723 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007725 final long identity = Binder.clearCallingIdentity();
7726 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007727 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007728 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007729 } finally {
7730 Binder.restoreCallingIdentity(identity);
7731 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007732 }
7733
7734 /**
7735 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007736 * Get the allowed carrier list and the excluded carrier list, including the priority between
7737 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 * Require system privileges. In the future we may add this to carrier APIs.
7739 *
Michele Berionne482f8202018-11-27 18:57:59 -08007740 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007741 */
7742 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007743 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007744 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007745 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007746
7747 final long identity = Binder.clearCallingIdentity();
7748 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007749 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7750 if (response instanceof CarrierRestrictionRules) {
7751 return (CarrierRestrictionRules) response;
7752 }
7753 // Response is an Exception of some kind,
7754 // which is signalled to the user as a NULL retval
7755 return null;
7756 } catch (Exception e) {
7757 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7758 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007759 } finally {
7760 Binder.restoreCallingIdentity(identity);
7761 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007762 }
7763
fionaxu59545b42016-05-25 15:53:37 -07007764 /**
fionaxu59545b42016-05-25 15:53:37 -07007765 * Action set from carrier signalling broadcast receivers to enable/disable radio
7766 * @param subId the subscription ID that this action applies to.
7767 * @param enabled control enable or disable radio.
7768 * {@hide}
7769 */
7770 @Override
7771 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7772 enforceModifyPermission();
7773 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007774
7775 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007776 if (phone == null) {
7777 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7778 return;
7779 }
7780 try {
7781 phone.carrierActionSetRadioEnabled(enabled);
7782 } catch (Exception e) {
7783 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007784 } finally {
7785 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007786 }
7787 }
7788
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007789 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007790 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7791 * network status based on which carrier apps could apply actions accordingly,
7792 * enable/disable default url handler for example.
7793 *
7794 * @param subId the subscription ID that this action applies to.
7795 * @param report control start/stop reporting the default network status.
7796 * {@hide}
7797 */
7798 @Override
7799 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7800 enforceModifyPermission();
7801 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007802
7803 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007804 if (phone == null) {
7805 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7806 return;
7807 }
7808 try {
7809 phone.carrierActionReportDefaultNetworkStatus(report);
7810 } catch (Exception e) {
7811 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007812 } finally {
7813 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007814 }
7815 }
7816
7817 /**
fionaxud9622282017-07-17 17:51:30 -07007818 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7819 * @param subId the subscription ID that this action applies to.
7820 * {@hide}
7821 */
7822 @Override
7823 public void carrierActionResetAll(int subId) {
7824 enforceModifyPermission();
7825 final Phone phone = getPhone(subId);
7826 if (phone == null) {
7827 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7828 return;
7829 }
7830 try {
7831 phone.carrierActionResetAll();
7832 } catch (Exception e) {
7833 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7834 }
7835 }
7836
7837 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007838 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7839 * bug report is being generated.
7840 */
7841 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007842 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007843 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7844 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007845 writer.println("Permission Denial: can't dump Phone from pid="
7846 + Binder.getCallingPid()
7847 + ", uid=" + Binder.getCallingUid()
7848 + "without permission "
7849 + android.Manifest.permission.DUMP);
7850 return;
7851 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007852 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007853 }
Jack Yueb89b242016-06-22 13:27:47 -07007854
Brad Ebingerdac2f002018-04-03 15:17:52 -07007855 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007856 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7857 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7858 @NonNull String[] args) {
7859 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7860 this, in.getFileDescriptor(), out.getFileDescriptor(),
7861 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007862 }
7863
Jack Yueb89b242016-06-22 13:27:47 -07007864 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007865 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007866 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007867 * @param reason the reason the data enable change is taking place
7868 * @param enabled True if enabling the data, otherwise disabling.
7869 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007870 */
7871 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007872 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007873 boolean enabled) {
7874 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7875 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7876 try {
7877 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007878 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007879 } catch (SecurityException se) {
7880 enforceModifyPermission();
7881 }
7882 } else {
7883 enforceModifyPermission();
7884 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007885
7886 final long identity = Binder.clearCallingIdentity();
7887 try {
7888 Phone phone = getPhone(subId);
7889 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007890 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7891 phone.carrierActionSetMeteredApnsEnabled(enabled);
7892 } else {
7893 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7894 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007895 }
7896 } finally {
7897 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007898 }
7899 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007900
7901 /**
7902 * Get Client request stats
7903 * @return List of Client Request Stats
7904 * @hide
7905 */
7906 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007907 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7908 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007909 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007910 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007911 return null;
7912 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007913 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007914
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 if (phone != null) {
7918 return phone.getClientRequestStats();
7919 }
7920
7921 return null;
7922 } finally {
7923 Binder.restoreCallingIdentity(identity);
7924 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007925 }
7926
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007927 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007928 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007929 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007930 }
Jack Yueb4124c2017-02-16 15:32:43 -08007931
7932 /**
Grace Chen70990072017-03-24 17:21:30 -07007933 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007934 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007935 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007936 * @param state State of SIM (power down, power up, pass through)
7937 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7938 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7939 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007940 *
7941 **/
7942 @Override
Grace Chen70990072017-03-24 17:21:30 -07007943 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007944 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007945 Phone phone = PhoneFactory.getPhone(slotIndex);
7946
vagdeviaf9a5b92018-08-15 16:01:53 -07007947 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7948
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007949 final long identity = Binder.clearCallingIdentity();
7950 try {
7951 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007952 phone.setSimPowerState(state, null, workSource);
7953 }
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
7957 }
7958
7959 /**
7960 * Set SIM card power state.
7961 *
7962 * @param slotIndex SIM slot id.
7963 * @param state State of SIM (power down, power up, pass through)
7964 * @param callback callback to trigger after success or failure
7965 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7966 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7967 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7968 *
7969 **/
7970 @Override
7971 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7972 IIntegerConsumer callback) {
7973 enforceModifyPermission();
7974 Phone phone = PhoneFactory.getPhone(slotIndex);
7975
7976 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7977
7978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 if (phone != null) {
7981 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7982 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007983 }
7984 } finally {
7985 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007986 }
7987 }
Shuo Qiandd210312017-04-12 22:11:33 +00007988
Tyler Gunn65d45c22017-06-05 11:22:26 -07007989 private boolean isUssdApiAllowed(int subId) {
7990 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007992 if (configManager == null) {
7993 return false;
7994 }
7995 PersistableBundle pb = configManager.getConfigForSubId(subId);
7996 if (pb == null) {
7997 return false;
7998 }
7999 return pb.getBoolean(
8000 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8001 }
8002
Shuo Qiandd210312017-04-12 22:11:33 +00008003 /**
8004 * Check if phone is in emergency callback mode
8005 * @return true if phone is in emergency callback mode
8006 * @param subId sub id
8007 */
goneil9c5f4872017-12-05 14:07:56 -08008008 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008009 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008010 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008011 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012
8013 final long identity = Binder.clearCallingIdentity();
8014 try {
8015 if (phone != null) {
8016 return phone.isInEcm();
8017 } else {
8018 return false;
8019 }
8020 } finally {
8021 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008022 }
8023 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008024
8025 /**
8026 * Get the current signal strength information for the given subscription.
8027 * Because this information is not updated when the device is in a low power state
8028 * it should not be relied-upon to be current.
8029 * @param subId Subscription index
8030 * @return the most recent cached signal strength info from the modem
8031 */
8032 @Override
8033 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 Phone p = getPhone(subId);
8037 if (p == null) {
8038 return null;
8039 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008040
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008041 return p.getSignalStrength();
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008045 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008046
Pengquan Meng77b7f132018-08-22 14:49:57 -07008047 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008048 * Get the current modem radio state for the given slot.
8049 * @param slotIndex slot index.
8050 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008051 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008052 * @return the current radio power state from the modem
8053 */
8054 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008055 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008056 Phone phone = PhoneFactory.getPhone(slotIndex);
8057 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008058 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8059 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008060 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8061 }
8062
8063 final long identity = Binder.clearCallingIdentity();
8064 try {
8065 return phone.getRadioPowerState();
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
8069 }
8070 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8071 }
8072
8073 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008074 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8075 *
8076 * <p>Requires one of the following permissions:
8077 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8078 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8079 * privileges.
8080 *
8081 * @param subId subscription id
8082 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8083 * {@code false}.
8084 */
8085 @Override
8086 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008087 try {
8088 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8089 null);
8090 } catch (Exception e) {
8091 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8092 mApp, subId, "isDataRoamingEnabled");
8093 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008094
Pengquan Menga1bb6272018-09-06 09:59:22 -07008095 boolean isEnabled = false;
8096 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008097 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008098 Phone phone = getPhone(subId);
8099 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 } finally {
8101 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008102 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008103 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008104 }
8105
8106
8107 /**
8108 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8109 *
8110 * <p> Requires permission:
8111 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8112 * privileges.
8113 *
8114 * @param subId subscription id
8115 * @param isEnabled {@code true} means enable, {@code false} means disable.
8116 */
8117 @Override
8118 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008119 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8120 mApp, subId, "setDataRoamingEnabled");
8121
Pengquan Menga1bb6272018-09-06 09:59:22 -07008122 final long identity = Binder.clearCallingIdentity();
8123 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008124 Phone phone = getPhone(subId);
8125 if (phone != null) {
8126 phone.setDataRoamingEnabled(isEnabled);
8127 }
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008130 }
8131 }
8132
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008133 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008134 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008135 TelephonyPermissions
8136 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008137 mApp, subId, "isManualNetworkSelectionAllowed");
8138
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008139 boolean isAllowed = true;
8140 final long identity = Binder.clearCallingIdentity();
8141 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008142 Phone phone = getPhone(subId);
8143 if (phone != null) {
8144 isAllowed = phone.isCspPlmnEnabled();
8145 }
8146 } finally {
8147 Binder.restoreCallingIdentity(identity);
8148 }
8149 return isAllowed;
8150 }
8151
8152 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008153 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008154 // Verify that tha callingPackage belongs to the calling UID
8155 mApp.getSystemService(AppOpsManager.class)
8156 .checkPackage(Binder.getCallingUid(), callingPackage);
8157
Jordan Liu1e142fc2019-04-22 15:10:43 -07008158 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008159 try {
8160 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008161 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008162 } catch (SecurityException e) {
8163 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8164 // has carrier privileges on an active UICC
8165 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8166 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008167 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008168 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008169 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008170
8171 final long identity = Binder.clearCallingIdentity();
8172 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008173 UiccController uiccController = UiccController.getInstance();
8174 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008175 if (hasReadPermission) {
8176 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008177 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008178
8179 // Remove private info if the caller doesn't have access
8180 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8181 for (UiccCardInfo cardInfo : cardInfos) {
8182 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8183 // is available
8184 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8185 if (card == null || card.getUiccProfile() == null) {
8186 // assume no access if the card or profile is unavailable
8187 filteredInfos.add(cardInfo.getUnprivileged());
8188 continue;
8189 }
8190 UiccProfile profile = card.getUiccProfile();
8191 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8192 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8193 filteredInfos.add(cardInfo);
8194 } else {
8195 filteredInfos.add(cardInfo.getUnprivileged());
8196 }
8197 }
8198 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008199 } finally {
8200 Binder.restoreCallingIdentity(identity);
8201 }
8202 }
8203
8204 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008205 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008206 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008207
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008208 final long identity = Binder.clearCallingIdentity();
8209 try {
8210 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8211 if (slots == null) {
8212 Rlog.i(LOG_TAG, "slots is null.");
8213 return null;
8214 }
8215
8216 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8217 for (int i = 0; i < slots.length; i++) {
8218 UiccSlot slot = slots[i];
8219 if (slot == null) {
8220 continue;
8221 }
8222
Jordan Liu7be7e652019-05-06 18:55:02 +00008223 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008224 UiccCard card = slot.getUiccCard();
8225 if (card != null) {
8226 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008227 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008228 cardId = slot.getEid();
8229 if (TextUtils.isEmpty(cardId)) {
8230 cardId = slot.getIccId();
8231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008232 }
8233
Jordan Liu857451f2019-05-09 16:35:35 -07008234 if (cardId != null) {
8235 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8236 // if cardId is an EID, it's all digits so this is fine
8237 cardId = IccUtils.stripTrailingFs(cardId);
8238 }
8239
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008240 int cardState = 0;
8241 switch (slot.getCardState()) {
8242 case CARDSTATE_ABSENT:
8243 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8244 break;
8245 case CARDSTATE_PRESENT:
8246 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8247 break;
8248 case CARDSTATE_ERROR:
8249 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8250 break;
8251 case CARDSTATE_RESTRICTED:
8252 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8253 break;
8254 default:
8255 break;
8256
8257 }
8258
8259 infos[i] = new UiccSlotInfo(
8260 slot.isActive(),
8261 slot.isEuicc(),
8262 cardId,
8263 cardState,
8264 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008265 slot.isExtendedApduSupported(),
8266 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008267 }
8268 return infos;
8269 } finally {
8270 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008271 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008272 }
8273
8274 @Override
8275 public boolean switchSlots(int[] physicalSlots) {
8276 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008277
8278 final long identity = Binder.clearCallingIdentity();
8279 try {
8280 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8281 } finally {
8282 Binder.restoreCallingIdentity(identity);
8283 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008284 }
Jack Yu4c988042018-02-27 15:30:01 -08008285
8286 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008287 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008288 final long identity = Binder.clearCallingIdentity();
8289 try {
8290 return UiccController.getInstance().getCardIdForDefaultEuicc();
8291 } finally {
8292 Binder.restoreCallingIdentity(identity);
8293 }
8294 }
8295
Pengquan Meng85728fb2018-03-12 16:31:21 -07008296 /**
goneil47ffb6e2018-04-06 15:40:58 -07008297 * A test API to reload the UICC profile.
8298 *
8299 * <p>Requires that the calling app has permission
8300 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8301 * @hide
8302 */
8303 @Override
8304 public void refreshUiccProfile(int subId) {
8305 enforceModifyPermission();
8306
8307 final long identity = Binder.clearCallingIdentity();
8308 try {
8309 Phone phone = getPhone(subId);
8310 if (phone == null) {
8311 return;
8312 }
8313 UiccCard uiccCard = phone.getUiccCard();
8314 if (uiccCard == null) {
8315 return;
8316 }
8317 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8318 if (uiccProfile == null) {
8319 return;
8320 }
8321 uiccProfile.refresh();
8322 } finally {
8323 Binder.restoreCallingIdentity(identity);
8324 }
8325 }
8326
8327 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008328 * Returns false if the mobile data is disabled by default, otherwise return true.
8329 */
8330 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008331 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008332 }
8333
8334 /**
8335 * Returns true if the data roaming is enabled by default, i.e the system property
8336 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8337 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8338 */
8339 private boolean getDefaultDataRoamingEnabled(int subId) {
8340 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008341 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008342 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008343 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8344 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8345 return isDataRoamingEnabled;
8346 }
8347
8348 /**
8349 * Returns the default network type for the given {@code subId}, if the default network type is
8350 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8351 */
8352 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008353 List<Integer> list = TelephonyProperties.default_network();
8354 int phoneId = mSubscriptionController.getPhoneId(subId);
8355 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8356 return list.get(phoneId);
8357 }
8358 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008359 }
fionaxua13278b2018-03-21 00:08:13 -07008360
8361 @Override
8362 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008363 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008364 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008365
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 final Phone phone = getPhone(subId);
8369 if (phone == null) {
8370 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8371 return;
8372 }
chen xueaba88a2019-03-15 13:15:10 -07008373 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8374 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008375 if (carrierPrivilegeRules == null) {
8376 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8377 } else {
8378 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8379 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008380 } finally {
8381 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008382 }
fionaxua13278b2018-03-21 00:08:13 -07008383 }
8384
8385 @Override
8386 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008387 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008388
8389 final long identity = Binder.clearCallingIdentity();
8390 try {
8391 final Phone phone = getPhone(subId);
8392 if (phone == null) {
8393 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8394 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8395 }
8396 return phone.getCarrierIdListVersion();
8397 } finally {
8398 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008399 }
fionaxua13278b2018-03-21 00:08:13 -07008400 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008401
8402 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008403 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8404 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008405 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008406 mApp, subId, callingPackage, callingFeatureId,
8407 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008408 return -1;
8409 }
8410
8411 final long identity = Binder.clearCallingIdentity();
8412 try {
8413 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8414 } finally {
8415 Binder.restoreCallingIdentity(identity);
8416 }
8417 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008418
8419 @Override
8420 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008421 TelephonyPermissions
8422 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008423 mApp, subId, "getCdmaRoamingMode");
8424
8425 final long identity = Binder.clearCallingIdentity();
8426 try {
8427 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
8432
8433 @Override
8434 public boolean setCdmaRoamingMode(int subId, int mode) {
8435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8436 mApp, subId, "setCdmaRoamingMode");
8437
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8441 } finally {
8442 Binder.restoreCallingIdentity(identity);
8443 }
8444 }
8445
8446 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008447 public int getCdmaSubscriptionMode(int subId) {
8448 TelephonyPermissions
8449 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8450 mApp, subId, "getCdmaSubscriptionMode");
8451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
8460 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008461 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8462 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8463 mApp, subId, "setCdmaSubscriptionMode");
8464
8465 final long identity = Binder.clearCallingIdentity();
8466 try {
8467 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8468 } finally {
8469 Binder.restoreCallingIdentity(identity);
8470 }
8471 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008472
sqianc5eccab2018-10-19 18:46:41 -07008473 @Override
sqian8c685422019-02-22 15:55:18 -08008474 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008475 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008476 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008477 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8478 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008479 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8480 }
8481 final long identity = Binder.clearCallingIdentity();
8482 try {
sqian854d44b2018-12-12 16:48:18 -08008483 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8484 for (Phone phone: PhoneFactory.getPhones()) {
8485 if (phone.getEmergencyNumberTracker() != null
8486 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8487 emergencyNumberListInternal.put(
8488 phone.getSubId(),
8489 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8490 }
sqian11b7a0e2018-12-05 18:48:28 -08008491 }
sqian854d44b2018-12-12 16:48:18 -08008492 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008493 } finally {
8494 Binder.restoreCallingIdentity(identity);
8495 }
sqianc5eccab2018-10-19 18:46:41 -07008496 }
8497
8498 @Override
sqian8c685422019-02-22 15:55:18 -08008499 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008500 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008501 if (!exactMatch) {
8502 TelephonyPermissions
8503 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008504 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008505 }
8506 final long identity = Binder.clearCallingIdentity();
8507 try {
sqian854d44b2018-12-12 16:48:18 -08008508 for (Phone phone: PhoneFactory.getPhones()) {
8509 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008510 && phone.getEmergencyNumberTracker()
8511 .isEmergencyNumber(number, exactMatch)) {
8512 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008513 }
sqian11b7a0e2018-12-05 18:48:28 -08008514 }
8515 return false;
8516 } finally {
8517 Binder.restoreCallingIdentity(identity);
8518 }
8519 }
8520
sqianf4ca7ed2019-01-15 18:32:07 -08008521 /**
8522 * Update emergency number list for test mode.
8523 */
8524 @Override
8525 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8526 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8527 "updateEmergencyNumberListTestMode");
8528
8529 final long identity = Binder.clearCallingIdentity();
8530 try {
8531 for (Phone phone: PhoneFactory.getPhones()) {
8532 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8533 if (tracker != null) {
8534 tracker.executeEmergencyNumberTestModeCommand(action, num);
8535 }
8536 }
8537 } finally {
8538 Binder.restoreCallingIdentity(identity);
8539 }
8540 }
8541
8542 /**
8543 * Get the full emergency number list for test mode.
8544 */
8545 @Override
8546 public List<String> getEmergencyNumberListTestMode() {
8547 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8548 "getEmergencyNumberListTestMode");
8549
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
8552 Set<String> emergencyNumbers = new HashSet<>();
8553 for (Phone phone: PhoneFactory.getPhones()) {
8554 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8555 if (tracker != null) {
8556 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8557 emergencyNumbers.add(num.getNumber());
8558 }
8559 }
8560 }
8561 return new ArrayList<>(emergencyNumbers);
8562 } finally {
8563 Binder.restoreCallingIdentity(identity);
8564 }
8565 }
8566
chen xud6b45bd2018-10-30 22:27:10 -07008567 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008568 public int getEmergencyNumberDbVersion(int subId) {
8569 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8570
8571 final long identity = Binder.clearCallingIdentity();
8572 try {
8573 final Phone phone = getPhone(subId);
8574 if (phone == null) {
8575 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8576 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8577 }
8578 return phone.getEmergencyNumberDbVersion();
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
8583
8584 @Override
8585 public void notifyOtaEmergencyNumberDbInstalled() {
8586 enforceModifyPermission();
8587
8588 final long identity = Binder.clearCallingIdentity();
8589 try {
8590 for (Phone phone: PhoneFactory.getPhones()) {
8591 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8592 if (tracker != null) {
8593 tracker.updateOtaEmergencyNumberDatabase();
8594 }
8595 }
8596 } finally {
8597 Binder.restoreCallingIdentity(identity);
8598 }
8599 }
8600
8601 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008602 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008603 enforceActiveEmergencySessionPermission();
8604
8605 final long identity = Binder.clearCallingIdentity();
8606 try {
8607 for (Phone phone: PhoneFactory.getPhones()) {
8608 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8609 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008610 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8611 }
8612 }
8613 } finally {
8614 Binder.restoreCallingIdentity(identity);
8615 }
8616 }
8617
8618 @Override
8619 public void resetOtaEmergencyNumberDbFilePath() {
8620 enforceActiveEmergencySessionPermission();
8621
8622 final long identity = Binder.clearCallingIdentity();
8623 try {
8624 for (Phone phone: PhoneFactory.getPhones()) {
8625 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8626 if (tracker != null) {
8627 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008628 }
8629 }
8630 } finally {
8631 Binder.restoreCallingIdentity(identity);
8632 }
8633 }
8634
8635 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008636 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8637 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8638 Phone phone = getPhone(subId);
8639 if (phone == null) {
8640 return null;
8641 }
8642 final long identity = Binder.clearCallingIdentity();
8643 try {
8644 UiccProfile profile = UiccController.getInstance()
8645 .getUiccProfileForPhone(phone.getPhoneId());
8646 if (profile != null) {
8647 return profile.getCertsFromCarrierPrivilegeAccessRules();
8648 }
8649 } finally {
8650 Binder.restoreCallingIdentity(identity);
8651 }
8652 return null;
8653 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008654
8655 /**
8656 * Enable or disable a modem stack.
8657 */
8658 @Override
8659 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8660 enforceModifyPermission();
8661
8662 final long identity = Binder.clearCallingIdentity();
8663 try {
8664 Phone phone = PhoneFactory.getPhone(slotIndex);
8665 if (phone == null) {
8666 return false;
8667 } else {
8668 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8669 }
8670 } finally {
8671 Binder.restoreCallingIdentity(identity);
8672 }
8673 }
Michelecea4cf22018-12-21 15:00:11 -08008674
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008675 /**
8676 * Whether a modem stack is enabled or not.
8677 */
8678 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008679 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8680 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008681 Phone phone = PhoneFactory.getPhone(slotIndex);
8682 if (phone == null) return false;
8683
8684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008685 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8686 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008687 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8688 }
8689
8690 final long identity = Binder.clearCallingIdentity();
8691 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008692 try {
8693 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8694 } catch (NoSuchElementException ex) {
8695 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8696 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008697 } finally {
8698 Binder.restoreCallingIdentity(identity);
8699 }
8700 }
8701
Michelecea4cf22018-12-21 15:00:11 -08008702 @Override
Michele0ea7d782019-03-19 14:58:42 -07008703 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008704 enforceModifyPermission();
8705
8706 final long identity = Binder.clearCallingIdentity();
8707 try {
8708 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008709 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008710 .commit();
8711 } finally {
8712 Binder.restoreCallingIdentity(identity);
8713 }
8714 }
8715
8716 @Override
Michele0ea7d782019-03-19 14:58:42 -07008717 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008718 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008720 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8721 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008722 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008723 }
Michelecea4cf22018-12-21 15:00:11 -08008724
8725 final long identity = Binder.clearCallingIdentity();
8726 try {
Michele0ea7d782019-03-19 14:58:42 -07008727 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008728 } finally {
8729 Binder.restoreCallingIdentity(identity);
8730 }
8731 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008732
Michele0ea7d782019-03-19 14:58:42 -07008733 @TelephonyManager.IsMultiSimSupportedResult
8734 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008735 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8736 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8737 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008738 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8739 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008740 }
8741 // Check if the hardware supports multisim functionality. If usage of multisim is not
8742 // supported by the modem, indicate that it is restricted.
8743 PhoneCapability staticCapability =
8744 mPhoneConfigurationManager.getStaticPhoneCapability();
8745 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008746 loge("isMultiSimSupportedInternal: no static configuration available");
8747 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008748 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008749 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008750 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8751 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008752 }
8753 // Check if support of multiple SIMs is restricted by carrier
8754 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008755 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008756 }
8757
Michele0ea7d782019-03-19 14:58:42 -07008758 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008759 }
8760
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008761 /**
8762 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008763 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8764 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8765 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008766 * @param numOfSims number of active sims we want to switch to
8767 */
8768 @Override
8769 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008770 if (numOfSims == 1) {
8771 enforceModifyPermission();
8772 } else {
8773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8774 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8775 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008776 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008777
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008778 try {
Michele30b57b22019-03-01 12:01:14 -08008779 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008780 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008781 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8782 return;
8783 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008784 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8785 } finally {
8786 Binder.restoreCallingIdentity(identity);
8787 }
8788 }
8789
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008790 @Override
8791 public boolean isApplicationOnUicc(int subId, int appType) {
8792 enforceReadPrivilegedPermission("isApplicationOnUicc");
8793 Phone phone = getPhone(subId);
8794 if (phone == null) {
8795 return false;
8796 }
8797 final long identity = Binder.clearCallingIdentity();
8798 try {
8799 UiccCard uiccCard = phone.getUiccCard();
8800 if (uiccCard == null) {
8801 return false;
8802 }
8803 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8804 if (uiccProfile == null) {
8805 return false;
8806 }
8807 if (TelephonyManager.APPTYPE_SIM <= appType
8808 && appType <= TelephonyManager.APPTYPE_ISIM) {
8809 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8810 }
8811 return false;
8812 } finally {
8813 Binder.restoreCallingIdentity(identity);
8814 }
8815 }
8816
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008817 /**
chen xub4baa772019-04-03 10:23:41 -07008818 * Get whether making changes to modem configurations will trigger reboot.
8819 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008820 */
8821 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008822 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8823 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008825 mApp, subId, callingPackage, callingFeatureId,
8826 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008827 return false;
8828 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008829 final long identity = Binder.clearCallingIdentity();
8830 try {
8831 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8832 } finally {
8833 Binder.restoreCallingIdentity(identity);
8834 }
8835 }
8836
Nathan Harold29f5f052019-02-15 13:41:57 -08008837 private void updateModemStateMetrics() {
8838 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8839 // TODO: check the state for each modem if the api is ready.
8840 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8841 }
8842
Pengquan Meng3889a572019-01-23 11:16:29 -08008843 @Override
8844 public int[] getSlotsMapping() {
8845 enforceReadPrivilegedPermission("getSlotsMapping");
8846
8847 final long identity = Binder.clearCallingIdentity();
8848 try {
8849 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8850 // All logical slots should have a mapping to a physical slot.
8851 int[] logicalSlotsMapping = new int[phoneCount];
8852 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8853 for (int i = 0; i < slotInfos.length; i++) {
8854 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8855 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8856 }
8857 }
8858 return logicalSlotsMapping;
8859 } finally {
8860 Binder.restoreCallingIdentity(identity);
8861 }
8862 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008863
8864 /**
8865 * Get the IRadio HAL Version
8866 */
8867 @Override
8868 public int getRadioHalVersion() {
8869 Phone phone = getDefaultPhone();
8870 if (phone == null) return -1;
8871 HalVersion hv = phone.getHalVersion();
8872 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8873 return hv.major * 100 + hv.minor;
8874 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008875
8876 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008877 * Get the current calling package name.
8878 * @return the current calling package name
8879 */
8880 @Override
8881 public String getCurrentPackageName() {
8882 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8883 }
8884
8885 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008886 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8887 * corresponding network requests on a subId.
8888 *
8889 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008890 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008891 * 2) APN is un-metered for this subscription, or
8892 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008893 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008894 *
8895 * @return whether data is allowed for a apn type.
8896 *
8897 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008898 */
8899 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008900 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008901 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8902 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008903
8904 // Now that all security checks passes, perform the operation as ourselves.
8905 final long identity = Binder.clearCallingIdentity();
8906 try {
8907 Phone phone = getPhone(subId);
8908 if (phone == null) return false;
8909
Jack Yu41407ee2019-05-13 16:54:09 -07008910 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8912 } finally {
8913 Binder.restoreCallingIdentity(identity);
8914 }
8915 }
8916
8917 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008918 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008919 enforceReadPrivilegedPermission("isApnMetered");
8920
8921 // Now that all security checks passes, perform the operation as ourselves.
8922 final long identity = Binder.clearCallingIdentity();
8923 try {
8924 Phone phone = getPhone(subId);
8925 if (phone == null) return true; // By default return true.
8926
Jack Yu41407ee2019-05-13 16:54:09 -07008927 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008928 } finally {
8929 Binder.restoreCallingIdentity(identity);
8930 }
8931 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008932
8933 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008934 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8935 int subscriptionId, IBooleanConsumer resultCallback) {
8936 enforceModifyPermission();
8937 long token = Binder.clearCallingIdentity();
8938 try {
8939 Phone phone = getPhone(subscriptionId);
8940 if (phone == null) {
8941 try {
8942 if (resultCallback != null) {
8943 resultCallback.accept(false);
8944 }
8945 } catch (RemoteException e) {
8946 // ignore
8947 }
8948 return;
8949 }
8950 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8951 Pair.create(specifiers, (x) -> {
8952 try {
8953 if (resultCallback != null) {
8954 resultCallback.accept(x);
8955 }
8956 } catch (RemoteException e) {
8957 // ignore
8958 }
8959 });
8960 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8961 } finally {
8962 Binder.restoreCallingIdentity(token);
8963 }
8964 }
8965
8966 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008967 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8968 TelephonyPermissions
8969 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8970 mApp, subId, "getSystemSelectionChannels");
8971 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8972 final long identity = Binder.clearCallingIdentity();
8973 try {
8974 List<RadioAccessSpecifier> specifiers =
8975 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8976 null, subId, workSource);
8977 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8978 return specifiers;
8979 } finally {
8980 Binder.restoreCallingIdentity(identity);
8981 }
8982 }
8983
8984 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008985 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008986 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008987 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8988 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8989 if (iccRecords == null) {
8990 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8991 return false;
8992 }
8993 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8994 }
8995
8996 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008997 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8998 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008999 if (callingPackage == null) {
9000 callingPackage = getCurrentPackageName();
9001 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009002 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9003 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009004 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9005 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009006 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9007 }
9008 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9009 Intent intent = new Intent();
9010 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9011 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9012 // Bring up choose default SMS subscription dialog right now
9013 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9014 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9015 mApp.startActivity(intent);
9016 }
chen xud5ca2d52019-05-28 15:20:57 -07009017
9018 @Override
9019 public String getMmsUAProfUrl(int subId) {
9020 //TODO investigate if this API should require proper permission check in R b/133791609
9021 final long identity = Binder.clearCallingIdentity();
9022 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009023 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9024 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9025 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9026 return carrierUAProfUrl;
9027 }
chen xud5ca2d52019-05-28 15:20:57 -07009028 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9029 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9030 } finally {
9031 Binder.restoreCallingIdentity(identity);
9032 }
9033 }
9034
9035 @Override
9036 public String getMmsUserAgent(int subId) {
9037 //TODO investigate if this API should require proper permission check in R b/133791609
9038 final long identity = Binder.clearCallingIdentity();
9039 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009040 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9041 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9042 if (!TextUtils.isEmpty(carrierUserAgent)) {
9043 return carrierUserAgent;
9044 }
chen xud5ca2d52019-05-28 15:20:57 -07009045 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9046 .getString(com.android.internal.R.string.config_mms_user_agent);
9047 } finally {
9048 Binder.restoreCallingIdentity(identity);
9049 }
9050 }
Jack Yub07d4972019-05-28 16:12:25 -07009051
9052 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009053 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9054 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9055
9056 final long identity = Binder.clearCallingIdentity();
9057 try {
9058 Phone phone = getPhone(subscriptionId);
9059 if (phone == null) return false;
9060
9061 switch (policy) {
9062 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9063 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9064 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9065 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9066 default:
9067 throw new IllegalArgumentException(policy + " is not a valid policy");
9068 }
9069 } finally {
9070 Binder.restoreCallingIdentity(identity);
9071 }
9072 }
9073
9074 @Override
9075 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9076 boolean enabled) {
9077 enforceModifyPermission();
9078
9079 final long identity = Binder.clearCallingIdentity();
9080 try {
9081 Phone phone = getPhone(subscriptionId);
9082 if (phone == null) return;
9083
9084 switch (policy) {
9085 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9086 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9087 break;
9088 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9089 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9090 break;
9091 default:
9092 throw new IllegalArgumentException(policy + " is not a valid policy");
9093 }
9094 } finally {
9095 Binder.restoreCallingIdentity(identity);
9096 }
9097 }
9098
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009099 /**
Hall Liub48cf452020-09-25 11:13:49 -07009100 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009101 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9102 * otherwise.
9103 */
9104 @Override
9105 public void setCepEnabled(boolean isCepEnabled) {
9106 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9107
9108 final long identity = Binder.clearCallingIdentity();
9109 try {
9110 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9111 for (Phone phone : PhoneFactory.getPhones()) {
9112 Phone defaultPhone = phone.getImsPhone();
9113 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9114 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9115 ImsPhoneCallTracker imsPhoneCallTracker =
9116 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9117 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9118 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9119 + imsPhone.getMsisdn());
9120 }
9121 }
9122 } finally {
9123 Binder.restoreCallingIdentity(identity);
9124 }
9125 }
allenwtsu46dcc572020-01-08 18:24:03 +08009126
9127 /**
9128 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9129 *
9130 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9131 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9132 * before being read.
9133 */
9134 @Override
9135 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9136 isCompressed) {
9137 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9138 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9140 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9141 }
9142 if (!isImsAvailableOnDevice()) {
9143 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9144 "IMS not available on device.");
9145 }
9146
9147 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009148 try {
Hui Wang068ab862020-10-31 05:12:53 +00009149 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9150 } finally {
9151 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009152 }
9153 }
zoey chenf95ca592019-12-30 16:11:23 +08009154
9155 @Override
9156 public boolean isIccLockEnabled(int subId) {
9157 enforceReadPrivilegedPermission("isIccLockEnabled");
9158
9159 // Now that all security checks passes, perform the operation as ourselves.
9160 final long identity = Binder.clearCallingIdentity();
9161 try {
9162 Phone phone = getPhone(subId);
9163 if (phone != null && phone.getIccCard() != null) {
9164 return phone.getIccCard().getIccLockEnabled();
9165 } else {
9166 return false;
9167 }
9168 } finally {
9169 Binder.restoreCallingIdentity(identity);
9170 }
9171 }
9172
9173 /**
zoey chene02881a2019-12-30 16:11:23 +08009174 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009175 *
zoey chene02881a2019-12-30 16:11:23 +08009176 * @return an integer representing the status of IccLock enabled or disabled in the following
9177 * three cases:
9178 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9179 * successfully.
9180 * - Positive number and zero for remaining password attempts.
9181 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009182 *
9183 */
9184 @Override
9185 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9186 enforceModifyPermission();
9187
9188 Phone phone = getPhone(subId);
9189 if (phone == null) {
9190 return 0;
9191 }
9192 // Now that all security checks passes, perform the operation as ourselves.
9193 final long identity = Binder.clearCallingIdentity();
9194 try {
9195 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9196 new Pair<Boolean, String>(enabled, password), phone, null);
9197 return attemptsRemaining;
9198
9199 } catch (Exception e) {
9200 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9201 } finally {
9202 Binder.restoreCallingIdentity(identity);
9203 }
9204 return 0;
9205 }
9206
9207 /**
9208 * Change the ICC password used in ICC pin lock.
9209 *
zoey chene02881a2019-12-30 16:11:23 +08009210 * @return an integer representing the status of IccLock changed in the following three cases:
9211 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9212 * - Positive number and zero for remaining password attempts.
9213 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009214 *
9215 */
9216 @Override
9217 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9218 enforceModifyPermission();
9219
9220 Phone phone = getPhone(subId);
9221 if (phone == null) {
9222 return 0;
9223 }
9224 // Now that all security checks passes, perform the operation as ourselves.
9225 final long identity = Binder.clearCallingIdentity();
9226 try {
9227 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9228 new Pair<String, String>(oldPassword, newPassword), phone, null);
9229 return attemptsRemaining;
9230
9231 } catch (Exception e) {
9232 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9233 } finally {
9234 Binder.restoreCallingIdentity(identity);
9235 }
9236 return 0;
9237 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009238
Peter Wangdafb9ac2020-01-15 14:13:38 -08009239 /**
9240 * Request for receiving user activity notification
9241 */
9242 @Override
9243 public void requestUserActivityNotification() {
9244 if (!mNotifyUserActivity.get()
9245 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9246 mNotifyUserActivity.set(true);
9247 }
9248 }
9249
9250 /**
9251 * Called when userActivity is signalled in the power manager.
9252 * This is safe to call from any thread, with any window manager locks held or not.
9253 */
9254 @Override
9255 public void userActivity() {
9256 // ***************************************
9257 // * Inherited from PhoneWindowManager *
9258 // ***************************************
9259 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9260 // WITH ITS LOCKS HELD.
9261 //
9262 // This code must be VERY careful about the locks
9263 // it acquires.
9264 // In fact, the current code acquires way too many,
9265 // and probably has lurking deadlocks.
9266
9267 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9268 throw new SecurityException("Only the OS may call notifyUserActivity()");
9269 }
9270
9271 if (mNotifyUserActivity.getAndSet(false)) {
9272 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9273 USER_ACTIVITY_NOTIFICATION_DELAY);
9274 }
9275 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009276
Malcolm Chen884180b2020-04-13 11:59:40 -07009277 @Override
9278 public boolean canConnectTo5GInDsdsMode() {
9279 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9280 }
Jack Yud10cdd42020-09-28 20:28:01 -07009281
9282 @Override
9283 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9284 String callingFeatureId) {
9285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9286 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9287 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9288 }
9289
9290 Phone phone = getPhone(subId);
9291 if (phone == null) {
9292 throw new RuntimeException("phone is not available");
9293 }
9294 // Now that all security checks passes, perform the operation as ourselves.
9295 final long identity = Binder.clearCallingIdentity();
9296 try {
9297 return phone.getEquivalentHomePlmns();
9298 } finally {
9299 Binder.restoreCallingIdentity(identity);
9300 }
9301 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009302
Hui Wang0866fcc2020-10-12 12:14:23 -07009303 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009304 public boolean isRadioInterfaceCapabilitySupported(
9305 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009306 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009307 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9308 if (radioInterfaceCapabilities == null) {
9309 throw new RuntimeException("radio interface capabilities are not available");
9310 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009311 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009312 }
9313 }
9314
9315 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009316 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9317 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009318 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9319 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9320 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9321 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9322 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009323 if (DBG) {
9324 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9325 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9326 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9327 }
9328
9329 if (!SubscriptionManager.isValidSubscriptionId(subId)
9330 || appType < TelephonyManager.APPTYPE_UNKNOWN
9331 || appType > TelephonyManager.APPTYPE_ISIM
9332 || nafUrl == null || securityProtocol == null || callback == null) {
9333 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9334 if (callback != null) {
9335 try {
9336 callback.onAuthenticationFailure(
9337 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9338 } catch (RemoteException exception) {
9339 log("Fail to notify onAuthenticationFailure due to " + exception);
9340 }
9341 return;
9342 }
9343 }
9344
9345 final long token = Binder.clearCallingIdentity();
9346 try {
9347 getGbaManager(subId).bootstrapAuthenticationRequest(
9348 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9349 forceBootStrapping, callback));
9350 } finally {
9351 Binder.restoreCallingIdentity(token);
9352 }
9353 }
9354
Jack Nudelman24d51a52020-11-24 12:08:04 -08009355 /**
9356 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9357 * requested radio power state will actually be set. See {@link
9358 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9359 *
9360 * @param subId the subscription ID of the phone requesting to set the radio power state.
9361 * @param enable {@code true} if trying to turn radio on.
9362 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9363 * false}.
9364 */
9365 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9366 Phone phone = getPhone(subId);
9367 if (phone != null) {
9368 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9369 return true;
9370 }
9371 return false;
9372 }
9373
9374 private int handleDataThrottlingRequest(int subId,
9375 DataThrottlingRequest dataThrottlingRequest) {
9376 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9377 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9378 if (!setRadioPowerForThermal(subId, true)) {
9379 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9380 }
9381
9382 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9383
9384 int thermalMitigationResult =
9385 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9386 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9387 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9388 }
9389 return thermalMitigationResult;
9390 }
9391
9392 /**
9393 * Thermal mitigation request to control functionalities at modem.
9394 *
9395 * @param subId the id of the subscription.
9396 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9397 *
9398 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9399 */
9400 @Override
9401 @ThermalMitigationResult
9402 public int sendThermalMitigationRequest(
9403 int subId,
9404 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9405 enforceModifyPermission();
9406
9407 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9408 final long identity = Binder.clearCallingIdentity();
9409
9410 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9411 try {
9412 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9413 switch (thermalMitigationAction) {
9414 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9415 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009416 handleDataThrottlingRequest(subId,
9417 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009418 break;
9419 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9420 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9421 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9422 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9423 }
9424
9425 // Ensure that radio is on. If not able to power on due to phone being
9426 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9427 if (!setRadioPowerForThermal(subId, true)) {
9428 thermalMitigationResult =
9429 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9430 break;
9431 }
9432
9433 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9434 false);
9435 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9436 break;
9437 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9438 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9439 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9440 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9441 }
9442
9443 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9444 if (registry != null) {
9445 TelephonyConnectionService service =
9446 registry.getTelephonyConnectionService();
9447 Phone phone = getPhone(subId);
9448 if (phone == null) {
9449 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009450 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009451 break;
9452 }
9453
9454 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009455 != TelephonyManager.CALL_STATE_IDLE
9456 || phone.isInEmergencySmsMode() || phone.isInEcm()
9457 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009458 String errorMessage = "Phone state is not valid. call state = "
9459 + PhoneConstantConversions.convertCallState(phone.getState())
9460 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9461 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9462 errorMessage += service == null
9463 ? " TelephonyConnectionService is null"
9464 : " isEmergencyCallPending = "
9465 + service.isEmergencyCallPending();
9466 Log.e(LOG_TAG, errorMessage);
9467 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009468 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009469 break;
9470 }
9471 } else {
9472 thermalMitigationResult =
9473 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9474 break;
9475 }
9476
9477 // Turn radio off. If not able to power off due to phone being unavailable,
9478 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9479 if (!setRadioPowerForThermal(subId, false)) {
9480 thermalMitigationResult =
9481 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9482 break;
9483 }
9484 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009485 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009486 break;
9487 default:
9488 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9489 + "not exist. Requested action: " + thermalMitigationAction);
9490 }
9491 } catch (IllegalArgumentException e) {
9492 throw e;
9493 } catch (Exception e) {
9494 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9495 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9496 } finally {
9497 Binder.restoreCallingIdentity(identity);
9498 }
9499
9500 if (DBG) {
9501 log("thermalMitigationRequest returning with thermalMitigationResult: "
9502 + thermalMitigationResult);
9503 }
9504
9505 return thermalMitigationResult;
9506 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009507
9508 /**
9509 * Set the GbaService Package Name that Telephony will bind to.
9510 *
9511 * @param subId The sim that the GbaService is associated with.
9512 * @param packageName The name of the package to be replaced with.
9513 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9514 */
9515 @Override
9516 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9517 enforceModifyPermission();
9518
9519 final long identity = Binder.clearCallingIdentity();
9520 try {
9521 return getGbaManager(subId).overrideServicePackage(packageName);
9522 } finally {
9523 Binder.restoreCallingIdentity(identity);
9524 }
9525 }
9526
9527 /**
9528 * Return the package name of the currently bound GbaService.
9529 *
9530 * @param subId The sim that the GbaService is associated with.
9531 * @return the package name of the GbaService configuration, null if GBA is not supported.
9532 */
9533 @Override
9534 public String getBoundGbaService(int subId) {
9535 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9536
9537 final long identity = Binder.clearCallingIdentity();
9538 try {
9539 return getGbaManager(subId).getServicePackage();
9540 } finally {
9541 Binder.restoreCallingIdentity(identity);
9542 }
9543 }
9544
9545 /**
9546 * Set the release time for telephony to unbind GbaService.
9547 *
9548 * @param subId The sim that the GbaService is associated with.
9549 * @param interval The release time to unbind GbaService by millisecond.
9550 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9551 */
9552 @Override
9553 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9554 enforceModifyPermission();
9555
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 return getGbaManager(subId).overrideReleaseTime(interval);
9559 } finally {
9560 Binder.restoreCallingIdentity(identity);
9561 }
9562 }
9563
9564 /**
9565 * Return the release time for telephony to unbind GbaService.
9566 *
9567 * @param subId The sim that the GbaService is associated with.
9568 * @return The release time to unbind GbaService by millisecond.
9569 */
9570 @Override
9571 public int getGbaReleaseTime(int subId) {
9572 enforceReadPrivilegedPermission("getGbaReleaseTime");
9573
9574 final long identity = Binder.clearCallingIdentity();
9575 try {
9576 return getGbaManager(subId).getReleaseTime();
9577 } finally {
9578 Binder.restoreCallingIdentity(identity);
9579 }
9580 }
9581
9582 private GbaManager getGbaManager(int subId) {
9583 GbaManager instance = GbaManager.getInstance(subId);
9584 if (instance == null) {
9585 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9586 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9587 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9588 }
9589 return instance;
9590 }
Hui Wang068ab862020-10-31 05:12:53 +00009591
9592 /**
9593 * indicate whether the device and the carrier can support
9594 * RCS VoLTE single registration.
9595 */
9596 @Override
9597 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009598 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9599 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9600 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9601 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009602
9603 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9604 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9605 }
9606
9607 final long identity = Binder.clearCallingIdentity();
9608 try {
9609 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9610 if (rpm != null) {
9611 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9612 }
9613 return false;
9614 } finally {
9615 Binder.restoreCallingIdentity(identity);
9616 }
9617 }
9618
9619 /**
9620 * Register RCS provisioning callback.
9621 */
9622 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009623 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009624 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009625 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009626 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009627 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9628 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009629
9630 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9631 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9632 }
9633 if (!isImsAvailableOnDevice()) {
9634 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9635 "IMS not available on device.");
9636 }
9637
9638 final long identity = Binder.clearCallingIdentity();
9639 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009640 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009641 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009642 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9643 "Service not available for the subscription.");
9644 }
Hui Wang068ab862020-10-31 05:12:53 +00009645 } finally {
9646 Binder.restoreCallingIdentity(identity);
9647 }
9648 }
9649
9650 /**
9651 * Unregister RCS provisioning callback.
9652 */
9653 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009654 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009655 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009656 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009657 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009658 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9659 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009660
9661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9662 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9663 }
9664 if (!isImsAvailableOnDevice()) {
9665 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9666 "IMS not available on device.");
9667 }
9668
9669 final long identity = Binder.clearCallingIdentity();
9670 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009671 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009672 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009673 } finally {
9674 Binder.restoreCallingIdentity(identity);
9675 }
9676 }
9677
9678 /**
9679 * trigger RCS reconfiguration.
9680 */
9681 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009682 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9683 "triggerRcsReconfiguration",
9684 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009685
9686 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9687 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9688 }
9689 if (!isImsAvailableOnDevice()) {
9690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9691 "IMS not available on device.");
9692 }
9693
9694 final long identity = Binder.clearCallingIdentity();
9695 try {
9696 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9697 } finally {
9698 Binder.restoreCallingIdentity(identity);
9699 }
9700 }
9701
9702 /**
9703 * Provide the client configuration parameters of the RCS application.
9704 */
9705 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009706 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9707 "setRcsClientConfiguration",
9708 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009709
9710 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9711 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9712 }
9713 if (!isImsAvailableOnDevice()) {
9714 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9715 "IMS not available on device.");
9716 }
9717
9718 final long identity = Binder.clearCallingIdentity();
9719
9720 try {
9721 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9722 if (configBinder == null) {
9723 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9724 } else {
9725 configBinder.setRcsClientConfiguration(rcc);
9726 }
9727 } catch (RemoteException e) {
9728 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9729 } finally {
9730 Binder.restoreCallingIdentity(identity);
9731 }
9732 }
9733
9734 /**
Hui Wang19a21872021-02-19 20:45:36 -08009735 * Enables or disables the test mode for RCS VoLTE single registration.
9736 */
9737 @Override
9738 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9739 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9740 "setRcsSingleRegistrationTestModeEnabled");
9741
9742 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9743 }
9744
9745 /**
9746 * Gets the test mode for RCS VoLTE single registration.
9747 */
9748 @Override
9749 public boolean getRcsSingleRegistrationTestModeEnabled() {
9750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9751 "getRcsSingleRegistrationTestModeEnabled");
9752
9753 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9754 }
9755
9756 /**
Hui Wang068ab862020-10-31 05:12:53 +00009757 * Overrides the config of RCS VoLTE single registration enabled for the device.
9758 */
9759 @Override
9760 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9762 "setDeviceSingleRegistrationEnabledOverride");
9763 enforceModifyPermission();
9764
9765 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9766 : Boolean.parseBoolean(enabledStr);
9767 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009768 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009769 }
9770
9771 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009772 * Sends a device to device communication message. Only usable via shell.
9773 * @param message message to send.
9774 * @param value message value.
9775 */
9776 @Override
9777 public void sendDeviceToDeviceMessage(int message, int value) {
9778 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9779 "setCarrierSingleRegistrationEnabledOverride");
9780 enforceModifyPermission();
9781
9782 final long identity = Binder.clearCallingIdentity();
9783 try {
9784 TelephonyConnectionService service =
9785 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9786 if (service == null) {
9787 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9788 return;
9789 }
9790 service.sendTestDeviceToDeviceMessage(message, value);
9791 } finally {
9792 Binder.restoreCallingIdentity(identity);
9793 }
9794 }
9795
9796
9797 /**
Hui Wang068ab862020-10-31 05:12:53 +00009798 * Gets the config of RCS VoLTE single registration enabled for the device.
9799 */
9800 @Override
9801 public boolean getDeviceSingleRegistrationEnabled() {
9802 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9803 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9804 }
9805
9806 /**
9807 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9808 */
9809 @Override
9810 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9811 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9812 "setCarrierSingleRegistrationEnabledOverride");
9813 enforceModifyPermission();
9814
9815 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9816 : Boolean.parseBoolean(enabledStr);
9817 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9818 subId, enabled);
9819 }
9820
9821 /**
9822 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9823 */
9824 @Override
9825 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9826 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9827 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9828 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009829
9830 /**
9831 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9832 * their mobile plan.
9833 */
9834 @Override
9835 public String getMobileProvisioningUrl() {
9836 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9837 final long identity = Binder.clearCallingIdentity();
9838 try {
9839 return getDefaultPhone().getMobileProvisioningUrl();
9840 } finally {
9841 Binder.restoreCallingIdentity(identity);
9842 }
9843 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009844
James.cf Linbcdf8b32021-01-14 16:44:13 +08009845 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009846 * Get the EAB contact from the EAB database.
9847 */
9848 @Override
9849 public String getContactFromEab(String contact) {
9850 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9851 enforceModifyPermission();
9852 final long identity = Binder.clearCallingIdentity();
9853 try {
9854 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9855 } finally {
9856 Binder.restoreCallingIdentity(identity);
9857 }
9858 }
9859
9860 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009861 * Remove the EAB contacts from the EAB database.
9862 */
9863 @Override
9864 public int removeContactFromEab(int subId, String contacts) {
9865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9866 enforceModifyPermission();
9867 final long identity = Binder.clearCallingIdentity();
9868 try {
9869 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9870 } finally {
9871 Binder.restoreCallingIdentity(identity);
9872 }
9873 }
9874
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009875 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009876 public boolean getDeviceUceEnabled() {
9877 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9878 final long identity = Binder.clearCallingIdentity();
9879 try {
9880 return mApp.getDeviceUceEnabled();
9881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 }
9885
9886 @Override
9887 public void setDeviceUceEnabled(boolean isEnabled) {
9888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
9891 mApp.setDeviceUceEnabled(isEnabled);
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
9897 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009898 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9899 String callingPackage) {
9900 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9901 mApp, subId, "setSignalStrengthUpdateRequest");
9902
9903 final int callingUid = Binder.getCallingUid();
9904 // Verify that tha callingPackage belongs to the calling UID
9905 mApp.getSystemService(AppOpsManager.class)
9906 .checkPackage(callingUid, callingPackage);
9907
9908 validateSignalStrengthUpdateRequest(request, callingUid);
9909
9910 final long identity = Binder.clearCallingIdentity();
9911 try {
9912 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9913 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9914
9915 if (result instanceof IllegalStateException) {
9916 throw (IllegalStateException) result;
9917 }
9918 } finally {
9919 Binder.restoreCallingIdentity(identity);
9920 }
9921 }
9922
9923 @Override
9924 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9925 String callingPackage) {
9926 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9927 mApp, subId, "clearSignalStrengthUpdateRequest");
9928
9929 final int callingUid = Binder.getCallingUid();
9930 // Verify that tha callingPackage belongs to the calling UID
9931 mApp.getSystemService(AppOpsManager.class)
9932 .checkPackage(callingUid, callingPackage);
9933
9934 final long identity = Binder.clearCallingIdentity();
9935 try {
9936 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9937 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9938
9939 if (result instanceof IllegalStateException) {
9940 throw (IllegalStateException) result;
9941 }
9942 } finally {
9943 Binder.restoreCallingIdentity(identity);
9944 }
9945 }
9946
9947 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9948 int callingUid) {
9949 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9950 // phone/system process do not have further restriction on request
9951 return;
9952 }
9953
9954 // Applications has restrictions on how to use the request:
9955 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9956 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9957 // This is not system caller which has been checked above
9958 throw new IllegalArgumentException(
9959 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9960 }
9961
9962 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9963 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9964 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9965 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9966 || info.isEnabled()) {
9967 throw new IllegalArgumentException(
9968 "Only system can set hide fields in SignalThresholdInfo");
9969 }
9970
9971 // Thresholds length for each RAN need in range. This has been validated in
9972 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9973 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9974 final int[] thresholds = info.getThresholds();
9975 Objects.requireNonNull(thresholds);
9976 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9977 || thresholds.length
9978 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9979 throw new IllegalArgumentException(
9980 "thresholds length is out of range: " + thresholds.length);
9981 }
9982 }
9983 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009984
9985 /**
9986 * Prepare TelephonyManager for an unattended reboot. The reboot is
9987 * required to be done shortly after the API is invoked.
9988 */
9989 @Override
9990 @TelephonyManager.PrepareUnattendedRebootResult
9991 public int prepareForUnattendedReboot() {
9992 enforceRebootPermission();
9993
9994 final long identity = Binder.clearCallingIdentity();
9995 try {
9996 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
9997 } finally {
9998 Binder.restoreCallingIdentity(identity);
9999 }
10000 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010001}