blob: f75fd3bdd73550a6e925902a04addcce8f3f3df3 [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;
Sooraj Sasindran29654162021-03-03 23:00:01 +0000864 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
865 request.result =
866 TelephonyManager
867 .ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700868 }
869 loge("enableNrDualConnectivity" + ": CommandException: "
870 + ar.exception);
871 } else {
872 loge("enableNrDualConnectivity" + ": Unknown exception");
873 }
874 }
875 notifyRequester(request);
876 break;
877 }
878
SongFerngWang9e060372020-12-21 16:41:52 +0800879 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800881 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
882 request);
883 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800884 break;
885
SongFerngWang9e060372020-12-21 16:41:52 +0800886 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800887 ar = (AsyncResult) msg.obj;
888 request = (MainThreadRequest) ar.userObj;
889 if (ar.exception == null && ar.result != null) {
890 request.result = ar.result; // Integer
891 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530892 // request.result must be set to something non-null
893 // for the calling thread to unblock
894 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800896 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800897 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800898 loge("getAllowedNetworkTypesBitmask: CommandException: "
899 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800901 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800902 }
903 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700904 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800905 break;
906
SongFerngWang9e060372020-12-21 16:41:52 +0800907 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800908 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800909 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
910 request);
911 Pair<Integer, Long> reasonWithNetworkTypes =
912 (Pair<Integer, Long>) request.argument;
913 getPhoneFromRequest(request).setAllowedNetworkTypes(
914 reasonWithNetworkTypes.first,
915 reasonWithNetworkTypes.second,
916 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 break;
918
SongFerngWang9e060372020-12-21 16:41:52 +0800919 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
920 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800921 break;
922
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
924 request = (MainThreadRequest)msg.obj;
925 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800926 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000927 break;
928
929 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
930 ar = (AsyncResult)msg.obj;
931 request = (MainThreadRequest)ar.userObj;
932 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700933 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000934 break;
935
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800936 case CMD_SET_VOICEMAIL_NUMBER:
937 request = (MainThreadRequest) msg.obj;
938 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
939 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800940 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
941 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800942 break;
943
944 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
945 handleNullReturnEvent(msg, "setVoicemailNumber");
946 break;
947
Stuart Scott54788802015-03-30 13:18:01 -0700948 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
949 request = (MainThreadRequest) msg.obj;
950 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
951 request);
952 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
953 break;
954
955 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
956 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
957 break;
958
Shishir Agrawal302c8692015-06-19 13:49:39 -0700959 case CMD_PERFORM_NETWORK_SCAN:
960 request = (MainThreadRequest) msg.obj;
961 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
962 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
963 break;
964
Hall Liua1acea22020-09-18 19:04:59 -0700965 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800966 request = (MainThreadRequest) msg.obj;
967 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700968 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
969 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
970 request.argument;
971 int callForwardingReason = args.first;
972 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800973 break;
Hall Liua1acea22020-09-18 19:04:59 -0700974 }
975 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700978 TelephonyManager.CallForwardingInfoCallback callback =
979 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
980 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800981 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700982 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800983 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
984 for (CallForwardInfo callForwardInfo : callForwardInfos) {
985 // Service Class is a bit mask per 3gpp 27.007. Search for
986 // any service for voice call.
987 if ((callForwardInfo.serviceClass
988 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700989 callForwardingInfo = new CallForwardingInfo(true,
990 callForwardInfo.reason,
991 callForwardInfo.number,
992 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800993 break;
994 }
995 }
996 // Didn't find a call forward info for voice call.
997 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700998 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
999 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -08001000 }
Hall Liua1acea22020-09-18 19:04:59 -07001001 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -08001002 } else {
1003 if (ar.result == null) {
1004 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1005 }
1006 if (ar.exception != null) {
1007 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1008 }
Hall Liuae527aa2020-09-29 17:10:18 -07001009 int errorCode = TelephonyManager
1010 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001011 if (ar.exception instanceof CommandException) {
1012 CommandException.Error error =
1013 ((CommandException) (ar.exception)).getCommandError();
1014 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001015 errorCode = TelephonyManager
1016 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001017 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001018 errorCode = TelephonyManager
1019 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001020 }
1021 }
Hall Liua1acea22020-09-18 19:04:59 -07001022 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001023 }
sqian80370722020-01-29 15:02:51 -08001024 break;
Hall Liua1acea22020-09-18 19:04:59 -07001025 }
sqian80370722020-01-29 15:02:51 -08001026
Hall Liua1acea22020-09-18 19:04:59 -07001027 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001028 request = (MainThreadRequest) msg.obj;
1029 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001030 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001031 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001032 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1033 request.argument).first;
1034 request.phone.setCallForwardingOption(
1035 callForwardingInfoToSet.isEnabled()
1036 ? CommandsInterface.CF_ACTION_ENABLE
1037 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001038 callForwardingInfoToSet.getReason(),
1039 callForwardingInfoToSet.getNumber(),
1040 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1041 break;
Hall Liua1acea22020-09-18 19:04:59 -07001042 }
sqian80370722020-01-29 15:02:51 -08001043
Hall Liua1acea22020-09-18 19:04:59 -07001044 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001045 ar = (AsyncResult) msg.obj;
1046 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001047 Consumer<Integer> callback =
1048 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1049 request.argument).second;
1050 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001051 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001052 int errorCode = TelephonyManager.CallForwardingInfoCallback
1053 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001054 if (ar.exception instanceof CommandException) {
1055 CommandException.Error error =
1056 ((CommandException) (ar.exception)).getCommandError();
1057 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001058 errorCode = TelephonyManager.CallForwardingInfoCallback
1059 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001060 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001061 errorCode = TelephonyManager.CallForwardingInfoCallback
1062 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001063 }
1064 }
1065 callback.accept(errorCode);
1066 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001067 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001068 }
sqian80370722020-01-29 15:02:51 -08001069 break;
Hall Liua1acea22020-09-18 19:04:59 -07001070 }
sqian80370722020-01-29 15:02:51 -08001071
Hall Liua1acea22020-09-18 19:04:59 -07001072 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001073 request = (MainThreadRequest) msg.obj;
1074 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1075 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1076 break;
Hall Liua1acea22020-09-18 19:04:59 -07001077 }
sqian80370722020-01-29 15:02:51 -08001078
Hall Liua1acea22020-09-18 19:04:59 -07001079 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001080 ar = (AsyncResult) msg.obj;
1081 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001082 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001083 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1084 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001085 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001086 // Service Class is a bit mask per 3gpp 27.007.
1087 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001088 if (callForwardResults.length > 1
1089 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001090 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001091 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001092 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1093 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001094 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001095 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001096 }
1097 } else {
1098 if (ar.result == null) {
1099 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1100 }
1101 if (ar.exception != null) {
1102 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1103 }
1104 if (ar.exception instanceof CommandException) {
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 callForwardingStatus =
1109 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1110 }
1111 }
1112 }
Hall Liua1acea22020-09-18 19:04:59 -07001113 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001114 break;
Hall Liua1acea22020-09-18 19:04:59 -07001115 }
sqian80370722020-01-29 15:02:51 -08001116
Hall Liua1acea22020-09-18 19:04:59 -07001117 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001118 request = (MainThreadRequest) msg.obj;
1119 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001120 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1121 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001122 break;
Hall Liua1acea22020-09-18 19:04:59 -07001123 }
sqian80370722020-01-29 15:02:51 -08001124
Hall Liua1acea22020-09-18 19:04:59 -07001125 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001126 ar = (AsyncResult) msg.obj;
1127 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001128 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1129 Consumer<Integer> callback =
1130 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1131 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001132 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001133 if (ar.exception instanceof CommandException) {
1134 CommandException.Error error =
1135 ((CommandException) (ar.exception)).getCommandError();
1136 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1137 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1138 } else {
1139 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1140 }
1141 } else {
1142 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1143 }
1144 } else {
1145 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1146 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001147 }
sqian80370722020-01-29 15:02:51 -08001148 break;
Hall Liua1acea22020-09-18 19:04:59 -07001149 }
sqian80370722020-01-29 15:02:51 -08001150
Shishir Agrawal302c8692015-06-19 13:49:39 -07001151 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1152 ar = (AsyncResult) msg.obj;
1153 request = (MainThreadRequest) ar.userObj;
1154 CellNetworkScanResult cellScanResult;
1155 if (ar.exception == null && ar.result != null) {
1156 cellScanResult = new CellNetworkScanResult(
1157 CellNetworkScanResult.STATUS_SUCCESS,
1158 (List<OperatorInfo>) ar.result);
1159 } else {
1160 if (ar.result == null) {
1161 loge("getCellNetworkScanResults: Empty response");
1162 }
1163 if (ar.exception != null) {
1164 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1165 }
1166 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1167 if (ar.exception instanceof CommandException) {
1168 CommandException.Error error =
1169 ((CommandException) (ar.exception)).getCommandError();
1170 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1171 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1172 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1173 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1174 }
1175 }
1176 cellScanResult = new CellNetworkScanResult(errorCode, null);
1177 }
1178 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
1182 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1183 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001184 ManualNetworkSelectionArgument selArg =
1185 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001186 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1187 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001188 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1189 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001190 break;
1191
1192 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 if (ar.exception == null) {
1196 request.result = true;
1197 } else {
1198 request.result = false;
1199 loge("setNetworkSelectionModeManual " + ar.exception);
1200 }
1201 notifyRequester(request);
1202 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001203 break;
1204
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001205 case CMD_GET_MODEM_ACTIVITY_INFO:
1206 request = (MainThreadRequest) msg.obj;
1207 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001208 if (defaultPhone != null) {
1209 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001210 } else {
1211 ResultReceiver result = (ResultReceiver) request.argument;
1212 Bundle bundle = new Bundle();
1213 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1214 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1215 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001216 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001217 break;
1218
1219 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1220 ar = (AsyncResult) msg.obj;
1221 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001222 ResultReceiver result = (ResultReceiver) request.argument;
1223
1224 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001225 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001226 // Update the last modem activity info and the result of the request.
1227 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1228 if (isModemActivityInfoValid(info)) {
1229 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1230 int[] txTimeMs = info.getTransmitTimeMillis();
1231 int[] lastModemTxTimeMs = mLastModemActivityInfo
1232 .getTransmitTimeMillis();
1233 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1234 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1235 }
1236 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1237 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1238 + mLastModemActivityInfo.getSleepTimeMillis());
1239 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1240 + mLastModemActivityInfo.getIdleTimeMillis());
1241 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1242 mLastModemActivityInfo.setReceiveTimeMillis(
1243 info.getReceiveTimeMillis()
1244 + mLastModemActivityInfo.getReceiveTimeMillis());
1245 }
1246 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1247 mLastModemActivityInfo.getSleepTimeMillis(),
1248 mLastModemActivityInfo.getIdleTimeMillis(),
1249 mLastModemActivityInfo.getTransmitTimeMillis(),
1250 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001251 } else {
1252 if (ar.result == null) {
1253 loge("queryModemActivityInfo: Empty response");
1254 } else if (ar.exception instanceof CommandException) {
1255 loge("queryModemActivityInfo: CommandException: " +
1256 ar.exception);
1257 } else {
1258 loge("queryModemActivityInfo: Unknown exception");
1259 }
1260 }
sqian1a1be542020-03-05 11:37:28 -08001261 Bundle bundle = new Bundle();
1262 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1263 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001264 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001265 break;
1266
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 case CMD_SET_ALLOWED_CARRIERS:
1268 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001269 CarrierRestrictionRules argument =
1270 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001271 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001272 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 break;
1274
1275 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1276 ar = (AsyncResult) msg.obj;
1277 request = (MainThreadRequest) ar.userObj;
1278 if (ar.exception == null && ar.result != null) {
1279 request.result = ar.result;
1280 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001281 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1282 if (ar.exception instanceof CommandException) {
1283 loge("setAllowedCarriers: CommandException: " + ar.exception);
1284 CommandException.Error error =
1285 ((CommandException) (ar.exception)).getCommandError();
1286 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1287 request.result =
1288 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1289 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001290 } else {
1291 loge("setAllowedCarriers: Unknown exception");
1292 }
1293 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001294 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001295 break;
1296
1297 case CMD_GET_ALLOWED_CARRIERS:
1298 request = (MainThreadRequest) msg.obj;
1299 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001300 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 break;
1302
1303 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1304 ar = (AsyncResult) msg.obj;
1305 request = (MainThreadRequest) ar.userObj;
1306 if (ar.exception == null && ar.result != null) {
1307 request.result = ar.result;
1308 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001309 request.result = new IllegalStateException(
1310 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001311 if (ar.result == null) {
1312 loge("getAllowedCarriers: Empty response");
1313 } else if (ar.exception instanceof CommandException) {
1314 loge("getAllowedCarriers: CommandException: " +
1315 ar.exception);
1316 } else {
1317 loge("getAllowedCarriers: Unknown exception");
1318 }
1319 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001320 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001321 break;
1322
Nathan Haroldb3014052017-01-25 15:57:32 -08001323 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1324 ar = (AsyncResult) msg.obj;
1325 request = (MainThreadRequest) ar.userObj;
1326 if (ar.exception == null && ar.result != null) {
1327 request.result = ar.result;
1328 } else {
1329 request.result = new IllegalArgumentException(
1330 "Failed to retrieve Forbidden Plmns");
1331 if (ar.result == null) {
1332 loge("getForbiddenPlmns: Empty response");
1333 } else {
1334 loge("getForbiddenPlmns: Unknown exception");
1335 }
1336 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001338 break;
1339
1340 case CMD_GET_FORBIDDEN_PLMNS:
1341 request = (MainThreadRequest) msg.obj;
1342 uiccCard = getUiccCardFromRequest(request);
1343 if (uiccCard == null) {
1344 loge("getForbiddenPlmns() UiccCard is null");
1345 request.result = new IllegalArgumentException(
1346 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001347 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001348 break;
1349 }
1350 Integer appType = (Integer) request.argument;
1351 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1352 if (uiccApp == null) {
1353 loge("getForbiddenPlmns() no app with specified type -- "
1354 + appType);
1355 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001357 break;
1358 } else {
1359 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1360 + " specified type -- " + appType);
1361 }
1362 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1363 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1364 onCompleted);
1365 break;
1366
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001367 case CMD_SWITCH_SLOTS:
1368 request = (MainThreadRequest) msg.obj;
1369 int[] physicalSlots = (int[]) request.argument;
1370 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1371 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1372 break;
1373
1374 case EVENT_SWITCH_SLOTS_DONE:
1375 ar = (AsyncResult) msg.obj;
1376 request = (MainThreadRequest) ar.userObj;
1377 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001378 notifyRequester(request);
1379 break;
1380 case CMD_GET_NETWORK_SELECTION_MODE:
1381 request = (MainThreadRequest) msg.obj;
1382 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1383 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1384 break;
1385
1386 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1387 ar = (AsyncResult) msg.obj;
1388 request = (MainThreadRequest) ar.userObj;
1389 if (ar.exception != null) {
1390 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1391 } else {
1392 int mode = ((int[]) ar.result)[0];
1393 if (mode == 0) {
1394 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1395 } else {
1396 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1397 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001398 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001399 notifyRequester(request);
1400 break;
1401 case CMD_GET_CDMA_ROAMING_MODE:
1402 request = (MainThreadRequest) msg.obj;
1403 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1404 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1405 break;
1406 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1407 ar = (AsyncResult) msg.obj;
1408 request = (MainThreadRequest) ar.userObj;
1409 if (ar.exception != null) {
1410 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1411 } else {
1412 request.result = ((int[]) ar.result)[0];
1413 }
1414 notifyRequester(request);
1415 break;
1416 case CMD_SET_CDMA_ROAMING_MODE:
1417 request = (MainThreadRequest) msg.obj;
1418 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1419 int mode = (int) request.argument;
1420 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1421 break;
1422 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1423 ar = (AsyncResult) msg.obj;
1424 request = (MainThreadRequest) ar.userObj;
1425 request.result = ar.exception == null;
1426 notifyRequester(request);
1427 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001428 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1429 request = (MainThreadRequest) msg.obj;
1430 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1431 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1432 break;
1433 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1434 ar = (AsyncResult) msg.obj;
1435 request = (MainThreadRequest) ar.userObj;
1436 if (ar.exception != null) {
1437 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1438 } else {
1439 request.result = ((int[]) ar.result)[0];
1440 }
1441 notifyRequester(request);
1442 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001443 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1446 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001447 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1448 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001449 break;
1450 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1451 ar = (AsyncResult) msg.obj;
1452 request = (MainThreadRequest) ar.userObj;
1453 request.result = ar.exception == null;
1454 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001455 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 case CMD_GET_ALL_CELL_INFO:
1457 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001458 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001459 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001460 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001461 case EVENT_GET_ALL_CELL_INFO_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001464 // If a timeout occurs, the response will be null
1465 request.result = (ar.exception == null && ar.result != null)
1466 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001467 synchronized (request) {
1468 request.notifyAll();
1469 }
1470 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001471 case CMD_REQUEST_CELL_INFO_UPDATE:
1472 request = (MainThreadRequest) msg.obj;
1473 request.phone.requestCellInfoUpdate(request.workSource,
1474 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1475 break;
1476 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1477 ar = (AsyncResult) msg.obj;
1478 request = (MainThreadRequest) ar.userObj;
1479 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1480 try {
1481 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001482 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001483 cb.onError(
1484 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1485 ar.exception.getClass().getName(),
1486 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001487 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001488 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001489 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001490 } else {
1491 // use the result as returned
1492 cb.onCellInfo((List<CellInfo>) ar.result);
1493 }
1494 } catch (RemoteException re) {
1495 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1496 }
1497 break;
Sarah Chincc055732020-11-18 13:39:35 -08001498 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 request = (MainThreadRequest) msg.obj;
1500 WorkSource ws = (WorkSource) request.argument;
1501 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001502 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001503 break;
Sarah Chincc055732020-11-18 13:39:35 -08001504 }
1505 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001506 ar = (AsyncResult) msg.obj;
1507 request = (MainThreadRequest) ar.userObj;
1508 if (ar.exception == null) {
1509 request.result = ar.result;
1510 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001511 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001512 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001513 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001514 }
1515
1516 synchronized (request) {
1517 request.notifyAll();
1518 }
1519 break;
Sarah Chincc055732020-11-18 13:39:35 -08001520 }
chen xu6dac5ab2018-10-26 17:39:23 -07001521 case CMD_MODEM_REBOOT:
1522 request = (MainThreadRequest) msg.obj;
1523 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001524 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001525 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001526 case EVENT_CMD_MODEM_REBOOT_DONE:
1527 handleNullReturnEvent(msg, "rebootModem");
1528 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001529 case CMD_REQUEST_ENABLE_MODEM:
1530 request = (MainThreadRequest) msg.obj;
1531 boolean enable = (boolean) request.argument;
1532 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001533 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001534 PhoneConfigurationManager.getInstance()
1535 .enablePhone(request.phone, enable, onCompleted);
1536 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001537 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001538 ar = (AsyncResult) msg.obj;
1539 request = (MainThreadRequest) ar.userObj;
1540 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001541 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001542 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001543 if ((boolean) request.result) {
1544 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1545 updateModemStateMetrics();
1546 } else {
1547 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1548 + ar.exception);
1549 }
1550 notifyRequester(request);
1551 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001552 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001553 case CMD_GET_MODEM_STATUS:
1554 request = (MainThreadRequest) msg.obj;
1555 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1556 PhoneConfigurationManager.getInstance()
1557 .getPhoneStatusFromModem(request.phone, onCompleted);
1558 break;
1559 case EVENT_GET_MODEM_STATUS_DONE:
1560 ar = (AsyncResult) msg.obj;
1561 request = (MainThreadRequest) ar.userObj;
1562 int id = request.phone.getPhoneId();
1563 if (ar.exception == null && ar.result != null) {
1564 request.result = ar.result;
1565 //update the cache as modem status has changed
1566 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1567 (boolean) request.result);
1568 } else {
1569 // Return true if modem status cannot be retrieved. For most cases,
1570 // modem status is on. And for older version modems, GET_MODEM_STATUS
1571 // and disable modem are not supported. Modem is always on.
1572 // TODO: this should be fixed in R to support a third
1573 // status UNKNOWN b/131631629
1574 request.result = true;
1575 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1576 + ar.exception);
1577 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001578 notifyRequester(request);
1579 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001580 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1581 request = (MainThreadRequest) msg.obj;
1582 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1583 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1584 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1585 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1586 break;
1587 }
1588 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1589 ar = (AsyncResult) msg.obj;
1590 request = (MainThreadRequest) ar.userObj;
1591 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1592 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1593 args.second.accept(ar.exception == null);
1594 notifyRequester(request);
1595 break;
1596 }
Sarah Chincc055732020-11-18 13:39:35 -08001597 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1598 request = (MainThreadRequest) msg.obj;
1599 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1600 Phone phone = getPhoneFromRequest(request);
1601 if (phone != null) {
1602 phone.getSystemSelectionChannels(onCompleted);
1603 } else {
1604 loge("getSystemSelectionChannels: No phone object");
1605 request.result = new ArrayList<RadioAccessSpecifier>();
1606 notifyRequester(request);
1607 }
1608 break;
1609 }
1610 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1611 ar = (AsyncResult) msg.obj;
1612 request = (MainThreadRequest) ar.userObj;
1613 if (ar.exception == null && ar.result != null) {
1614 request.result = ar.result;
1615 } else {
1616 request.result = new IllegalArgumentException(
1617 "Failed to retrieve system selection channels");
1618 if (ar.result == null) {
1619 loge("getSystemSelectionChannels: Empty response");
1620 } else {
1621 loge("getSystemSelectionChannels: Unknown exception");
1622 }
1623 }
1624 notifyRequester(request);
1625 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001626 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1627 ar = (AsyncResult) msg.obj;
1628 request = (MainThreadRequest) ar.userObj;
1629 if (ar.exception == null && ar.result != null) {
1630 request.result = ar.result;
1631 } else {
1632 request.result = -1;
1633 loge("Failed to set Forbidden Plmns");
1634 if (ar.result == null) {
1635 loge("setForbidenPlmns: Empty response");
1636 } else if (ar.exception != null) {
1637 loge("setForbiddenPlmns: Exception: " + ar.exception);
1638 request.result = -1;
1639 } else {
1640 loge("setForbiddenPlmns: Unknown exception");
1641 }
1642 }
1643 notifyRequester(request);
1644 break;
1645 case CMD_SET_FORBIDDEN_PLMNS:
1646 request = (MainThreadRequest) msg.obj;
1647 uiccCard = getUiccCardFromRequest(request);
1648 if (uiccCard == null) {
1649 loge("setForbiddenPlmns: UiccCard is null");
1650 request.result = -1;
1651 notifyRequester(request);
1652 break;
1653 }
1654 Pair<Integer, List<String>> setFplmnsArgs =
1655 (Pair<Integer, List<String>>) request.argument;
1656 appType = setFplmnsArgs.first;
1657 List<String> fplmns = setFplmnsArgs.second;
1658 uiccApp = uiccCard.getApplicationByType(appType);
1659 if (uiccApp == null) {
1660 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1661 request.result = -1;
1662 loge("Failed to get UICC App");
1663 notifyRequester(request);
1664 } else {
1665 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1666 ((SIMRecords) uiccApp.getIccRecords())
1667 .setForbiddenPlmns(onCompleted, fplmns);
1668 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001669 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001670 case CMD_ERASE_MODEM_CONFIG:
1671 request = (MainThreadRequest) msg.obj;
1672 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1673 defaultPhone.eraseModemConfig(onCompleted);
1674 break;
1675 case EVENT_ERASE_MODEM_CONFIG_DONE:
1676 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001677 break;
zoey chenf95ca592019-12-30 16:11:23 +08001678
1679 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1680 request = (MainThreadRequest) msg.obj;
1681 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1682 Pair<String, String> changed = (Pair<String, String>) request.argument;
1683 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1684 changed.first, changed.second, onCompleted);
1685 break;
1686 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1687 ar = (AsyncResult) msg.obj;
1688 request = (MainThreadRequest) ar.userObj;
1689 if (ar.exception == null) {
1690 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001691 // If the operation is successful, update the PIN storage
1692 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1693 int phoneId = getPhoneFromRequest(request).getPhoneId();
1694 UiccController.getInstance().getPinStorage()
1695 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001696 } else {
1697 request.result = msg.arg1;
1698 }
1699 notifyRequester(request);
1700 break;
1701
Michele Berionned9fbae52020-11-13 02:36:59 +00001702 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001703 request = (MainThreadRequest) msg.obj;
1704 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1705 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1706 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1707 enabled.first, enabled.second, onCompleted);
1708 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001709 }
zoey chenf95ca592019-12-30 16:11:23 +08001710 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1711 ar = (AsyncResult) msg.obj;
1712 request = (MainThreadRequest) ar.userObj;
1713 if (ar.exception == null) {
1714 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001715 // If the operation is successful, update the PIN storage
1716 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1717 int phoneId = getPhoneFromRequest(request).getPhoneId();
1718 if (enabled.first) {
1719 UiccController.getInstance().getPinStorage()
1720 .storePin(enabled.second, phoneId);
1721 } else {
1722 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1723 }
zoey chenf95ca592019-12-30 16:11:23 +08001724 } else {
1725 request.result = msg.arg1;
1726 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001727
1728
zoey chenf95ca592019-12-30 16:11:23 +08001729 notifyRequester(request);
1730 break;
1731
Peter Wangdafb9ac2020-01-15 14:13:38 -08001732 case MSG_NOTIFY_USER_ACTIVITY:
1733 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001734 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001735 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1736 getDefaultPhone().getContext().sendBroadcastAsUser(
1737 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1738 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001739
1740 case CMD_SET_DATA_THROTTLING: {
1741 request = (MainThreadRequest) msg.obj;
1742 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1743 DataThrottlingRequest dataThrottlingRequest =
1744 (DataThrottlingRequest) request.argument;
1745 Phone phone = getPhoneFromRequest(request);
1746 if (phone != null) {
1747 phone.setDataThrottling(onCompleted,
1748 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1749 dataThrottlingRequest.getCompletionDurationMillis());
1750 } else {
1751 loge("setDataThrottling: No phone object");
1752 request.result =
1753 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1754 notifyRequester(request);
1755 }
1756
1757 break;
1758 }
1759 case EVENT_SET_DATA_THROTTLING_DONE:
1760 ar = (AsyncResult) msg.obj;
1761 request = (MainThreadRequest) ar.userObj;
1762
1763 if (ar.exception == null) {
1764 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1765 } else if (ar.exception instanceof CommandException) {
1766 loge("setDataThrottling: CommandException: " + ar.exception);
1767 CommandException.Error error =
1768 ((CommandException) (ar.exception)).getCommandError();
1769
1770 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1771 request.result = TelephonyManager
1772 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1773 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1774 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1775 } else {
1776 request.result =
1777 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1778 }
1779 } else {
1780 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1781 }
1782 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1783 notifyRequester(request);
1784 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001785
1786 case CMD_SET_SIM_POWER: {
1787 request = (MainThreadRequest) msg.obj;
1788 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1789 request = (MainThreadRequest) msg.obj;
1790 int stateToSet =
1791 ((Pair<Integer, IIntegerConsumer>)
1792 request.argument).first;
1793 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1794 break;
1795 }
1796 case EVENT_SET_SIM_POWER_DONE: {
1797 ar = (AsyncResult) msg.obj;
1798 request = (MainThreadRequest) ar.userObj;
1799 IIntegerConsumer callback =
1800 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1801 if (ar.exception != null) {
1802 loge("setSimPower exception: " + ar.exception);
1803 int errorCode = TelephonyManager.CallForwardingInfoCallback
1804 .RESULT_ERROR_UNKNOWN;
1805 if (ar.exception instanceof CommandException) {
1806 CommandException.Error error =
1807 ((CommandException) (ar.exception)).getCommandError();
1808 if (error == CommandException.Error.SIM_ERR) {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1810 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1812 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1813 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1814 } else {
1815 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1816 }
1817 }
1818 try {
1819 callback.accept(errorCode);
1820 } catch (RemoteException e) {
1821 // Ignore if the remote process is no longer available to call back.
1822 Log.w(LOG_TAG, "setSimPower: callback not available.");
1823 }
1824 } else {
1825 try {
1826 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1827 } catch (RemoteException e) {
1828 // Ignore if the remote process is no longer available to call back.
1829 Log.w(LOG_TAG, "setSimPower: callback not available.");
1830 }
1831 }
1832 break;
1833 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001834 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1835 request = (MainThreadRequest) msg.obj;
1836
1837 final Phone phone = getPhoneFromRequest(request);
1838 if (phone == null || phone.getServiceStateTracker() == null) {
1839 request.result = new IllegalStateException("Phone or SST is null");
1840 notifyRequester(request);
1841 break;
1842 }
1843
1844 Pair<Integer, SignalStrengthUpdateRequest> pair =
1845 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1846 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1847 request);
1848 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1849 request.subId, pair.first /*callingUid*/,
1850 pair.second /*request*/, onCompleted);
1851 break;
1852 }
1853 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1854 ar = (AsyncResult) msg.obj;
1855 request = (MainThreadRequest) ar.userObj;
1856 // request.result will be the exception of ar if present, true otherwise.
1857 // Be cautious not to leave result null which will wait() forever
1858 request.result = ar.exception != null ? ar.exception : true;
1859 notifyRequester(request);
1860 break;
1861 }
1862 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1863 request = (MainThreadRequest) msg.obj;
1864
1865 Phone phone = getPhoneFromRequest(request);
1866 if (phone == null || phone.getServiceStateTracker() == null) {
1867 request.result = new IllegalStateException("Phone or SST is null");
1868 notifyRequester(request);
1869 break;
1870 }
1871
1872 Pair<Integer, SignalStrengthUpdateRequest> pair =
1873 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1874 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1875 request);
1876 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1877 request.subId, pair.first /*callingUid*/,
1878 pair.second /*request*/, onCompleted);
1879 break;
1880 }
1881 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1882 ar = (AsyncResult) msg.obj;
1883 request = (MainThreadRequest) ar.userObj;
1884 request.result = ar.exception != null ? ar.exception : true;
1885 notifyRequester(request);
1886 break;
1887 }
Jordan Liud5366d92020-11-24 14:50:34 -08001888
Michele Berionned9fbae52020-11-13 02:36:59 +00001889 case CMD_PREPARE_UNATTENDED_REBOOT:
1890 request = (MainThreadRequest) msg.obj;
1891 request.result =
1892 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1893 notifyRequester(request);
1894 break;
1895
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001896 default:
1897 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1898 break;
1899 }
1900 }
Jake Hambye994d462014-02-03 13:10:13 -08001901
Pengquan Menga1bb6272018-09-06 09:59:22 -07001902 private void notifyRequester(MainThreadRequest request) {
1903 synchronized (request) {
1904 request.notifyAll();
1905 }
1906 }
1907
Jake Hambye994d462014-02-03 13:10:13 -08001908 private void handleNullReturnEvent(Message msg, String command) {
1909 AsyncResult ar = (AsyncResult) msg.obj;
1910 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1911 if (ar.exception == null) {
1912 request.result = true;
1913 } else {
1914 request.result = false;
1915 if (ar.exception instanceof CommandException) {
1916 loge(command + ": CommandException: " + ar.exception);
1917 } else {
1918 loge(command + ": Unknown exception");
1919 }
1920 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001921 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001922 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001923 }
1924
1925 /**
1926 * Posts the specified command to be executed on the main thread,
1927 * waits for the request to complete, and returns the result.
1928 * @see #sendRequestAsync
1929 */
1930 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001931 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1932 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001933 }
1934
1935 /**
1936 * Posts the specified command to be executed on the main thread,
1937 * waits for the request to complete, and returns the result.
1938 * @see #sendRequestAsync
1939 */
1940 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1941 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001942 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001943 }
1944
1945 /**
1946 * Posts the specified command to be executed on the main thread,
1947 * waits for the request to complete, and returns the result.
1948 * @see #sendRequestAsync
1949 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001950 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001951 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1952 }
1953
1954 /**
1955 * Posts the specified command to be executed on the main thread,
1956 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1957 * if not timeout or null otherwise.
1958 * @see #sendRequestAsync
1959 */
1960 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1961 long timeoutInMs) {
1962 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001963 }
1964
1965 /**
1966 * Posts the specified command to be executed on the main thread,
1967 * waits for the request to complete, and returns the result.
1968 * @see #sendRequestAsync
1969 */
Nathan Harold92bed182018-10-12 18:16:49 -07001970 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001971 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001972 }
1973
1974 /**
1975 * Posts the specified command to be executed on the main thread,
1976 * waits for the request to complete, and returns the result.
1977 * @see #sendRequestAsync
1978 */
1979 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001980 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1981 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001982 }
1983
1984 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001985 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1986 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1987 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001988 * @see #sendRequestAsync
1989 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001990 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1991 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001992 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1993 throw new RuntimeException("This method will deadlock if called from the main thread.");
1994 }
1995
Nathan Harold92bed182018-10-12 18:16:49 -07001996 MainThreadRequest request = null;
1997 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1998 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1999 } else if (phone != null) {
2000 request = new MainThreadRequest(argument, phone, workSource);
2001 } else {
2002 request = new MainThreadRequest(argument, subId, workSource);
2003 }
2004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 Message msg = mMainThreadHandler.obtainMessage(command, request);
2006 msg.sendToTarget();
2007
Rambo Wang0f050d82021-02-12 11:43:36 -08002008
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002009 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002010 if (timeoutInMs >= 0) {
2011 // Wait for at least timeoutInMs before returning null request result
2012 long now = SystemClock.elapsedRealtime();
2013 long deadline = now + timeoutInMs;
2014 while (request == null && now < deadline) {
2015 try {
2016 request.wait(deadline - now);
2017 } catch (InterruptedException e) {
2018 // Do nothing, go back and check if request is completed or timeout
2019 } finally {
2020 now = SystemClock.elapsedRealtime();
2021 }
2022 }
2023 } else {
2024 // Wait for the request to complete
2025 while (request.result == null) {
2026 try {
2027 request.wait();
2028 } catch (InterruptedException e) {
2029 // Do nothing, go back and wait until the request is complete
2030 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002031 }
2032 }
2033 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002034 if (request.result == null) {
2035 Log.wtf(LOG_TAG,
2036 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2037 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002038 return request.result;
2039 }
2040
2041 /**
2042 * Asynchronous ("fire and forget") version of sendRequest():
2043 * Posts the specified command to be executed on the main thread, and
2044 * returns immediately.
2045 * @see #sendRequest
2046 */
2047 private void sendRequestAsync(int command) {
2048 mMainThreadHandler.sendEmptyMessage(command);
2049 }
2050
2051 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002052 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002053 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002054 */
2055 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002056 sendRequestAsync(command, argument, null, null);
2057 }
2058
2059 /**
2060 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2061 * @see {@link #sendRequest(int,Object)}
2062 */
2063 private void sendRequestAsync(
2064 int command, Object argument, Phone phone, WorkSource workSource) {
2065 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002066 Message msg = mMainThreadHandler.obtainMessage(command, request);
2067 msg.sendToTarget();
2068 }
2069
2070 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 * Initialize the singleton PhoneInterfaceManager instance.
2072 * This is only done once, at startup, from PhoneApp.onCreate().
2073 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002074 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002075 synchronized (PhoneInterfaceManager.class) {
2076 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002077 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002078 } else {
2079 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2080 }
2081 return sInstance;
2082 }
2083 }
2084
2085 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002086 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002088 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002089 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002090 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002091 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2092 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002093 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002094 mTelephonySharedPreferences =
2095 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002096 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002097 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002098 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 publish();
2101 }
2102
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002103 private Phone getDefaultPhone() {
2104 Phone thePhone = getPhone(getDefaultSubscription());
2105 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2106 }
2107
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002108 private void publish() {
2109 if (DBG) log("publish: " + this);
2110
Peter Wangc035ce42020-01-08 21:00:22 -08002111 TelephonyFrameworkInitializer
2112 .getTelephonyServiceManager()
2113 .getTelephonyServiceRegisterer()
2114 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 }
2116
Stuart Scott584921c2015-01-15 17:10:34 -08002117 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002118 if (request.phone != null) {
2119 return request.phone;
2120 } else {
2121 return getPhoneFromSubId(request.subId);
2122 }
2123 }
2124
2125 private Phone getPhoneFromSubId(int subId) {
2126 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2127 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002128 }
2129
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002130 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2131 Phone phone = getPhoneFromRequest(request);
2132 return phone == null ? null :
2133 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2134 }
2135
Wink Saville36469e72014-06-11 15:17:00 -07002136 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002137 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002138 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002139 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002140
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002141 private void sendEraseModemConfig(Phone phone) {
2142 if (phone != null) {
2143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2144 mApp, phone.getSubId(), "eraseModemConfig");
2145 final long identity = Binder.clearCallingIdentity();
2146 try {
2147 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2148 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2149 } finally {
2150 Binder.restoreCallingIdentity(identity);
2151 }
2152 }
2153 }
2154
Peter Wang050bb052020-01-13 23:33:09 -08002155 private boolean isImsAvailableOnDevice() {
2156 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2157 if (pm == null) {
2158 // For some reason package manger is not available.. This will fail internally anyway,
2159 // so do not throw error and allow.
2160 return true;
2161 }
2162 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2163 }
2164
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002166 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002167 }
2168
Wink Savilleb564aae2014-10-23 10:18:09 -07002169 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002170 if (DBG) log("dial: " + number);
2171 // No permission check needed here: This is just a wrapper around the
2172 // ACTION_DIAL intent, which is available to any app since it puts up
2173 // the UI before it does anything.
2174
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 String url = createTelUrl(number);
2178 if (url == null) {
2179 return;
2180 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002181
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182 // PENDING: should we just silently fail if phone is offhook or ringing?
2183 PhoneConstants.State state = mCM.getState(subId);
2184 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2185 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2186 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2187 mApp.startActivity(intent);
2188 }
2189 } finally {
2190 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002191 }
2192 }
2193
2194 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002195 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002196 }
2197
Wink Savilleb564aae2014-10-23 10:18:09 -07002198 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002199 if (DBG) log("call: " + number);
2200
2201 // This is just a wrapper around the ACTION_CALL intent, but we still
2202 // need to do a permission check since we're calling startActivity()
2203 // from the context of the phone app.
2204 enforceCallPermission();
2205
Jordan Liu1617b712019-07-10 15:06:26 -07002206 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002207 != AppOpsManager.MODE_ALLOWED) {
2208 return;
2209 }
2210
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211 final long identity = Binder.clearCallingIdentity();
2212 try {
2213 String url = createTelUrl(number);
2214 if (url == null) {
2215 return;
2216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218 boolean isValid = false;
2219 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2220 if (slist != null) {
2221 for (SubscriptionInfo subInfoRecord : slist) {
2222 if (subInfoRecord.getSubscriptionId() == subId) {
2223 isValid = true;
2224 break;
2225 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002226 }
Wink Saville08874612014-08-31 19:19:58 -07002227 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 if (!isValid) {
2229 return;
2230 }
Wink Saville08874612014-08-31 19:19:58 -07002231
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002232 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2233 intent.putExtra(SUBSCRIPTION_KEY, subId);
2234 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2235 mApp.startActivity(intent);
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 }
2240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002242 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002243 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2244 }
2245
Wink Savilleb564aae2014-10-23 10:18:09 -07002246 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002247 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002248 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2249 }
2250
Wink Savilleb564aae2014-10-23 10:18:09 -07002251 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002253
2254 final long identity = Binder.clearCallingIdentity();
2255 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002256 Phone phone = getPhone(subId);
2257 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 checkSimPin.start();
2259 return checkSimPin.unlockSim(null, pin);
2260 } finally {
2261 Binder.restoreCallingIdentity(identity);
2262 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002263 }
2264
Wink Savilleb564aae2014-10-23 10:18:09 -07002265 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002267
2268 final long identity = Binder.clearCallingIdentity();
2269 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002270 Phone phone = getPhone(subId);
2271 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002272 checkSimPuk.start();
2273 return checkSimPuk.unlockSim(puk, pin);
2274 } finally {
2275 Binder.restoreCallingIdentity(identity);
2276 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 }
2278
2279 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002280 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002281 * a synchronous one.
2282 */
2283 private static class UnlockSim extends Thread {
2284
2285 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002286 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287
2288 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002289 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2290 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002291
2292 // For replies from SimCard interface
2293 private Handler mHandler;
2294
2295 // For async handler to identify request type
2296 private static final int SUPPLY_PIN_COMPLETE = 100;
2297
Michele Berionned9fbae52020-11-13 02:36:59 +00002298 UnlockSim(int phoneId, IccCard simCard) {
2299 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002300 mSimCard = simCard;
2301 }
2302
2303 @Override
2304 public void run() {
2305 Looper.prepare();
2306 synchronized (UnlockSim.this) {
2307 mHandler = new Handler() {
2308 @Override
2309 public void handleMessage(Message msg) {
2310 AsyncResult ar = (AsyncResult) msg.obj;
2311 switch (msg.what) {
2312 case SUPPLY_PIN_COMPLETE:
2313 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2314 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002315 mRetryCount = msg.arg1;
2316 if (ar.exception != null) {
2317 if (ar.exception instanceof CommandException &&
2318 ((CommandException)(ar.exception)).getCommandError()
2319 == CommandException.Error.PASSWORD_INCORRECT) {
2320 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002321 } //When UiccCardApp dispose,handle message and return exception
2322 else if (ar.exception instanceof CommandException &&
2323 ((CommandException) (ar.exception)).getCommandError()
2324 == CommandException.Error.ABORTED) {
2325 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002326 } else {
2327 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2328 }
2329 } else {
2330 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2331 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002332 mDone = true;
2333 UnlockSim.this.notifyAll();
2334 }
2335 break;
2336 }
2337 }
2338 };
2339 UnlockSim.this.notifyAll();
2340 }
2341 Looper.loop();
2342 }
2343
2344 /*
2345 * Use PIN or PUK to unlock SIM card
2346 *
2347 * If PUK is null, unlock SIM card with PIN
2348 *
2349 * If PUK is not null, unlock SIM card with PUK and set PIN code
2350 */
Wink Saville9de0f752013-10-22 19:04:03 -07002351 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002352
2353 while (mHandler == null) {
2354 try {
2355 wait();
2356 } catch (InterruptedException e) {
2357 Thread.currentThread().interrupt();
2358 }
2359 }
2360 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2361
2362 if (puk == null) {
2363 mSimCard.supplyPin(pin, callback);
2364 } else {
2365 mSimCard.supplyPuk(puk, pin, callback);
2366 }
2367
2368 while (!mDone) {
2369 try {
2370 Log.d(LOG_TAG, "wait for done");
2371 wait();
2372 } catch (InterruptedException e) {
2373 // Restore the interrupted status
2374 Thread.currentThread().interrupt();
2375 }
2376 }
2377 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002378 int[] resultArray = new int[2];
2379 resultArray[0] = mResult;
2380 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002381
2382 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2383 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2384 }
2385
Wink Saville9de0f752013-10-22 19:04:03 -07002386 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
2388 }
2389
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002390 /**
2391 * This method has been removed due to privacy and stability concerns.
2392 */
2393 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002394 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002395 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2396 return;
Wink Saville36469e72014-06-11 15:17:00 -07002397 }
2398
Nathan Harold1f889d82020-06-04 17:05:26 -07002399 @Override
2400 public void updateServiceLocationWithPackageName(String callingPackage) {
2401 mApp.getSystemService(AppOpsManager.class)
2402 .checkPackage(Binder.getCallingUid(), callingPackage);
2403
Nathan Haroldf096d982020-11-18 17:18:06 -08002404 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002405 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2406 // Callers targeting S have no business invoking this method.
2407 return;
2408 }
2409
2410 LocationAccessPolicy.LocationPermissionResult locationResult =
2411 LocationAccessPolicy.checkLocationPermission(mApp,
2412 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2413 .setCallingPackage(callingPackage)
2414 .setCallingFeatureId(null)
2415 .setCallingPid(Binder.getCallingPid())
2416 .setCallingUid(Binder.getCallingUid())
2417 .setMethod("updateServiceLocation")
2418 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2419 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2420 .build());
2421 // Apps that lack location permission have no business calling this method;
2422 // however, because no permission was declared in the public API, denials must
2423 // all be "soft".
2424 switch (locationResult) {
2425 case DENIED_HARD: /* fall through */
2426 case DENIED_SOFT:
2427 return;
2428 }
2429
2430 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002431 final long identity = Binder.clearCallingIdentity();
2432 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002433 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002435 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002436 }
2437 } finally {
2438 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002439 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002440 }
2441
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002442 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002443 @Override
2444 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002445 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002448
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002449 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002450 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2451 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2452 callingFeatureId);
2453 }
2454
2455 @Deprecated
2456 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002457 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002458 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2459 }
2460
2461 @Override
2462 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2463 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002464 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002465 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002466 return false;
2467 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002468
2469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 return isRadioOnForSubscriber(subId);
2472 } finally {
2473 Binder.restoreCallingIdentity(identity);
2474 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002475 }
2476
2477 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 final long identity = Binder.clearCallingIdentity();
2479 try {
2480 final Phone phone = getPhone(subId);
2481 if (phone != null) {
2482 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2483 } else {
2484 return false;
2485 }
2486 } finally {
2487 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
2490
2491 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002492 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002493 }
Wink Saville36469e72014-06-11 15:17:00 -07002494
Wink Savilleb564aae2014-10-23 10:18:09 -07002495 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002496 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002497
2498 final long identity = Binder.clearCallingIdentity();
2499 try {
2500 final Phone phone = getPhone(subId);
2501 if (phone != null) {
2502 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2503 }
2504 } finally {
2505 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002506 }
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
2509 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002510 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002511 }
2512
Wink Savilleb564aae2014-10-23 10:18:09 -07002513 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002514 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002515
2516 final long identity = Binder.clearCallingIdentity();
2517 try {
2518 final Phone phone = getPhone(subId);
2519 if (phone == null) {
2520 return false;
2521 }
2522 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2523 toggleRadioOnOffForSubscriber(subId);
2524 }
2525 return true;
2526 } finally {
2527 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002528 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002529 }
Wink Saville36469e72014-06-11 15:17:00 -07002530
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002531 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002532 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002533 /*
2534 * If any of the Radios are available, it will need to be
2535 * shutdown. So return true if any Radio is available.
2536 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002537 final long identity = Binder.clearCallingIdentity();
2538 try {
2539 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2540 Phone phone = PhoneFactory.getPhone(i);
2541 if (phone != null && phone.isRadioAvailable()) return true;
2542 }
2543 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2544 return false;
2545 } finally {
2546 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002548 }
2549
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002550 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002551 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002552 enforceModifyPermission();
2553
2554 final long identity = Binder.clearCallingIdentity();
2555 try {
2556 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2557 logv("Shutting down Phone " + i);
2558 shutdownRadioUsingPhoneId(i);
2559 }
2560 } finally {
2561 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 }
2563 }
2564
2565 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002566 Phone phone = PhoneFactory.getPhone(phoneId);
2567 if (phone != null && phone.isRadioAvailable()) {
2568 phone.shutdownRadio();
2569 }
2570 }
2571
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002572 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002573 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002574
2575 final long identity = Binder.clearCallingIdentity();
2576 try {
2577 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2578 if (defaultPhone != null) {
2579 defaultPhone.setRadioPower(turnOn);
2580 return true;
2581 } else {
2582 loge("There's no default phone.");
2583 return false;
2584 }
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002587 }
Wink Saville36469e72014-06-11 15:17:00 -07002588 }
2589
Wink Savilleb564aae2014-10-23 10:18:09 -07002590 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002591 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002592
2593 final long identity = Binder.clearCallingIdentity();
2594 try {
2595 final Phone phone = getPhone(subId);
2596 if (phone != null) {
2597 phone.setRadioPower(turnOn);
2598 return true;
2599 } else {
2600 return false;
2601 }
2602 } finally {
2603 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 }
2606
Wink Saville36469e72014-06-11 15:17:00 -07002607 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 public boolean enableDataConnectivity() {
2610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611
2612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 int subId = mSubscriptionController.getDefaultDataSubId();
2615 final Phone phone = getPhone(subId);
2616 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002617 phone.getDataEnabledSettings().setDataEnabled(
2618 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002619 return true;
2620 } else {
2621 return false;
2622 }
2623 } finally {
2624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 }
2627
Wink Saville36469e72014-06-11 15:17:00 -07002628 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002629 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002630 public boolean disableDataConnectivity() {
2631 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 int subId = mSubscriptionController.getDefaultDataSubId();
2636 final Phone phone = getPhone(subId);
2637 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002638 phone.getDataEnabledSettings().setDataEnabled(
2639 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002640 return true;
2641 } else {
2642 return false;
2643 }
2644 } finally {
2645 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002646 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002647 }
2648
Sanket Padawe356d7632015-06-22 14:03:32 -07002649 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002650 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002651 final long identity = Binder.clearCallingIdentity();
2652 try {
2653 final Phone phone = getPhone(subId);
2654 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002655 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002656 } else {
2657 return false;
2658 }
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002661 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002662 }
2663
2664 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002665 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002666 }
2667
pkanwarae03a6b2016-11-06 20:37:09 -08002668 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002669 enforceCallPermission();
2670
2671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2674 return;
2675 }
2676 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2677 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2678 } finally {
2679 Binder.restoreCallingIdentity(identity);
2680 }
pkanwar32d516d2016-10-14 19:37:38 -07002681 };
2682
Wink Savilleb564aae2014-10-23 10:18:09 -07002683 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002684 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002685
2686 final long identity = Binder.clearCallingIdentity();
2687 try {
2688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2689 return false;
2690 }
2691 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002694 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002698 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002699 }
2700
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002701 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002702 final long identity = Binder.clearCallingIdentity();
2703 try {
2704 Phone phone = PhoneFactory.getPhone(slotIndex);
2705 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2706 PhoneConstantConversions.convertCallState(phone.getState());
2707 } finally {
2708 Binder.restoreCallingIdentity(identity);
2709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002710 }
2711
Sanket Padawe356d7632015-06-22 14:03:32 -07002712 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002713 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002714 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2715 }
2716
2717 @Override
2718 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002719 final long identity = Binder.clearCallingIdentity();
2720 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002721 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002722 if (phone != null) {
2723 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2724 } else {
2725 return PhoneConstantConversions.convertDataState(
2726 PhoneConstants.DataState.DISCONNECTED);
2727 }
2728 } finally {
2729 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002730 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
Sanket Padawe356d7632015-06-22 14:03:32 -07002733 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002734 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002735 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2736 }
2737
2738 @Override
2739 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002740 final long identity = Binder.clearCallingIdentity();
2741 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002742 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002743 if (phone != null) {
2744 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2745 } else {
2746 return TelephonyManager.DATA_ACTIVITY_NONE;
2747 }
2748 } finally {
2749 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
2753 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002754 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002755 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002756 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002757
2758 LocationAccessPolicy.LocationPermissionResult locationResult =
2759 LocationAccessPolicy.checkLocationPermission(mApp,
2760 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2761 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002762 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002763 .setCallingPid(Binder.getCallingPid())
2764 .setCallingUid(Binder.getCallingUid())
2765 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002766 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002767 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2768 .build());
2769 switch (locationResult) {
2770 case DENIED_HARD:
2771 throw new SecurityException("Not allowed to access cell location");
2772 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002773 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2774 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002775 }
2776
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002777 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002778 final long identity = Binder.clearCallingIdentity();
2779 try {
2780 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002781 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002782 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002783 } finally {
2784 Binder.restoreCallingIdentity(identity);
2785 }
Svetoslav64fad262015-04-14 14:35:21 -07002786 }
2787
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002788 @Override
Jack Yu01425032020-02-22 19:38:58 -08002789 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002790 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2791 // registered cell info, so return a NULL country instead.
2792 final long identity = Binder.clearCallingIdentity();
2793 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002794 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2795 // Get default phone in this case.
2796 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2797 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002798 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002799 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002800 if (phone == null) return "";
2801 ServiceStateTracker sst = phone.getServiceStateTracker();
2802 if (sst == null) return "";
2803 LocaleTracker lt = sst.getLocaleTracker();
2804 if (lt == null) return "";
2805 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2806 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2807 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002808 } finally {
2809 Binder.restoreCallingIdentity(identity);
2810 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002811 }
2812
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002813 /**
2814 * This method was removed due to potential issues caused by performing partial
2815 * updates of service state, and lack of a credible use case.
2816 *
2817 * This has the ability to break the telephony implementation by disabling notification of
2818 * changes in device connectivity. DO NOT USE THIS!
2819 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002820 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002821 public void enableLocationUpdates() {
2822 mApp.enforceCallingOrSelfPermission(
2823 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002826 /**
2827 * This method was removed due to potential issues caused by performing partial
2828 * updates of service state, and lack of a credible use case.
2829 *
2830 * This has the ability to break the telephony implementation by disabling notification of
2831 * changes in device connectivity. DO NOT USE THIS!
2832 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 @Override
2834 public void disableLocationUpdates() {
2835 mApp.enforceCallingOrSelfPermission(
2836 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002837 }
2838
2839 @Override
2840 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002841 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2842 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002843 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002844 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2845 throw new SecurityException(
2846 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2847 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002848
Jordan Liu1617b712019-07-10 15:06:26 -07002849 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002850 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2851 return null;
2852 }
Svetoslav64fad262015-04-14 14:35:21 -07002853
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002854 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002855
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002856 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002857 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002858
Nathan Haroldf180aac2018-06-01 18:43:55 -07002859 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2860 for (CellInfo ci : info) {
2861 if (ci instanceof CellInfoGsm) {
2862 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2863 } else if (ci instanceof CellInfoWcdma) {
2864 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002867 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002868 }
2869
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002870 private List<CellInfo> getCachedCellInfo() {
2871 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2872 for (Phone phone : PhoneFactory.getPhones()) {
2873 List<CellInfo> info = phone.getAllCellInfo();
2874 if (info != null) cellInfos.addAll(info);
2875 }
2876 return cellInfos;
2877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878
2879 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002880 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002881 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002882 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002883
2884 LocationAccessPolicy.LocationPermissionResult locationResult =
2885 LocationAccessPolicy.checkLocationPermission(mApp,
2886 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2887 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002888 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002889 .setCallingPid(Binder.getCallingPid())
2890 .setCallingUid(Binder.getCallingUid())
2891 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002892 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002893 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2894 .build());
2895 switch (locationResult) {
2896 case DENIED_HARD:
2897 throw new SecurityException("Not allowed to access cell info");
2898 case DENIED_SOFT:
2899 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002900 }
2901
Nathan Haroldf096d982020-11-18 17:18:06 -08002902 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002903 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2904 return getCachedCellInfo();
2905 }
2906
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002907 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002908 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 final long identity = Binder.clearCallingIdentity();
2910 try {
2911 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2912 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002913 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002914 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002915 if (info != null) cellInfos.addAll(info);
2916 }
2917 return cellInfos;
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002920 }
2921 }
2922
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002923 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002924 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2925 String callingFeatureId) {
2926 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2927 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002928 }
2929
2930 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002931 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2932 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002933 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002934 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002935 }
2936
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002937 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2938 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002939 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002940 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002941
2942 LocationAccessPolicy.LocationPermissionResult locationResult =
2943 LocationAccessPolicy.checkLocationPermission(mApp,
2944 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2945 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002946 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002947 .setCallingPid(Binder.getCallingPid())
2948 .setCallingUid(Binder.getCallingUid())
2949 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002950 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2951 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002952 .build());
2953 switch (locationResult) {
2954 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002955 if (TelephonyPermissions
2956 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002957 // Safetynet logging for b/154934934
2958 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2959 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002960 throw new SecurityException("Not allowed to access cell info");
2961 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002962 if (TelephonyPermissions
2963 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002964 // Safetynet logging for b/154934934
2965 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2966 }
Nathan Harold5320c422019-05-09 10:26:08 -07002967 try {
2968 cb.onCellInfo(new ArrayList<CellInfo>());
2969 } catch (RemoteException re) {
2970 // Drop without consequences
2971 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002972 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002973 }
2974
Nathan Harolda939a962019-05-09 10:13:47 -07002975
2976 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002977 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2978
2979 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2980 }
2981
2982 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002983 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002984 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002985 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986
2987 final long identity = Binder.clearCallingIdentity();
2988 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002989 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002990 } finally {
2991 Binder.restoreCallingIdentity(identity);
2992 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002993 }
2994
Shishir Agrawala9f32182016-04-12 12:00:16 -07002995 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002996 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002997 Phone phone = PhoneFactory.getPhone(slotIndex);
2998 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002999 return null;
3000 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003001 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003002 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003003 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003004 return null;
3005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003006
3007 final long identity = Binder.clearCallingIdentity();
3008 try {
3009 return phone.getImei();
3010 } finally {
3011 Binder.restoreCallingIdentity(identity);
3012 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003013 }
3014
3015 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003016 public String getTypeAllocationCodeForSlot(int slotIndex) {
3017 Phone phone = PhoneFactory.getPhone(slotIndex);
3018 String tac = null;
3019 if (phone != null) {
3020 String imei = phone.getImei();
3021 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3022 }
3023 return tac;
3024 }
3025
3026 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003027 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003028 Phone phone = PhoneFactory.getPhone(slotIndex);
3029 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003030 return null;
3031 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003032
Jeff Davidson913390f2018-02-23 17:11:49 -08003033 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003034 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003035 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003036 return null;
3037 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038
3039 final long identity = Binder.clearCallingIdentity();
3040 try {
3041 return phone.getMeid();
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
Jack Yu2af8d712017-03-15 17:14:14 -07003045 }
3046
3047 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003048 public String getManufacturerCodeForSlot(int slotIndex) {
3049 Phone phone = PhoneFactory.getPhone(slotIndex);
3050 String manufacturerCode = null;
3051 if (phone != null) {
3052 String meid = phone.getMeid();
3053 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3054 }
3055 return manufacturerCode;
3056 }
3057
3058 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003059 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3060 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003061 Phone phone = PhoneFactory.getPhone(slotIndex);
3062 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003063 return null;
3064 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003065 int subId = phone.getSubId();
3066 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003067 mApp, subId, callingPackage, callingFeatureId,
3068 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003069 return null;
3070 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003071
3072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 return phone.getDeviceSvn();
3075 } finally {
3076 Binder.restoreCallingIdentity(identity);
3077 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003078 }
3079
fionaxu43304da2017-11-27 22:51:16 -08003080 @Override
3081 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003082 final long identity = Binder.clearCallingIdentity();
3083 try {
3084 final Phone phone = getPhone(subId);
3085 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
3088 }
fionaxu43304da2017-11-27 22:51:16 -08003089 }
3090
3091 @Override
3092 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003093 final long identity = Binder.clearCallingIdentity();
3094 try {
3095 final Phone phone = getPhone(subId);
3096 return phone == null ? null : phone.getCarrierName();
3097 } finally {
3098 Binder.restoreCallingIdentity(identity);
3099 }
fionaxu43304da2017-11-27 22:51:16 -08003100 }
3101
calvinpanffe225e2018-11-01 19:43:06 +08003102 @Override
chen xu0026ca62019-03-06 15:28:50 -08003103 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003108 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003109 } finally {
3110 Binder.restoreCallingIdentity(identity);
3111 }
3112 }
3113
3114 @Override
chen xu0026ca62019-03-06 15:28:50 -08003115 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003116 final long identity = Binder.clearCallingIdentity();
3117 try {
3118 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003119 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003120 } finally {
3121 Binder.restoreCallingIdentity(identity);
3122 }
3123 }
3124
chen xu651eec72018-11-11 19:03:44 -08003125 @Override
chen xu864e11c2018-12-06 22:10:03 -08003126 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3127 if (!isSubscriptionMccMnc) {
3128 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3129 }
chen xu651eec72018-11-11 19:03:44 -08003130 final Phone phone = PhoneFactory.getPhone(slotIndex);
3131 if (phone == null) {
3132 return TelephonyManager.UNKNOWN_CARRIER_ID;
3133 }
3134 final long identity = Binder.clearCallingIdentity();
3135 try {
3136 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
3139 }
3140 }
3141
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003142 //
3143 // Internal helper methods.
3144 //
3145
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003146 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003147 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3148 *
3149 * @throws SecurityException if the caller does not have the required permission
3150 */
3151 private void enforceModifyPermission() {
3152 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3153 }
3154
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003155 /**
3156 * Make sure the caller is system.
3157 *
3158 * @throws SecurityException if the caller is not system.
3159 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003160 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003161 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3162 throw new SecurityException("Caller must be system");
3163 }
3164 }
3165
Shuo Qianf2b2df42019-11-13 17:43:31 -08003166 private void enforceActiveEmergencySessionPermission() {
3167 mApp.enforceCallingOrSelfPermission(
3168 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3169 }
3170
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003171 /**
3172 * Make sure the caller has the CALL_PHONE permission.
3173 *
3174 * @throws SecurityException if the caller does not have the required permission
3175 */
3176 private void enforceCallPermission() {
3177 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3178 }
3179
paulhu423b5f22019-08-23 19:17:33 +08003180 private void enforceSettingsPermission() {
3181 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003182 }
3183
Michele Berionned9fbae52020-11-13 02:36:59 +00003184 private void enforceRebootPermission() {
3185 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3186 }
3187
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003188 private String createTelUrl(String number) {
3189 if (TextUtils.isEmpty(number)) {
3190 return null;
3191 }
3192
Jake Hambye994d462014-02-03 13:10:13 -08003193 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003194 }
3195
Ihab Awadf9e92732013-12-05 18:02:52 -08003196 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003197 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3198 }
3199
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003200 private static void logv(String msg) {
3201 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3202 }
3203
Ihab Awadf9e92732013-12-05 18:02:52 -08003204 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3206 }
3207
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003208 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003210 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003211 }
3212
Sanket Padawe356d7632015-06-22 14:03:32 -07003213 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003214 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003215 final long identity = Binder.clearCallingIdentity();
3216 try {
3217 final Phone phone = PhoneFactory.getPhone(slotIndex);
3218 if (phone == null) {
3219 return PhoneConstants.PHONE_TYPE_NONE;
3220 } else {
3221 return phone.getPhoneType();
3222 }
3223 } finally {
3224 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003225 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003226 }
3227
3228 /**
3229 * Returns the CDMA ERI icon index to display
3230 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003231 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003232 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3233 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3234 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003235 }
3236
Sanket Padawe356d7632015-06-22 14:03:32 -07003237 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003238 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3239 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003240 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003241 mApp, subId, callingPackage, callingFeatureId,
3242 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003243 return -1;
3244 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003245
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 final Phone phone = getPhone(subId);
3249 if (phone != null) {
3250 return phone.getCdmaEriIconIndex();
3251 } else {
3252 return -1;
3253 }
3254 } finally {
3255 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003256 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003257 }
3258
3259 /**
3260 * Returns the CDMA ERI icon mode,
3261 * 0 - ON
3262 * 1 - FLASHING
3263 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003264 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003265 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3266 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3267 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003268 }
3269
Sanket Padawe356d7632015-06-22 14:03:32 -07003270 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003271 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3272 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003273 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003274 mApp, subId, callingPackage, callingFeatureId,
3275 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003276 return -1;
3277 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003278
3279 final long identity = Binder.clearCallingIdentity();
3280 try {
3281 final Phone phone = getPhone(subId);
3282 if (phone != null) {
3283 return phone.getCdmaEriIconMode();
3284 } else {
3285 return -1;
3286 }
3287 } finally {
3288 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003289 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003290 }
3291
3292 /**
3293 * Returns the CDMA ERI text,
3294 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3297 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3298 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003299 }
3300
Sanket Padawe356d7632015-06-22 14:03:32 -07003301 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003302 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3303 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003304 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003305 mApp, subId, callingPackage, callingFeatureId,
3306 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003307 return null;
3308 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003309
3310 final long identity = Binder.clearCallingIdentity();
3311 try {
3312 final Phone phone = getPhone(subId);
3313 if (phone != null) {
3314 return phone.getCdmaEriText();
3315 } else {
3316 return null;
3317 }
3318 } finally {
3319 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003320 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003321 }
3322
3323 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003324 * Returns the CDMA MDN.
3325 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003326 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003327 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003328 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3329 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 return phone.getLine1Number();
3336 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003337 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003338 return null;
3339 }
3340 } finally {
3341 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003342 }
3343 }
3344
3345 /**
3346 * Returns the CDMA MIN.
3347 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003348 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003349 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3351 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003352
3353 final long identity = Binder.clearCallingIdentity();
3354 try {
3355 final Phone phone = getPhone(subId);
3356 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3357 return phone.getCdmaMin();
3358 } else {
3359 return null;
3360 }
3361 } finally {
3362 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003363 }
3364 }
3365
Hall Liud892bec2018-11-30 14:51:45 -08003366 @Override
3367 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3368 INumberVerificationCallback callback, String callingPackage) {
3369 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3370 != PERMISSION_GRANTED) {
3371 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3372 }
3373 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3374
3375 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3376 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003377 throw new SecurityException("Calling package must be configured in the device config: "
3378 + "calling package: " + callingPackage
3379 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003380 }
3381
3382 if (range == null) {
3383 throw new NullPointerException("Range must be non-null");
3384 }
3385
3386 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003387 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003388
3389 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3390 }
3391
Junda Liuca05d5d2014-08-14 22:36:34 -07003392 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003393 * Returns true if CDMA provisioning needs to run.
3394 */
3395 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003396 final long identity = Binder.clearCallingIdentity();
3397 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003398 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003399 } finally {
3400 Binder.restoreCallingIdentity(identity);
3401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003402 }
3403
3404 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003405 * Sets the voice mail number of a given subId.
3406 */
3407 @Override
3408 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003409 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3410 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003411
3412 final long identity = Binder.clearCallingIdentity();
3413 try {
3414 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3415 new Pair<String, String>(alphaTag, number), new Integer(subId));
3416 return success;
3417 } finally {
3418 Binder.restoreCallingIdentity(identity);
3419 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003420 }
3421
Ta-wei Yen87c49842016-05-13 21:19:52 -07003422 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003423 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3424 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003425 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3426 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003427 if (!TextUtils.equals(callingPackage, systemDialer)) {
3428 throw new SecurityException("caller must be system dialer");
3429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003430
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3434 if (phoneAccountHandle == null) {
3435 return null;
3436 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003437 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003438 } finally {
3439 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003440 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003441 }
3442
3443 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003444 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3445 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003446 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003448 mApp, subId, callingPackage, callingFeatureId,
3449 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003450 return null;
3451 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003452
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003453 final long identity = Binder.clearCallingIdentity();
3454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003455 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003456 } finally {
3457 Binder.restoreCallingIdentity(identity);
3458 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003459 }
3460
3461 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003462 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3463 VisualVoicemailSmsFilterSettings settings) {
3464 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003465
3466 final long identity = Binder.clearCallingIdentity();
3467 try {
3468 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003469 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003470 } finally {
3471 Binder.restoreCallingIdentity(identity);
3472 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003473 }
3474
3475 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003476 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003478
3479 final long identity = Binder.clearCallingIdentity();
3480 try {
3481 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003482 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003483 } finally {
3484 Binder.restoreCallingIdentity(identity);
3485 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003486 }
3487
3488 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003489 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3490 String callingPackage, int subId) {
3491 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003492
3493 final long identity = Binder.clearCallingIdentity();
3494 try {
3495 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003496 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003497 } finally {
3498 Binder.restoreCallingIdentity(identity);
3499 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003500 }
3501
3502 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003503 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003504 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003505
3506 final long identity = Binder.clearCallingIdentity();
3507 try {
3508 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003510 } finally {
3511 Binder.restoreCallingIdentity(identity);
3512 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003513 }
3514
3515 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003516 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3517 String callingAttributionTag, int subId, String number, int port, String text,
3518 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003519 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003520 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003521 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003522 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003523 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3524 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003525 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003526
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003527 /**
fionaxu0152e512016-11-14 13:36:14 -08003528 * Sets the voice activation state of a given subId.
3529 */
3530 @Override
3531 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3533 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003534
3535 final long identity = Binder.clearCallingIdentity();
3536 try {
3537 final Phone phone = getPhone(subId);
3538 if (phone != null) {
3539 phone.setVoiceActivationState(activationState);
3540 } else {
3541 loge("setVoiceActivationState fails with invalid subId: " + subId);
3542 }
3543 } finally {
3544 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003545 }
3546 }
3547
3548 /**
3549 * Sets the data activation state of a given subId.
3550 */
3551 @Override
3552 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3554 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003555
3556 final long identity = Binder.clearCallingIdentity();
3557 try {
3558 final Phone phone = getPhone(subId);
3559 if (phone != null) {
3560 phone.setDataActivationState(activationState);
3561 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003562 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003563 }
3564 } finally {
3565 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003566 }
3567 }
3568
3569 /**
3570 * Returns the voice activation state of a given subId.
3571 */
3572 @Override
3573 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003575
fionaxu0152e512016-11-14 13:36:14 -08003576 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003577 final long identity = Binder.clearCallingIdentity();
3578 try {
3579 if (phone != null) {
3580 return phone.getVoiceActivationState();
3581 } else {
3582 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3583 }
3584 } finally {
3585 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003586 }
3587 }
3588
3589 /**
3590 * Returns the data activation state of a given subId.
3591 */
3592 @Override
3593 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003594 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003595
fionaxu0152e512016-11-14 13:36:14 -08003596 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003597 final long identity = Binder.clearCallingIdentity();
3598 try {
3599 if (phone != null) {
3600 return phone.getDataActivationState();
3601 } else {
3602 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3603 }
3604 } finally {
3605 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003606 }
3607 }
3608
3609 /**
Wink Saville36469e72014-06-11 15:17:00 -07003610 * Returns the unread count of voicemails for a subId
3611 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003612 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003613 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3614 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003616 mApp, subId, callingPackage, callingFeatureId,
3617 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003618 return 0;
3619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003620 final long identity = Binder.clearCallingIdentity();
3621 try {
3622 final Phone phone = getPhone(subId);
3623 if (phone != null) {
3624 return phone.getVoiceMessageCount();
3625 } else {
3626 return 0;
3627 }
3628 } finally {
3629 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003630 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003631 }
3632
3633 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003634 * returns true, if the device is in a state where both voice and data
3635 * are supported simultaneously. This can change based on location or network condition.
3636 */
3637 @Override
3638 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 final Phone phone = getPhone(subId);
3642 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3643 } finally {
3644 Binder.restoreCallingIdentity(identity);
3645 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003646 }
3647
3648 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003649 * Send the dialer code if called from the current default dialer or the caller has
3650 * carrier privilege.
3651 * @param inputCode The dialer code to send
3652 */
3653 @Override
3654 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003655 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003656 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003657 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3658 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003659 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003660 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003661 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003662 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663
3664 final long identity = Binder.clearCallingIdentity();
3665 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003666 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003667 } finally {
3668 Binder.restoreCallingIdentity(identity);
3669 }
fionaxu235cc5e2017-03-06 22:25:57 -08003670 }
3671
Pengquan Menga1bb6272018-09-06 09:59:22 -07003672 @Override
3673 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003674 TelephonyPermissions
3675 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3676 mApp, subId, "getNetworkSelectionMode");
3677 final long identity = Binder.clearCallingIdentity();
3678 try {
3679 if (!isActiveSubscription(subId)) {
3680 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3681 }
3682 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3683 } finally {
3684 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003685 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003686 }
3687
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003689 public boolean isInEmergencySmsMode() {
3690 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 for (Phone phone : PhoneFactory.getPhones()) {
3694 if (phone.isInEmergencySmsMode()) {
3695 return true;
3696 }
3697 }
3698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 return false;
3702 }
3703
shilu366312e2019-12-17 09:28:10 -08003704 /**
3705 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3706 * @param subId The subscription to use to check the configuration.
3707 * @param c The callback that will be used to send the result.
3708 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003709 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003710 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3711 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003712 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3713 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003714
Brad Ebinger77b832e2019-10-17 17:03:22 -07003715 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3717 "IMS not available on device.");
3718 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 final long token = Binder.clearCallingIdentity();
3720 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003721 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003722 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003724 } catch (ImsException e) {
3725 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 } finally {
3727 Binder.restoreCallingIdentity(token);
3728 }
3729 }
3730
shilu366312e2019-12-17 09:28:10 -08003731 /**
3732 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3733 * @param subId The subscription to use to check the configuration.
3734 * @param c The callback that will be used to send the result.
3735 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003737 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003738 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3739 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003740 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3741 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3742 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003743 final long token = Binder.clearCallingIdentity();
3744 try {
3745 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3746 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3747 .removeRegistrationCallbackForSubscription(c, subId);
3748 } catch (ImsException e) {
3749 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3750 + "is inactive, ignoring unregister.");
3751 // If the subscription is no longer active, just return, since the callback
3752 // will already have been removed internally.
3753 } finally {
3754 Binder.restoreCallingIdentity(token);
3755 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 }
3757
Brad Ebinger774ba362019-10-22 17:36:18 -07003758 /**
3759 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3760 */
3761 @Override
3762 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3763 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3764 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3765 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3766 "IMS not available on device.");
3767 }
3768 final long token = Binder.clearCallingIdentity();
3769 try {
3770 Phone phone = getPhone(subId);
3771 if (phone == null) {
3772 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3773 + subId + "'");
3774 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3775 }
3776 phone.getImsRegistrationState(regState -> {
3777 try {
3778 consumer.accept((regState == null)
3779 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3780 } catch (RemoteException e) {
3781 // Ignore if the remote process is no longer available to call back.
3782 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3783 }
3784 });
3785 } finally {
3786 Binder.restoreCallingIdentity(token);
3787 }
3788 }
3789
3790 /**
3791 * Get the transport type for the IMS service registration state.
3792 */
3793 @Override
3794 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003795 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3796 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003797 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3798 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3799 "IMS not available on device.");
3800 }
3801 final long token = Binder.clearCallingIdentity();
3802 try {
3803 Phone phone = getPhone(subId);
3804 if (phone == null) {
3805 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3806 + subId + "'");
3807 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3808 }
3809 phone.getImsRegistrationTech(regTech -> {
3810 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3811 int regTechConverted = (regTech == null)
3812 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3813 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3814 regTechConverted);
3815 try {
3816 consumer.accept(regTechConverted);
3817 } catch (RemoteException e) {
3818 // Ignore if the remote process is no longer available to call back.
3819 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3820 }
3821 });
3822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
3825 }
3826
shilu366312e2019-12-17 09:28:10 -08003827 /**
3828 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3829 * @param subId The subscription to use to check the configuration.
3830 * @param c The callback that will be used to send the result.
3831 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003832 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003833 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3834 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003835 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3836 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003837 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3838 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3839 "IMS not available on device.");
3840 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3842 final long token = Binder.clearCallingIdentity();
3843 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003844 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003845 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003846 } catch (ImsException e) {
3847 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003848 } finally {
3849 Binder.restoreCallingIdentity(token);
3850 }
3851 }
3852
shilu366312e2019-12-17 09:28:10 -08003853 /**
3854 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3855 * @param subId The subscription to use to check the configuration.
3856 * @param c The callback that will be used to send the result.
3857 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003858 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003859 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003860 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3861 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003862 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3863 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3864 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003865
3866 final long token = Binder.clearCallingIdentity();
3867 try {
3868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003870 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003871 } catch (ImsException e) {
3872 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3873 + "is inactive, ignoring unregister.");
3874 // If the subscription is no longer active, just return, since the callback
3875 // will already have been removed internally.
3876 } finally {
3877 Binder.restoreCallingIdentity(token);
3878 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003879 }
3880
3881 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003882 public boolean isCapable(int subId, int capability, int regTech) {
3883 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3885 final long token = Binder.clearCallingIdentity();
3886 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003887 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003888 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003889 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003890 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3891 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003892 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003893 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3894 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003895 } finally {
3896 Binder.restoreCallingIdentity(token);
3897 }
3898 }
3899
3900 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003901 public boolean isAvailable(int subId, int capability, int regTech) {
3902 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003903 final long token = Binder.clearCallingIdentity();
3904 try {
3905 Phone phone = getPhone(subId);
3906 if (phone == null) return false;
3907 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003908 } catch (com.android.ims.ImsException e) {
3909 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3910 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003911 } finally {
3912 Binder.restoreCallingIdentity(token);
3913 }
3914 }
3915
Brad Ebinger77b832e2019-10-17 17:03:22 -07003916 /**
3917 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3918 * subscription.
3919 * @param subId The subscription to use to check the configuration.
3920 * @param callback The callback that will be used to send the result.
3921 * @param capability The MmTelFeature capability that will be used to send the result.
3922 * @param transportType The transport type of the MmTelFeature capability.
3923 */
3924 @Override
3925 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3926 int transportType) {
3927 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3928 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3929 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3930 "IMS not available on device.");
3931 }
3932 final long token = Binder.clearCallingIdentity();
3933 try {
3934 int slotId = getSlotIndex(subId);
3935 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3936 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3937 + subId + "'");
3938 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3939 }
3940 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3941 transportType, aBoolean -> {
3942 try {
3943 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3944 } catch (RemoteException e) {
3945 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3946 + "running. Ignore");
3947 }
3948 });
3949 } finally {
3950 Binder.restoreCallingIdentity(token);
3951 }
3952 }
3953
shilu366312e2019-12-17 09:28:10 -08003954 /**
3955 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3956 * @param subId The subscription to use to check the configuration.
3957 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003958 @Override
3959 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003960 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3961 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003962
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3964 final long token = Binder.clearCallingIdentity();
3965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003966 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003967 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003968 } catch (ImsException e) {
3969 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003970 } finally {
3971 Binder.restoreCallingIdentity(token);
3972 }
3973 }
3974
3975 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003976 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003977 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003978 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 final long identity = Binder.clearCallingIdentity();
3980 try {
3981 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003982 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003983 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003984 } catch (ImsException e) {
3985 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003986 } finally {
3987 Binder.restoreCallingIdentity(identity);
3988 }
3989 }
3990
shilu366312e2019-12-17 09:28:10 -08003991 /**
3992 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3993 * @param subId The subscription to use to check the configuration.
3994 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003996 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003997 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3998 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 final long identity = Binder.clearCallingIdentity();
4000 try {
4001 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004002 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
4003 } catch (ImsException e) {
4004 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004005 } finally {
4006 Binder.restoreCallingIdentity(identity);
4007 }
4008 }
4009
4010 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004011 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004012 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004013 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004014 final long identity = Binder.clearCallingIdentity();
4015 try {
4016 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004017 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004018 } catch (ImsException e) {
4019 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 } finally {
4021 Binder.restoreCallingIdentity(identity);
4022 }
4023 }
4024
shilu366312e2019-12-17 09:28:10 -08004025 /**
4026 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4027 * @param subId The subscription to use to check the configuration.
4028 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 @Override
4030 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004031 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4032 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 final long identity = Binder.clearCallingIdentity();
4034 try {
4035 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004036 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004037 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 } catch (ImsException e) {
4039 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 } finally {
4041 Binder.restoreCallingIdentity(identity);
4042 }
4043 }
4044
4045 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004046 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004047 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004048 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004049 final long identity = Binder.clearCallingIdentity();
4050 try {
4051 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004052 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004053 } catch (ImsException e) {
4054 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004055 } finally {
4056 Binder.restoreCallingIdentity(identity);
4057 }
4058 }
4059
shilu366312e2019-12-17 09:28:10 -08004060 /**
4061 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4062 * @param subId The subscription to use to check the configuration.
4063 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 @Override
4065 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004066 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4067 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 final long identity = Binder.clearCallingIdentity();
4069 try {
4070 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004071 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004073 } catch (ImsException e) {
4074 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004075 } finally {
4076 Binder.restoreCallingIdentity(identity);
4077 }
4078 }
4079
4080 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004081 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004082 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004083 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 final long identity = Binder.clearCallingIdentity();
4085 try {
4086 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004087 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004088 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004089 } catch (ImsException e) {
4090 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004091 } finally {
4092 Binder.restoreCallingIdentity(identity);
4093 }
4094 }
4095
4096 @Override
4097 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4098 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4099 "setVoWiFiNonPersistent");
4100 final long identity = Binder.clearCallingIdentity();
4101 try {
4102 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004103 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004104 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004105 } catch (ImsException e) {
4106 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 } finally {
4108 Binder.restoreCallingIdentity(identity);
4109 }
4110 }
4111
shilu366312e2019-12-17 09:28:10 -08004112 /**
4113 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4114 * @param subId The subscription to use to check the configuration.
4115 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 @Override
4117 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004118 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4119 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 final long identity = Binder.clearCallingIdentity();
4121 try {
4122 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004123 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004124 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004125 } catch (ImsException e) {
4126 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004127 } finally {
4128 Binder.restoreCallingIdentity(identity);
4129 }
4130 }
4131
4132 @Override
4133 public void setVoWiFiModeSetting(int subId, int mode) {
4134 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4135 "setVoWiFiModeSetting");
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004139 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004140 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004141 } catch (ImsException e) {
4142 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004143 } finally {
4144 Binder.restoreCallingIdentity(identity);
4145 }
4146 }
4147
4148 @Override
4149 public int getVoWiFiRoamingModeSetting(int subId) {
4150 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4151 final long identity = Binder.clearCallingIdentity();
4152 try {
4153 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004154 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004155 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004156 } catch (ImsException e) {
4157 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4165 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4166 "setVoWiFiRoamingModeSetting");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004170 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004171 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004172 } catch (ImsException e) {
4173 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004174 } finally {
4175 Binder.restoreCallingIdentity(identity);
4176 }
4177 }
4178
4179 @Override
4180 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4181 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4182 "setRttCapabilityEnabled");
4183 final long identity = Binder.clearCallingIdentity();
4184 try {
4185 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004186 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4187 } catch (ImsException e) {
4188 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
4192 }
4193
shilu366312e2019-12-17 09:28:10 -08004194 /**
4195 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4196 * @param subId The subscription to use to check the configuration.
4197 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 @Override
4199 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004200 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4201 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 final long identity = Binder.clearCallingIdentity();
4203 try {
4204 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004205 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004206 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004207 } catch (ImsException e) {
4208 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004214 @Override
4215 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4216 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4217 final long identity = Binder.clearCallingIdentity();
4218 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004219 if (!isImsAvailableOnDevice()) {
4220 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4221 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004222 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004224 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004225 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 } catch (ImsException e) {
4227 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004228 } finally {
4229 Binder.restoreCallingIdentity(identity);
4230 }
4231 }
4232
4233 @Override
4234 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4235 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4236 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004237 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4238 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4239 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004240 try {
4241 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004242 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004243 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004244 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004245 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4246 + "is inactive, ignoring unregister.");
4247 // If the subscription is no longer active, just return, since the callback will already
4248 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004249 } finally {
4250 Binder.restoreCallingIdentity(identity);
4251 }
4252 }
4253
allenwtsu99c623b2020-01-03 18:24:23 +08004254
4255 private void checkModifyPhoneStatePermission(int subId, String message) {
4256 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4257 message);
4258 }
4259
4260 private boolean isImsProvisioningRequired(int subId, int capability,
4261 boolean isMmtelCapability) {
4262 Phone phone = getPhone(subId);
4263 if (phone == null) {
4264 loge("phone instance null for subid " + subId);
4265 return false;
4266 }
4267 if (isMmtelCapability) {
4268 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4269 return false;
4270 }
4271 } else {
4272 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4273 return false;
4274 }
4275 }
4276 return true;
4277 }
4278
4279 @Override
4280 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4281 boolean isProvisioned) {
4282 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4283
4284 final long identity = Binder.clearCallingIdentity();
4285 try {
4286 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4287 if (!isImsProvisioningRequired(subId, capability, false)) {
4288 return;
4289 }
4290
4291 // this capability requires provisioning, route to the correct API.
4292 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4293 switch (capability) {
4294 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4295 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4296 ims.setEabProvisioned(isProvisioned);
4297 break;
4298 default: {
4299 throw new IllegalArgumentException("Tried to set provisioning for "
4300 + "rcs capability '" + capability + "', which does not require "
4301 + "provisioning.");
4302 }
4303 }
4304 } finally {
4305 Binder.restoreCallingIdentity(identity);
4306 }
4307
4308 }
4309
4310
4311 @Override
4312 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4313 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4314 final long identity = Binder.clearCallingIdentity();
4315 try {
4316 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4317 if (!isImsProvisioningRequired(subId, capability, false)) {
4318 return true;
4319 }
4320
4321 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4322 switch (capability) {
4323 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4324 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4325 return ims.isEabProvisionedOnDevice();
4326
4327 default: {
4328 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4329 + "capability '" + capability + "', which does not require "
4330 + "provisioning.");
4331 }
4332 }
4333
4334 } finally {
4335 Binder.restoreCallingIdentity(identity);
4336 }
4337 }
4338
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004339 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004340 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4341 boolean isProvisioned) {
4342 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4343 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4344 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4345 }
allenwtsu99c623b2020-01-03 18:24:23 +08004346 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004347 final long identity = Binder.clearCallingIdentity();
4348 try {
4349 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004350 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004351 return;
4352 }
4353
4354 // this capability requires provisioning, route to the correct API.
4355 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4356 switch (capability) {
4357 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4358 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4359 ims.setVolteProvisioned(isProvisioned);
4360 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4361 ims.setWfcProvisioned(isProvisioned);
4362 }
4363 break;
4364 }
4365 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4366 // There is currently no difference in VT provisioning type.
4367 ims.setVtProvisioned(isProvisioned);
4368 break;
4369 }
4370 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4371 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4372 // change the capability of the feature instead if needed.
4373 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4374 == isProvisioned) {
4375 // No change in provisioning.
4376 return;
4377 }
4378 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4379 try {
4380 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004381 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004382 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4383 + ", Exception" + e.getMessage());
4384 }
4385 break;
4386 }
4387 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004388 throw new IllegalArgumentException("Tried to set provisioning for "
4389 + "MmTel capability '" + capability + "', which does not require "
4390 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004391 }
4392 }
4393
4394 } finally {
4395 Binder.restoreCallingIdentity(identity);
4396 }
4397 }
4398
4399 @Override
4400 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4401 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4402 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4403 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4404 }
4405 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4406 final long identity = Binder.clearCallingIdentity();
4407 try {
4408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004409 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004410 return true;
4411 }
4412
4413 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4414 switch (capability) {
4415 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4416 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4417 return ims.isVolteProvisionedOnDevice();
4418 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4419 return ims.isWfcProvisionedOnDevice();
4420 }
4421 // This should never happen, since we are checking tech above to make sure it
4422 // is either LTE or IWLAN.
4423 throw new IllegalArgumentException("Invalid radio technology for voice "
4424 + "capability.");
4425 }
4426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4427 // There is currently no difference in VT provisioning type.
4428 return ims.isVtProvisionedOnDevice();
4429 }
4430 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4431 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4432 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4433 }
4434 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004435 throw new IllegalArgumentException(
4436 "Tried to get provisioning for MmTel capability '" + capability
4437 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004438 }
4439 }
4440
4441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
4447 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4448 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4449 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4450 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4451 }
4452 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4453 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4454 return (provisionedBits & capability) > 0;
4455 }
4456
4457 @Override
4458 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4459 boolean isProvisioned) {
4460 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4461 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4462 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4463 }
4464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4465 "setProvisioningStatusForCapability");
4466 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4467 // If the current provisioning status for capability already matches isProvisioned,
4468 // do nothing.
4469 if (((provisionedBits & capability) > 0) == isProvisioned) {
4470 return;
4471 }
4472 if (isProvisioned) {
4473 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4474 } else {
4475 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4476 }
4477 }
4478
4479 /**
4480 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4481 * technology. The bitfield should mirror the bitfield defined by
4482 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4483 */
4484 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4485 String key = getMmTelProvisioningKey(subId, tech);
4486 // Default is no capabilities are provisioned.
4487 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4488 }
4489
4490 /**
4491 * Sets the MmTel capability provisioning bitfield (defined by
4492 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4493 * technology specified.
4494 *
4495 * Note: This is a synchronous command and should not be called on UI thread.
4496 */
4497 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4498 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4499 String key = getMmTelProvisioningKey(subId, tech);
4500 editor.putInt(key, newField);
4501 editor.commit();
4502 }
4503
4504 private static String getMmTelProvisioningKey(int subId, int tech) {
4505 // resulting key is provision_ims_mmtel_{subId}_{tech}
4506 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4507 }
4508
4509 /**
4510 * Query CarrierConfig to see if the specified capability requires provisioning for the
4511 * carrier associated with the subscription id.
4512 */
4513 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4514 int capability) {
4515 CarrierConfigManager configManager = new CarrierConfigManager(context);
4516 PersistableBundle c = configManager.getConfigForSubId(subId);
4517 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004518 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004519 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4520 false);
4521 boolean requireVoiceVtProvisioning = c.getBoolean(
4522 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4523
4524 // First check to make sure that the capability requires provisioning.
4525 switch (capability) {
4526 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4527 // intentional fallthrough
4528 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4529 if (requireVoiceVtProvisioning) {
4530 // Voice and Video requires provisioning
4531 return true;
4532 }
4533 break;
4534 }
4535 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4536 if (requireUtProvisioning) {
4537 // UT requires provisioning
4538 return true;
4539 }
4540 break;
4541 }
4542 }
4543 return false;
4544 }
4545
allenwtsu99c623b2020-01-03 18:24:23 +08004546 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4547 int capability) {
4548 CarrierConfigManager configManager = new CarrierConfigManager(context);
4549 PersistableBundle c = configManager.getConfigForSubId(subId);
4550
4551 boolean requireRcsProvisioning = c.getBoolean(
4552 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4553
4554 // First check to make sure that the capability requires provisioning.
4555 switch (capability) {
4556 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4557 // intentional fallthrough
4558 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4559 if (requireRcsProvisioning) {
4560 // OPTION or PRESENCE requires provisioning
4561 return true;
4562 }
4563 break;
4564 }
4565 }
4566 return false;
4567 }
4568
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004569 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004570 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004571 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4572 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4573 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004574 enforceReadPrivilegedPermission("getImsProvisioningInt");
4575 final long identity = Binder.clearCallingIdentity();
4576 try {
4577 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004578 int slotId = getSlotIndex(subId);
4579 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4580 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4581 + subId + "' for key:" + key);
4582 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4583 }
4584 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004585 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004586 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4587 + subId + "' for key:" + key);
4588 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004589 } finally {
4590 Binder.restoreCallingIdentity(identity);
4591 }
4592 }
4593
4594 @Override
4595 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004596 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4597 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4598 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004599 enforceReadPrivilegedPermission("getImsProvisioningString");
4600 final long identity = Binder.clearCallingIdentity();
4601 try {
4602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004603 int slotId = getSlotIndex(subId);
4604 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4605 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4606 + subId + "' for key:" + key);
4607 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4608 }
4609 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004610 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004611 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4612 + subId + "' for key:" + key);
4613 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004614 } finally {
4615 Binder.restoreCallingIdentity(identity);
4616 }
4617 }
4618
4619 @Override
4620 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004621 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4622 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4623 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004624 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4625 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004629 int slotId = getSlotIndex(subId);
4630 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4631 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4632 + subId + "' for key:" + key);
4633 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4634 }
4635 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004636 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004637 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4638 + "' for key:" + key);
4639 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004640 } finally {
4641 Binder.restoreCallingIdentity(identity);
4642 }
4643 }
4644
4645 @Override
4646 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004647 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4648 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4649 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4651 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004652 final long identity = Binder.clearCallingIdentity();
4653 try {
4654 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004655 int slotId = getSlotIndex(subId);
4656 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4657 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4658 + subId + "' for key:" + key);
4659 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4660 }
4661 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004662 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004663 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4664 + "' for key:" + key);
4665 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004666 } finally {
4667 Binder.restoreCallingIdentity(identity);
4668 }
4669 }
4670
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004671 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 int slotId = SubscriptionManager.getSlotIndex(subId);
4673 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004674 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4675 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004676 }
4677 return slotId;
4678 }
4679
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004680 private int getSlotIndex(int subId) {
4681 int slotId = SubscriptionManager.getSlotIndex(subId);
4682 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4683 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4684 }
4685 return slotId;
4686 }
4687
Wink Saville36469e72014-06-11 15:17:00 -07004688 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004689 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004690 */
4691 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004692 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4693 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004694 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004695 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004696 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004697 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004698 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004699 mApp, subId, callingPackage, callingFeatureId,
4700 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004701 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4702 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004703
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004704 final long identity = Binder.clearCallingIdentity();
4705 try {
4706 final Phone phone = getPhone(subId);
4707 if (phone != null) {
4708 return phone.getServiceState().getDataNetworkType();
4709 } else {
4710 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4711 }
4712 } finally {
4713 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004714 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004715 }
4716
4717 /**
4718 * Returns the data network type
4719 */
4720 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004721 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4722 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4723 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004724 }
4725
4726 /**
4727 * Returns the data network type for a subId
4728 */
4729 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004730 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4731 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004732 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004733 mApp, subId, callingPackage, callingFeatureId,
4734 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004735 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4736 }
4737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004738 final long identity = Binder.clearCallingIdentity();
4739 try {
4740 final Phone phone = getPhone(subId);
4741 if (phone != null) {
4742 return phone.getServiceState().getDataNetworkType();
4743 } else {
4744 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4745 }
4746 } finally {
4747 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004748 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004749 }
4750
4751 /**
Wink Saville36469e72014-06-11 15:17:00 -07004752 * Returns the Voice network type for a subId
4753 */
4754 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004755 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4756 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004758 mApp, subId, callingPackage, callingFeatureId,
4759 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004760 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4761 }
4762
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004763 final long identity = Binder.clearCallingIdentity();
4764 try {
4765 final Phone phone = getPhone(subId);
4766 if (phone != null) {
4767 return phone.getServiceState().getVoiceNetworkType();
4768 } else {
4769 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4770 }
4771 } finally {
4772 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004773 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004774 }
4775
4776 /**
4777 * @return true if a ICC card is present
4778 */
4779 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004780 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004781 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4782 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004783 }
4784
4785 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004786 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004787 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004788 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004789 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004790 final long identity = Binder.clearCallingIdentity();
4791 try {
4792 final Phone phone = PhoneFactory.getPhone(slotIndex);
4793 if (phone != null) {
4794 return phone.getIccCard().hasIccCard();
4795 } else {
4796 return false;
4797 }
4798 } finally {
4799 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004800 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004801 }
4802
4803 /**
4804 * Return if the current radio is LTE on CDMA. This
4805 * is a tri-state return value as for a period of time
4806 * the mode may be unknown.
4807 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004808 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004809 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004810 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004811 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004812 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004813 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4814 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4815 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004816 }
4817
Sanket Padawe356d7632015-06-22 14:03:32 -07004818 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004819 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4820 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004821 try {
4822 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4823 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004824 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4825 }
4826
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004827 final long identity = Binder.clearCallingIdentity();
4828 try {
4829 final Phone phone = getPhone(subId);
4830 if (phone == null) {
4831 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4832 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004833 return TelephonyProperties.lte_on_cdma_device()
4834 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 }
4836 } finally {
4837 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004838 }
Wink Saville36469e72014-06-11 15:17:00 -07004839 }
4840
Wink Saville36469e72014-06-11 15:17:00 -07004841 /**
4842 * {@hide}
4843 * Returns Default subId, 0 in the case of single standby.
4844 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004845 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004846 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004847 }
4848
Shishir Agrawala9f32182016-04-12 12:00:16 -07004849 private int getSlotForDefaultSubscription() {
4850 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4851 }
4852
Wink Savilleb564aae2014-10-23 10:18:09 -07004853 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004854 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004855 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004856
Pengquan Menge92a50d2018-09-21 15:54:48 -07004857 private boolean isActiveSubscription(int subId) {
4858 return mSubscriptionController.isActiveSubId(subId);
4859 }
4860
Ihab Awadf2177b72013-11-25 13:33:23 -08004861 /**
4862 * @see android.telephony.TelephonyManager.WifiCallingChoices
4863 */
4864 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004865 final long identity = Binder.clearCallingIdentity();
4866 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004867 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4869 getWhenToMakeWifiCallsDefaultPreference());
4870 } finally {
4871 Binder.restoreCallingIdentity(identity);
4872 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004873 }
4874
4875 /**
4876 * @see android.telephony.TelephonyManager.WifiCallingChoices
4877 */
4878 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 final long identity = Binder.clearCallingIdentity();
4880 try {
4881 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004882 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4884 } finally {
4885 Binder.restoreCallingIdentity(identity);
4886 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004887 }
4888
Sailesh Nepald1e68152013-12-12 19:08:02 -08004889 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004890 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004891 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004892 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004893
Jordan Liu4c733742019-02-28 12:03:40 -08004894 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4895 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4896 if (phoneId == -1) {
4897 throw new IllegalArgumentException("Given slot index: " + slotIndex
4898 + " does not correspond to an active phone");
4899 }
4900 return PhoneFactory.getPhone(phoneId);
4901 }
4902
Shishir Agrawal566b7612013-10-28 14:41:00 -07004903 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004904 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4905 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4907 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004908 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004909 if (DBG) {
4910 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4911 }
4912 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4913 p2);
4914 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004915
Jordan Liu4c733742019-02-28 12:03:40 -08004916
4917 @Override
4918 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4919 int slotIndex, String callingPackage, String aid, int p2) {
4920 enforceModifyPermission();
4921 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4922 if (DBG) {
4923 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4924 }
4925 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4926 callingPackage, aid, p2);
4927 }
4928
4929 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4930 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 final long identity = Binder.clearCallingIdentity();
4932 try {
4933 if (TextUtils.equals(ISDR_AID, aid)) {
4934 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004935 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4936 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004937 if (bestComponent == null
4938 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4939 loge("The calling package is not allowed to access ISD-R.");
4940 throw new SecurityException(
4941 "The calling package is not allowed to access ISD-R.");
4942 }
Derek Tan740e1672017-06-27 14:56:27 -07004943 }
Derek Tan740e1672017-06-27 14:56:27 -07004944
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004946 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4947 null /* workSource */);
4948 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004949 return response;
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004953 }
4954
4955 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004956 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004957 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4958 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004959 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4960 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4961 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004962
Jordan Liu4c733742019-02-28 12:03:40 -08004963 @Override
4964 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4965 enforceModifyPermission();
4966 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4967 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4968 channel);
4969 }
4970
4971 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004972 final long identity = Binder.clearCallingIdentity();
4973 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 if (channel < 0) {
4975 return false;
4976 }
Jordan Liu4c733742019-02-28 12:03:40 -08004977 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4978 null /* workSource */);
4979 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980 return success;
4981 } finally {
4982 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004983 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984 }
4985
4986 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004987 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004988 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004989 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4990 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004991 if (DBG) {
4992 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4993 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4994 + p3 + " data=" + data);
4995 }
4996 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4997 command, p1, p2, p3, data);
4998 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004999
Jordan Liu4c733742019-02-28 12:03:40 -08005000 @Override
5001 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
5002 int command, int p1, int p2, int p3, String data) {
5003 enforceModifyPermission();
5004 if (DBG) {
5005 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5006 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5007 + p3 + " data=" + data);
5008 }
5009 return iccTransmitApduLogicalChannelWithPermission(
5010 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5011 data);
5012 }
5013
5014 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5015 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005016 final long identity = Binder.clearCallingIdentity();
5017 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005018 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005019 return "";
5020 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005021
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005023 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5024 null /* workSource */);
5025 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005026
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 // Append the returned status code to the end of the response payload.
5028 String s = Integer.toHexString(
5029 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5030 if (response.payload != null) {
5031 s = IccUtils.bytesToHexString(response.payload) + s;
5032 }
5033 return s;
5034 } finally {
5035 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005036 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005037 }
Jake Hambye994d462014-02-03 13:10:13 -08005038
Evan Charltonc66da362014-05-16 14:06:40 -07005039 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005040 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5041 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005042 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5043 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005045 if (DBG) {
5046 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5047 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5048 }
5049 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5050 cla, command, p1, p2, p3, data);
5051 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005052
Jordan Liu4c733742019-02-28 12:03:40 -08005053 @Override
5054 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5055 int command, int p1, int p2, int p3, String data) {
5056 enforceModifyPermission();
5057 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5058 if (DBG) {
5059 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5060 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5061 + " data=" + data);
5062 }
5063
5064 return iccTransmitApduBasicChannelWithPermission(
5065 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5066 p2, p3, data);
5067 }
5068
5069 // open APDU basic channel assuming the caller has sufficient permissions
5070 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5071 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072 final long identity = Binder.clearCallingIdentity();
5073 try {
5074 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5075 && TextUtils.equals(ISDR_AID, data)) {
5076 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005077 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5078 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 if (bestComponent == null
5080 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5081 loge("The calling package is not allowed to select ISD-R.");
5082 throw new SecurityException(
5083 "The calling package is not allowed to select ISD-R.");
5084 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005085 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005087 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005088 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5089 null /* workSource */);
5090 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092 // Append the returned status code to the end of the response payload.
5093 String s = Integer.toHexString(
5094 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5095 if (response.payload != null) {
5096 s = IccUtils.bytesToHexString(response.payload) + s;
5097 }
5098 return s;
5099 } finally {
5100 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005101 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005102 }
5103
5104 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005105 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005106 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005107 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5108 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 final long identity = Binder.clearCallingIdentity();
5111 try {
5112 if (DBG) {
5113 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5114 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5115 }
5116
5117 IccIoResult response =
5118 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5119 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5120 subId);
5121
5122 if (DBG) {
5123 log("Exchange SIM_IO [R]" + response);
5124 }
5125
5126 byte[] result = null;
5127 int length = 2;
5128 if (response.payload != null) {
5129 length = 2 + response.payload.length;
5130 result = new byte[length];
5131 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5132 } else {
5133 result = new byte[length];
5134 }
5135
5136 result[length - 1] = (byte) response.sw2;
5137 result[length - 2] = (byte) response.sw1;
5138 return result;
5139 } finally {
5140 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005141 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005142 }
5143
Nathan Haroldb3014052017-01-25 15:57:32 -08005144 /**
5145 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5146 * on a particular subscription
5147 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005148 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5149 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005150 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005151 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005152 return null;
5153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005154
5155 final long identity = Binder.clearCallingIdentity();
5156 try {
5157 if (appType != TelephonyManager.APPTYPE_USIM
5158 && appType != TelephonyManager.APPTYPE_SIM) {
5159 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5160 return null;
5161 }
5162 Object response = sendRequest(
5163 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5164 if (response instanceof String[]) {
5165 return (String[]) response;
5166 }
yincheng zhaod698b842019-09-06 17:06:54 -07005167 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005168 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005169 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005170 } finally {
5171 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005172 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005173 }
5174
yincheng zhaod698b842019-09-06 17:06:54 -07005175 /**
5176 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5177 * subscription.
5178 *
5179 * @param subId the id of the subscription.
5180 * @param appType the uicc app type, must be USIM or SIM.
5181 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5182 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005183 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005184 * @return number of fplmns that is successfully written to the SIM.
5185 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005186 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5187 String callingFeatureId) {
5188 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5189 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005190 if (DBG) logv("no permissions for setForbiddenplmns");
5191 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5192 }
5193 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5194 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5195 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5196 }
5197 if (fplmns == null) {
5198 throw new IllegalArgumentException("Fplmn List provided is null");
5199 }
5200 for (String fplmn : fplmns) {
5201 if (!CellIdentity.isValidPlmn(fplmn)) {
5202 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5203 }
5204 }
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 Object response = sendRequest(
5208 CMD_SET_FORBIDDEN_PLMNS,
5209 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5210 subId);
5211 return (int) response;
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
5215 }
5216
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005217 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005218 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5220 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005221
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005222 final long identity = Binder.clearCallingIdentity();
5223 try {
5224 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5225 if (response.payload == null) {
5226 return "";
5227 }
Evan Charltonc66da362014-05-16 14:06:40 -07005228
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005229 // Append the returned status code to the end of the response payload.
5230 String s = Integer.toHexString(
5231 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5232 s = IccUtils.bytesToHexString(response.payload) + s;
5233 return s;
5234 } finally {
5235 Binder.restoreCallingIdentity(identity);
5236 }
Evan Charltonc66da362014-05-16 14:06:40 -07005237 }
5238
Jake Hambye994d462014-02-03 13:10:13 -08005239 /**
5240 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5241 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5242 *
5243 * @param itemID the ID of the item to read
5244 * @return the NV item as a String, or null on error.
5245 */
5246 @Override
5247 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005248 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005249 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5250 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251
5252 final long identity = Binder.clearCallingIdentity();
5253 try {
5254 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005255 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005256 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5257 return value;
5258 } finally {
5259 Binder.restoreCallingIdentity(identity);
5260 }
Jake Hambye994d462014-02-03 13:10:13 -08005261 }
5262
5263 /**
5264 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5265 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5266 *
5267 * @param itemID the ID of the item to read
5268 * @param itemValue the value to write, as a String
5269 * @return true on success; false on any failure
5270 */
5271 @Override
5272 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005273 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005274 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5275 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276
5277 final long identity = Binder.clearCallingIdentity();
5278 try {
5279 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5280 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005281 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005282 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5283 return success;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Jake Hambye994d462014-02-03 13:10:13 -08005287 }
5288
5289 /**
5290 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5291 * Used for device configuration by some CDMA operators.
5292 *
5293 * @param preferredRoamingList byte array containing the new PRL
5294 * @return true on success; false on any failure
5295 */
5296 @Override
5297 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005298 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5299 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005300
5301 final long identity = Binder.clearCallingIdentity();
5302 try {
5303 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5304 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5305 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5306 return success;
5307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Jake Hambye994d462014-02-03 13:10:13 -08005310 }
5311
5312 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005313 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005314 * Used for device configuration by some CDMA operators.
5315 *
chen xu6dac5ab2018-10-26 17:39:23 -07005316 * @param slotIndex - device slot.
5317 *
Jake Hambye994d462014-02-03 13:10:13 -08005318 * @return true on success; false on any failure
5319 */
5320 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005321 public boolean resetModemConfig(int slotIndex) {
5322 Phone phone = PhoneFactory.getPhone(slotIndex);
5323 if (phone != null) {
5324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5325 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005326
chen xu6dac5ab2018-10-26 17:39:23 -07005327 final long identity = Binder.clearCallingIdentity();
5328 try {
5329 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5330 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5331 return success;
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005335 }
chen xu6dac5ab2018-10-26 17:39:23 -07005336 return false;
5337 }
5338
5339 /**
5340 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5341 *
5342 * @param slotIndex - device slot.
5343 *
5344 * @return true on success; false on any failure
5345 */
5346 @Override
5347 public boolean rebootModem(int slotIndex) {
5348 Phone phone = PhoneFactory.getPhone(slotIndex);
5349 if (phone != null) {
5350 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5351 mApp, phone.getSubId(), "rebootModem");
5352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
5355 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5356 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5357 return success;
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
5361 }
5362 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005363 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005364
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005365 public String[] getPcscfAddress(String apnType, String callingPackage,
5366 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005367 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005368 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5369 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005370 return new String[0];
5371 }
5372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005373 final long identity = Binder.clearCallingIdentity();
5374 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005375 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005376 } finally {
5377 Binder.restoreCallingIdentity(identity);
5378 }
Wink Saville36469e72014-06-11 15:17:00 -07005379 }
5380
Brad Ebinger51f743a2017-01-23 13:50:20 -08005381 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005382 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5383 * {@link #disableIms(int)}.
5384 * @param slotIndex device slot.
5385 */
5386 public void resetIms(int slotIndex) {
5387 enforceModifyPermission();
5388
5389 final long identity = Binder.clearCallingIdentity();
5390 try {
5391 if (mImsResolver == null) {
5392 // may happen if the does not support IMS.
5393 return;
5394 }
5395 mImsResolver.disableIms(slotIndex);
5396 mImsResolver.enableIms(slotIndex);
5397 } finally {
5398 Binder.restoreCallingIdentity(identity);
5399 }
5400 }
5401
5402 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005403 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5404 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005405 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005406 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005407 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005408
5409 final long identity = Binder.clearCallingIdentity();
5410 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005411 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005412 // may happen if the device does not support IMS.
5413 return;
5414 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005415 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005416 } finally {
5417 Binder.restoreCallingIdentity(identity);
5418 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005419 }
5420
5421 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005422 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5423 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005424 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005425 public void disableIms(int slotId) {
5426 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005427
5428 final long identity = Binder.clearCallingIdentity();
5429 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005430 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005431 // may happen if the device does not support IMS.
5432 return;
5433 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005434 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 } finally {
5436 Binder.restoreCallingIdentity(identity);
5437 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005438 }
5439
5440 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005441 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5442 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005443 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005444 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005445 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005446 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005447
5448 final long identity = Binder.clearCallingIdentity();
5449 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005450 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005451 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5452 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005453 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005454 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005455 } finally {
5456 Binder.restoreCallingIdentity(identity);
5457 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005458 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005459 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005460 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5461 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005462 @Override
5463 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005464 enforceModifyPermission();
5465
5466 final long identity = Binder.clearCallingIdentity();
5467 try {
5468 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005469 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005470 } finally {
5471 Binder.restoreCallingIdentity(identity);
5472 }
5473 }
5474
5475 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005476 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005477 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005478 */
5479 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5480 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481
5482 final long identity = Binder.clearCallingIdentity();
5483 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005484 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005485 // may happen if the device does not support IMS.
5486 return null;
5487 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005488 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489 } finally {
5490 Binder.restoreCallingIdentity(identity);
5491 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005492 }
5493
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005494 /**
5495 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005496 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005497 */
5498 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5499 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005503 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005504 // may happen if the device does not support IMS.
5505 return null;
5506 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005507 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005508 } finally {
5509 Binder.restoreCallingIdentity(identity);
5510 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005511 }
5512
Brad Ebinger884c07b2018-02-15 16:17:40 -08005513 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005514 * Sets the ImsService Package Name that Telephony will bind to.
5515 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005516 * @param slotIndex the slot ID that the ImsService should bind for.
5517 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005518 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005519 * @param featureTypes An integer array of feature types associated with a packageName.
5520 * @param packageName The name of the package that the current configuration will be replaced
5521 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005522 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005523 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005524 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5525 int[] featureTypes, String packageName) {
5526 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5527 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5529 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005531
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005532 final long identity = Binder.clearCallingIdentity();
5533 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005534 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005535 // may happen if the device does not support IMS.
5536 return false;
5537 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005538 Map<Integer, String> featureConfig = new HashMap<>();
5539 for (int featureType : featureTypes) {
5540 featureConfig.put(featureType, packageName);
5541 }
5542 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5543 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005544 } finally {
5545 Binder.restoreCallingIdentity(identity);
5546 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005547 }
5548
5549 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005550 * Clears any carrier ImsService overrides for the slot index specified that were previously
5551 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5552 *
5553 * This should only be used for testing.
5554 *
5555 * @param slotIndex the slot ID that the ImsService should bind for.
5556 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5557 */
5558 @Override
5559 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5560 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5561 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5562 "clearCarrierImsServiceOverride");
5563 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5564 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5565 "clearCarrierImsServiceOverride");
5566
5567 final long identity = Binder.clearCallingIdentity();
5568 try {
5569 if (mImsResolver == null) {
5570 // may happen if the device does not support IMS.
5571 return false;
5572 }
5573 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
5577 }
5578
5579 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005580 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005581 *
5582 * @param slotId The slot that the ImsService is associated with.
5583 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5584 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005585 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005586 * @return the package name of the ImsService configuration.
5587 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005588 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5589 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005590 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005591 TelephonyPermissions
5592 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5593 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5594 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005596 final long identity = Binder.clearCallingIdentity();
5597 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005598 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005599 // may happen if the device does not support IMS.
5600 return "";
5601 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005602 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005603 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5604 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005608 }
5609
Brad Ebinger77b832e2019-10-17 17:03:22 -07005610 /**
5611 * Get the MmTelFeature state associated with the requested subscription id.
5612 * @param subId The subscription that the MmTelFeature is associated with.
5613 * @param callback A callback with an integer containing the
5614 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5615 */
5616 @Override
5617 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5618 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5619 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5620 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5621 "IMS not available on device.");
5622 }
5623 final long token = Binder.clearCallingIdentity();
5624 try {
5625 int slotId = getSlotIndex(subId);
5626 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5627 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5628 + subId + "'");
5629 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5630 }
5631 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5632 try {
5633 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5634 } catch (RemoteException e) {
5635 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5636 + "Ignore");
5637 }
5638 });
5639 } finally {
5640 Binder.restoreCallingIdentity(token);
5641 }
5642 }
5643
Daniel Brightbb5840b2021-01-12 15:48:18 -08005644 /**
5645 * Sets the ims registration state on all valid {@link Phone}s.
5646 */
5647 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005649
5650 final long identity = Binder.clearCallingIdentity();
5651 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005652 // NOTE: Before S, this method only set the default phone.
5653 for (final Phone phone : PhoneFactory.getPhones()) {
5654 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5655 phone.setImsRegistrationState(registered);
5656 }
5657 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 } finally {
5659 Binder.restoreCallingIdentity(identity);
5660 }
Wink Saville36469e72014-06-11 15:17:00 -07005661 }
5662
5663 /**
Stuart Scott54788802015-03-30 13:18:01 -07005664 * Set the network selection mode to automatic.
5665 *
5666 */
5667 @Override
5668 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005669 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5670 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005671
5672 final long identity = Binder.clearCallingIdentity();
5673 try {
shilufc958392020-01-20 11:36:01 -08005674 if (!isActiveSubscription(subId)) {
5675 return;
5676 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005677 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005678 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5679 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 } finally {
5681 Binder.restoreCallingIdentity(identity);
5682 }
Stuart Scott54788802015-03-30 13:18:01 -07005683 }
5684
Jack Yud10cdd42020-09-28 20:28:01 -07005685 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005686 * Ask the radio to connect to the input network and change selection mode to manual.
5687 *
5688 * @param subId the id of the subscription.
5689 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5690 * the operator to attach to.
5691 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5692 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5693 * normal network selection next time.
5694 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005695 */
5696 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005697 public boolean setNetworkSelectionModeManual(
5698 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005699 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5700 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005701
5702 if (!isActiveSubscription(subId)) {
5703 return false;
5704 }
5705
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 final long identity = Binder.clearCallingIdentity();
5707 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005708 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005709 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005710 if (DBG) {
5711 log("setNetworkSelectionModeManual: subId: " + subId
5712 + " operator: " + operatorInfo);
5713 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005714 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005718 }
shilu84f6e8b2019-12-19 13:58:01 -08005719 /**
5720 * Get the manual network selection
5721 *
5722 * @param subId the id of the subscription.
5723 *
5724 * @return the previously saved user selected PLMN
5725 */
5726 @Override
5727 public String getManualNetworkSelectionPlmn(int subId) {
5728 TelephonyPermissions
5729 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5730 mApp, subId, "getManualNetworkSelectionPlmn");
5731
5732 final long identity = Binder.clearCallingIdentity();
5733 try {
5734 if (!isActiveSubscription(subId)) {
5735 return "";
5736 }
5737
5738 final Phone phone = getPhone(subId);
5739 if (phone == null) {
5740 return "";
5741 }
5742 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5743 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5744 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5745 } finally {
5746 Binder.restoreCallingIdentity(identity);
5747 }
5748 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005749
5750 /**
5751 * Scans for available networks.
5752 */
5753 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005754 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5755 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005756 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5757 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005758 LocationAccessPolicy.LocationPermissionResult locationResult =
5759 LocationAccessPolicy.checkLocationPermission(mApp,
5760 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5761 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005762 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005763 .setCallingPid(Binder.getCallingPid())
5764 .setCallingUid(Binder.getCallingUid())
5765 .setMethod("getCellNetworkScanResults")
5766 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5767 .build());
5768 switch (locationResult) {
5769 case DENIED_HARD:
5770 throw new SecurityException("Not allowed to access scan results -- location");
5771 case DENIED_SOFT:
5772 return null;
5773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
Pengquan Menga1bb6272018-09-06 09:59:22 -07005775 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 try {
5777 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005778 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005779 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005780 } finally {
5781 Binder.restoreCallingIdentity(identity);
5782 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005783 }
5784
5785 /**
sqian80370722020-01-29 15:02:51 -08005786 * Get the call forwarding info, given the call forwarding reason.
5787 */
5788 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005789 public void getCallForwarding(int subId, int callForwardingReason,
5790 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005791 enforceReadPrivilegedPermission("getCallForwarding");
5792 long identity = Binder.clearCallingIdentity();
5793 try {
5794 if (DBG) {
5795 log("getCallForwarding: subId " + subId
5796 + " callForwardingReason" + callForwardingReason);
5797 }
Hall Liua1acea22020-09-18 19:04:59 -07005798
5799 Phone phone = getPhone(subId);
5800 if (phone == null) {
5801 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005802 callback.onError(
5803 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005804 } catch (RemoteException e) {
5805 // ignore
5806 }
5807 return;
5808 }
5809
5810 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5811 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5812 @Override
5813 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5814 try {
5815 callback.onCallForwardingInfoAvailable(info);
5816 } catch (RemoteException e) {
5817 // ignore
5818 }
5819 }
5820
5821 @Override
5822 public void onError(int error) {
5823 try {
5824 callback.onError(error);
5825 } catch (RemoteException e) {
5826 // ignore
5827 }
5828 }
5829 });
5830 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
5834 }
5835
5836 /**
5837 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5838 * reason, the number to forward, and the timeout before the forwarding is attempted.
5839 */
5840 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005841 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5842 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005843 enforceModifyPermission();
5844 long identity = Binder.clearCallingIdentity();
5845 try {
5846 if (DBG) {
5847 log("setCallForwarding: subId " + subId
5848 + " callForwardingInfo" + callForwardingInfo);
5849 }
Hall Liua1acea22020-09-18 19:04:59 -07005850
5851 Phone phone = getPhone(subId);
5852 if (phone == null) {
5853 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005854 callback.accept(
5855 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005856 } catch (RemoteException e) {
5857 // ignore
5858 }
5859 return;
5860 }
5861
5862 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5863 FunctionalUtils.ignoreRemoteException(callback::accept));
5864
5865 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005866 } finally {
5867 Binder.restoreCallingIdentity(identity);
5868 }
5869 }
5870
5871 /**
Hall Liua1acea22020-09-18 19:04:59 -07005872 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005873 */
5874 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005875 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005876 enforceReadPrivilegedPermission("getCallForwarding");
5877 long identity = Binder.clearCallingIdentity();
5878 try {
Hall Liua1acea22020-09-18 19:04:59 -07005879
5880 Phone phone = getPhone(subId);
5881 if (phone == null) {
5882 try {
5883 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5884 } catch (RemoteException e) {
5885 // ignore
5886 }
5887 return;
5888 }
5889
5890 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5891
sqian80370722020-01-29 15:02:51 -08005892 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005893 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005894 } finally {
5895 Binder.restoreCallingIdentity(identity);
5896 }
5897 }
5898
5899 /**
Hall Liua1acea22020-09-18 19:04:59 -07005900 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005901 */
5902 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005903 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005904 enforceModifyPermission();
5905 long identity = Binder.clearCallingIdentity();
5906 try {
Hall Liua1acea22020-09-18 19:04:59 -07005907 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5908
5909 Phone phone = getPhone(subId);
5910 if (phone == null) {
5911 try {
5912 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5913 } catch (RemoteException e) {
5914 // ignore
5915 }
5916 return;
5917 }
5918
5919 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5920 FunctionalUtils.ignoreRemoteException(callback::accept));
5921
5922 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
5926 }
5927
5928 /**
yinxub1bed742017-04-17 11:45:04 -07005929 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005930 *
yinxub1bed742017-04-17 11:45:04 -07005931 * @param subId id of the subscription
5932 * @param request contains the radio access networks with bands/channels to scan
5933 * @param messenger callback messenger for scan results or errors
5934 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005935 * @return the id of the requested scan which can be used to stop the scan.
5936 */
5937 @Override
5938 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005939 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005940 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5941 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005942 LocationAccessPolicy.LocationPermissionResult locationResult =
5943 LocationAccessPolicy.checkLocationPermission(mApp,
5944 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5945 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005946 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005947 .setCallingPid(Binder.getCallingPid())
5948 .setCallingUid(Binder.getCallingUid())
5949 .setMethod("requestNetworkScan")
5950 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5951 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005952 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005953 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5954 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005955 if (e != null) {
5956 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5957 throw e;
5958 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005959 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005960 return TelephonyScanManager.INVALID_SCAN_ID;
5961 }
5962 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963 }
Hall Liu912dfd32019-04-25 14:02:26 -07005964 int callingUid = Binder.getCallingUid();
5965 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005966 final long identity = Binder.clearCallingIdentity();
5967 try {
5968 return mNetworkScanRequestTracker.startNetworkScan(
5969 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005970 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005971 } finally {
5972 Binder.restoreCallingIdentity(identity);
5973 }
yinxu504e1392017-04-12 16:03:22 -07005974 }
5975
Hall Liub2ac8ef2019-02-28 15:56:23 -08005976 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005977 NetworkScanRequest request, int subId, String callingPackage) {
5978 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005979 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5980 boolean hasNetworkScanPermission =
5981 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5982 == PERMISSION_GRANTED;
5983
5984 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5985 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5986 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005987 }
5988
5989 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5990 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005991 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5992 return new SecurityException("Specific channels must not be"
5993 + " scanned without location access.");
5994 }
5995 }
5996 }
5997
Hall Liub2ac8ef2019-02-28 15:56:23 -08005998 return null;
5999 }
6000
yinxu504e1392017-04-12 16:03:22 -07006001 /**
6002 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07006003 *
6004 * @param subId id of the subscription
6005 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006006 */
6007 @Override
6008 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006009 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6010 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006011
Hall Liu912dfd32019-04-25 14:02:26 -07006012 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006013 final long identity = Binder.clearCallingIdentity();
6014 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006015 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 } finally {
6017 Binder.restoreCallingIdentity(identity);
6018 }
yinxu504e1392017-04-12 16:03:22 -07006019 }
6020
6021 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006022 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006023 *
SongFerngWang9e060372020-12-21 16:41:52 +08006024 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006025 */
6026 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006027 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006028 TelephonyPermissions
6029 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006030 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031
6032 final long identity = Binder.clearCallingIdentity();
6033 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006034 if (DBG) log("getAllowedNetworkTypesBitmask");
6035 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6036 int networkTypesBitmask = (result != null ? result[0] : -1);
6037 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6038 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006039 } finally {
6040 Binder.restoreCallingIdentity(identity);
6041 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006042 }
6043
6044 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006045 * Get the allowed network types for certain reason.
6046 *
6047 * @param subId the id of the subscription.
6048 * @param reason the reason the allowed network type change is taking place
6049 * @return the allowed network types.
6050 */
6051 @Override
6052 public long getAllowedNetworkTypesForReason(int subId,
6053 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6054 TelephonyPermissions
6055 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6056 mApp, subId, "getAllowedNetworkTypesForReason");
6057 final long identity = Binder.clearCallingIdentity();
6058 try {
6059 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6060 } finally {
6061 Binder.restoreCallingIdentity(identity);
6062 }
6063 }
6064
6065 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006066 * Enable/Disable E-UTRA-NR Dual Connectivity
6067 * @param subId subscription id of the sim card
6068 * @param nrDualConnectivityState expected NR dual connectivity state
6069 * This can be passed following states
6070 * <ol>
6071 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6072 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6073 * <li>Disable NR dual connectivity and force secondary cell to be released
6074 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6075 * </ol>
6076 * @return operation result.
6077 */
6078 @Override
6079 public int setNrDualConnectivityState(int subId,
6080 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6082 mApp, subId, "enableNRDualConnectivity");
6083 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6084 final long identity = Binder.clearCallingIdentity();
6085 try {
6086 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6087 nrDualConnectivityState, subId,
6088 workSource);
6089 if (DBG) log("enableNRDualConnectivity result: " + result);
6090 return result;
6091 } finally {
6092 Binder.restoreCallingIdentity(identity);
6093 }
6094 }
6095
6096 /**
6097 * Is E-UTRA-NR Dual Connectivity enabled
6098 * @return true if dual connectivity is enabled else false
6099 */
6100 @Override
6101 public boolean isNrDualConnectivityEnabled(int subId) {
6102 TelephonyPermissions
6103 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6104 mApp, subId, "isNRDualConnectivityEnabled");
6105 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6106 final long identity = Binder.clearCallingIdentity();
6107 try {
6108 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6109 null, subId, workSource);
6110 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6111 return isEnabled;
6112 } finally {
6113 Binder.restoreCallingIdentity(identity);
6114 }
6115 }
6116
6117 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006118 * get carrier bandwidth per primary and secondary carrier
6119 * @param subId subscription id of the sim card
6120 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6121 */
6122 @Override
6123 public CarrierBandwidth getCarrierBandwidth(int subId) {
6124 TelephonyPermissions
6125 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6126 mApp, subId, "isNRDualConnectivityEnabled");
6127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6128 final long identity = Binder.clearCallingIdentity();
6129 try {
6130 CarrierBandwidth carrierBandwidth =
6131 getPhoneFromSubId(subId).getCarrierBandwidth();
6132 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6133 return carrierBandwidth;
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
6136 }
6137 }
6138
6139 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006140 * Set the allowed network types of the device and
6141 * provide the reason triggering the allowed network change.
6142 *
6143 * @param subId the id of the subscription.
6144 * @param reason the reason the allowed network type change is taking place
6145 * @param allowedNetworkTypes the allowed network types.
6146 * @return true on success; false on any failure.
6147 */
6148 @Override
6149 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006150 @TelephonyManager.AllowedNetworkTypesReason int reason,
6151 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006152 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6153 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006154 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6155 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6156 return false;
6157 }
6158
6159 if (DBG) {
6160 log("setAllowedNetworkTypesForReason: " + reason
6161 + " value: " + allowedNetworkTypes);
6162 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006163 final long identity = Binder.clearCallingIdentity();
6164 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006165 Boolean success = (Boolean) sendRequest(
6166 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6167 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6168
6169 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6170 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006171 } finally {
6172 Binder.restoreCallingIdentity(identity);
6173 }
6174 }
6175
6176 /**
Miaoa84611c2019-03-15 09:21:10 +08006177 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006178 *
Miaoa84611c2019-03-15 09:21:10 +08006179 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006180 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006181 * @hide
6182 */
6183 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006184 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006185 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006186 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006187 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 try {
Miaoa84611c2019-03-15 09:21:10 +08006189 if (phone != null) {
6190 return phone.hasMatchedTetherApnSetting();
6191 } else {
6192 return false;
6193 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006194 } finally {
6195 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006196 }
Junda Liu475951f2014-11-07 16:45:03 -08006197 }
6198
6199 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006200 * Enable or disable always reporting signal strength changes from radio.
6201 *
6202 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6203 */
6204 @Override
6205 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6206 enforceModifyPermission();
6207 enforceSystemCaller();
6208
6209 final long identity = Binder.clearCallingIdentity();
6210 final Phone phone = getPhone(subId);
6211 try {
6212 if (phone != null) {
6213 if (DBG) {
6214 log("setAlwaysReportSignalStrength: subId=" + subId
6215 + " isEnable=" + isEnable);
6216 }
6217 phone.setAlwaysReportSignalStrength(isEnable);
6218 } else {
6219 loge("setAlwaysReportSignalStrength: no phone found for subId="
6220 + subId);
6221 }
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224 }
6225 }
6226
6227 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006228 * Get the user enabled state of Mobile Data.
6229 *
6230 * TODO: remove and use isUserDataEnabled.
6231 * This can't be removed now because some vendor codes
6232 * calls through ITelephony directly while they should
6233 * use TelephonyManager.
6234 *
6235 * @return true on enabled
6236 */
6237 @Override
6238 public boolean getDataEnabled(int subId) {
6239 return isUserDataEnabled(subId);
6240 }
6241
6242 /**
6243 * Get whether mobile data is enabled per user setting.
6244 *
6245 * There are other factors deciding whether mobile data is actually enabled, but they are
6246 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006247 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006248 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006249 *
6250 * @return {@code true} if data is enabled else {@code false}
6251 */
6252 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006253 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006254 try {
6255 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6256 null);
6257 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006258 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6259 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006261
6262 final long identity = Binder.clearCallingIdentity();
6263 try {
6264 int phoneId = mSubscriptionController.getPhoneId(subId);
6265 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6266 Phone phone = PhoneFactory.getPhone(phoneId);
6267 if (phone != null) {
6268 boolean retVal = phone.isUserDataEnabled();
6269 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6270 return retVal;
6271 } else {
6272 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6273 return false;
6274 }
6275 } finally {
6276 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006277 }
6278 }
6279
6280 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006281 * Checks if the device is capable of mobile data by considering whether whether the
6282 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6283 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006284 *
Shuo Qian985d1232020-01-08 14:30:06 -08006285 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006286 */
6287 @Override
6288 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006289 try {
6290 try {
6291 mApp.enforceCallingOrSelfPermission(
6292 android.Manifest.permission.ACCESS_NETWORK_STATE,
6293 null);
6294 } catch (Exception e) {
6295 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6296 "isDataEnabled");
6297 }
6298 } catch (Exception e) {
6299 enforceReadPrivilegedPermission("isDataEnabled");
6300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301
6302 final long identity = Binder.clearCallingIdentity();
6303 try {
6304 int phoneId = mSubscriptionController.getPhoneId(subId);
6305 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6306 Phone phone = PhoneFactory.getPhone(phoneId);
6307 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006308 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6310 return retVal;
6311 } else {
6312 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6313 return false;
6314 }
6315 } finally {
6316 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006317 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006318 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006319
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006320 /**
6321 * Check if data is enabled for a specific reason
6322 * @param subId Subscription index
6323 * @param reason the reason the data enable change is taking place
6324 * @return {@code true} if the overall data is enabled; {@code false} if not.
6325 */
6326 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006327 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006328 @TelephonyManager.DataEnabledReason int reason) {
6329 try {
6330 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6331 null);
6332 } catch (Exception e) {
6333 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006334 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006335 }
6336
6337
6338 final long identity = Binder.clearCallingIdentity();
6339 try {
6340 int phoneId = mSubscriptionController.getPhoneId(subId);
6341 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006342 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006343 + " reason=" + reason);
6344 }
6345 Phone phone = PhoneFactory.getPhone(phoneId);
6346 if (phone != null) {
6347 boolean retVal;
6348 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6349 retVal = phone.isUserDataEnabled();
6350 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006351 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006352 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006353 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006354 return retVal;
6355 } else {
6356 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006357 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006358 + subId + " retVal=false");
6359 }
6360 return false;
6361 }
6362 } finally {
6363 Binder.restoreCallingIdentity(identity);
6364 }
6365 }
6366
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006367 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006368 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006369 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6370 // Skip the check if it's one of these special uids
6371 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6372 }
6373
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006374 //load access rules from carrier configs, and check those as well: b/139133814
6375 SubscriptionController subController = SubscriptionController.getInstance();
6376 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6377 || subController == null) return privilegeFromSim;
6378
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006379 PackageManager pkgMgr = phone.getContext().getPackageManager();
6380 String[] packages = pkgMgr.getPackagesForUid(uid);
6381
6382 final long identity = Binder.clearCallingIdentity();
6383 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006384 int subId = phone.getSubId();
6385 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6386 // A test override is in place for the privileges for this subId, so don't try to
6387 // read the subscription privileges.
6388 return privilegeFromSim;
6389 }
6390 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006391 SubscriptionManager subManager = (SubscriptionManager)
6392 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6393 for (String pkg : packages) {
6394 if (subManager.canManageSubscription(subInfo, pkg)) {
6395 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6396 }
6397 }
6398 return privilegeFromSim;
6399 } finally {
6400 Binder.restoreCallingIdentity(identity);
6401 }
6402 }
6403
6404 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6405 String pkgName) {
6406 //load access rules from carrier configs, and check those as well: b/139133814
6407 SubscriptionController subController = SubscriptionController.getInstance();
6408 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6409 || subController == null) return privilegeFromSim;
6410
6411 final long identity = Binder.clearCallingIdentity();
6412 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006413 int subId = phone.getSubId();
6414 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6415 // A test override is in place for the privileges for this subId, so don't try to
6416 // read the subscription privileges.
6417 return privilegeFromSim;
6418 }
6419 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006420 SubscriptionManager subManager = (SubscriptionManager)
6421 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6422 return subManager.canManageSubscription(subInfo, pkgName)
6423 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6424 } finally {
6425 Binder.restoreCallingIdentity(identity);
6426 }
6427 }
6428
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006429 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006430 public int getCarrierPrivilegeStatus(int subId) {
6431 final Phone phone = getPhone(subId);
6432 if (phone == null) {
6433 loge("getCarrierPrivilegeStatus: Invalid subId");
6434 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6435 }
6436 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006437 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006438 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6440 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006441
6442 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6443 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006444 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006445 }
Junda Liu29340342014-07-10 15:23:27 -07006446
6447 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006448 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006449 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006450 final Phone phone = getPhone(subId);
6451 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006452 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6454 }
6455 UiccProfile profile =
6456 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6457 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006458 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006459 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6460 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006461 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006462 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006463 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006464 }
6465
6466 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006467 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6468 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006469 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006470 }
6471
6472 int phoneId = SubscriptionManager.getPhoneId(subId);
6473 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006474 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006475 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006476 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6477 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006478 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6479 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6480 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006481 }
6482
6483 @Override
6484 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006485 if (TextUtils.isEmpty(pkgName))
6486 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006487 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6488 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6489 UiccCard card = UiccController.getInstance().getUiccCard(i);
6490 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006491 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006492 continue;
6493 }
6494
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006495 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6496 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6497 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006498 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6499 break;
6500 }
6501 }
6502
6503 return result;
Junda Liu29340342014-07-10 15:23:27 -07006504 }
Derek Tan89e89d42014-07-08 17:00:10 -07006505
6506 @Override
Junda Liue64de782015-04-16 17:19:16 -07006507 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6508 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6509 loge("phoneId " + phoneId + " is not valid.");
6510 return null;
6511 }
6512 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006513 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006514 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006515 return null ;
6516 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006517 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006518 }
6519
Amith Yamasani6e118872016-02-19 12:53:51 -08006520 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006521 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006522 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006523 List<String> privilegedPackages = new ArrayList<>();
6524 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006525 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6526 // has UICC in that slot.
6527 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006528 if (card.hasCarrierPrivilegeRules()) {
6529 if (packages == null) {
6530 // Only check packages in user 0 for now
6531 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006532 PackageManager.MATCH_DISABLED_COMPONENTS
6533 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006534 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006535 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006536 }
6537 for (int p = packages.size() - 1; p >= 0; p--) {
6538 PackageInfo pkgInfo = packages.get(p);
6539 if (pkgInfo != null && pkgInfo.packageName != null
6540 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006541 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006542 privilegedPackages.add(pkgInfo.packageName);
6543 }
6544 }
6545 }
6546 }
6547 return privilegedPackages;
6548 }
6549
chen xuf7e9fe82019-05-09 19:31:02 -07006550 @Override
6551 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006552 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6553
6554 final long identity = Binder.clearCallingIdentity();
6555
chen xuf7e9fe82019-05-09 19:31:02 -07006556 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006557 try {
6558 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6559 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6560 }
6561 } finally {
6562 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006563 }
6564 return privilegedPackages;
6565 }
6566
Wink Savilleb564aae2014-10-23 10:18:09 -07006567 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006568 final Phone phone = getPhone(subId);
6569 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006570 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006571 return null;
6572 }
6573 String iccId = card.getIccId();
6574 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006575 return null;
6576 }
6577 return iccId;
6578 }
6579
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006580 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006581 public void setCallComposerStatus(int subId, int status) {
6582 enforceModifyPermission();
6583
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 Phone phone = getPhone(subId);
6587 if (phone != null) {
6588 Phone defaultPhone = phone.getImsPhone();
6589 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6590 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6591 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006592 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6593 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006594 }
6595 }
Shuo Qiand8782462020-12-22 19:10:14 -08006596 } catch (ImsException e) {
6597 throw new ServiceSpecificException(e.getCode());
6598 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006599 Binder.restoreCallingIdentity(identity);
6600 }
6601 }
6602
6603 @Override
6604 public int getCallComposerStatus(int subId) {
6605 enforceReadPrivilegedPermission("getCallComposerStatus");
6606
6607 final long identity = Binder.clearCallingIdentity();
6608 try {
6609 Phone phone = getPhone(subId);
6610 if (phone != null) {
6611 Phone defaultPhone = phone.getImsPhone();
6612 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6613 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6614 return imsPhone.getCallComposerStatus();
6615 }
6616 }
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
6619 }
6620 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6621 }
6622
6623 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006624 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6625 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006626 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006627 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006628
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 final String iccId = getIccId(subId);
6632 final Phone phone = getPhone(subId);
6633 if (phone == null) {
6634 return false;
6635 }
6636 final String subscriberId = phone.getSubscriberId();
6637
6638 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006639 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006640 + subscriberId + " to " + number);
6641 }
6642
6643 if (TextUtils.isEmpty(iccId)) {
6644 return false;
6645 }
6646
6647 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6648
6649 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6650 if (alphaTag == null) {
6651 editor.remove(alphaTagPrefKey);
6652 } else {
6653 editor.putString(alphaTagPrefKey, alphaTag);
6654 }
6655
6656 // Record both the line number and IMSI for this ICCID, since we need to
6657 // track all merged IMSIs based on line number
6658 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6659 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6660 if (number == null) {
6661 editor.remove(numberPrefKey);
6662 editor.remove(subscriberPrefKey);
6663 } else {
6664 editor.putString(numberPrefKey, number);
6665 editor.putString(subscriberPrefKey, subscriberId);
6666 }
6667
6668 editor.commit();
6669 return true;
6670 } finally {
6671 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006672 }
Derek Tan7226c842014-07-02 17:42:23 -07006673 }
6674
6675 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006676 public String getLine1NumberForDisplay(int subId, String callingPackage,
6677 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006678 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006679 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006680 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006681 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006682 return null;
6683 }
Derek Tan97ebb422014-09-05 16:55:38 -07006684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 String iccId = getIccId(subId);
6688 if (iccId != null) {
6689 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6690 if (DBG_MERGE) {
6691 log("getLine1NumberForDisplay returning "
6692 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6693 }
6694 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6697 return null;
6698 } finally {
6699 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006700 }
Derek Tan7226c842014-07-02 17:42:23 -07006701 }
6702
6703 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006704 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6705 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006706 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006707 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006708 return null;
6709 }
Derek Tan97ebb422014-09-05 16:55:38 -07006710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 final long identity = Binder.clearCallingIdentity();
6712 try {
6713 String iccId = getIccId(subId);
6714 if (iccId != null) {
6715 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6716 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6717 }
6718 return null;
6719 } finally {
6720 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006721 }
Derek Tan7226c842014-07-02 17:42:23 -07006722 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006723
6724 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006725 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6726 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006727 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6728 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006729 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006730 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006731 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006732 return null;
6733 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006734
Jordan Liub49b04b2019-05-06 14:45:15 -07006735 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6736 // the process, where TelephonyManager was instantiated.
6737 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006738 final long identity = Binder.clearCallingIdentity();
6739 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006740 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 final TelephonyManager tele = TelephonyManager.from(context);
6742 final SubscriptionManager sub = SubscriptionManager.from(context);
6743
6744 // Figure out what subscribers are currently active
6745 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746
Jordan Liub49b04b2019-05-06 14:45:15 -07006747 // Only consider subs which match the current subId
6748 // This logic can be simplified. See b/131189269 for progress.
6749 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006750 activeSubscriberIds.add(tele.getSubscriberId(subId));
6751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752
6753 // First pass, find a number override for an active subscriber
6754 String mergeNumber = null;
6755 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6756 for (String key : prefs.keySet()) {
6757 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6758 final String subscriberId = (String) prefs.get(key);
6759 if (activeSubscriberIds.contains(subscriberId)) {
6760 final String iccId = key.substring(
6761 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6762 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6763 mergeNumber = (String) prefs.get(numberKey);
6764 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006765 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006766 + " for active subscriber " + subscriberId);
6767 }
6768 if (!TextUtils.isEmpty(mergeNumber)) {
6769 break;
6770 }
6771 }
6772 }
6773 }
6774
6775 // Shortcut when no active merged subscribers
6776 if (TextUtils.isEmpty(mergeNumber)) {
6777 return null;
6778 }
6779
6780 // Second pass, find all subscribers under that line override
6781 final ArraySet<String> result = new ArraySet<>();
6782 for (String key : prefs.keySet()) {
6783 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6784 final String number = (String) prefs.get(key);
6785 if (mergeNumber.equals(number)) {
6786 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6787 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6788 final String subscriberId = (String) prefs.get(subscriberKey);
6789 if (!TextUtils.isEmpty(subscriberId)) {
6790 result.add(subscriberId);
6791 }
6792 }
6793 }
6794 }
6795
6796 final String[] resultArray = result.toArray(new String[result.size()]);
6797 Arrays.sort(resultArray);
6798 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006799 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006800 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6801 }
6802 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006803 } finally {
6804 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006805 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006806 }
6807
6808 @Override
zoey chen38003472019-12-13 17:16:31 +08006809 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6810 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006811
6812 final long identity = Binder.clearCallingIdentity();
6813 try {
6814 final TelephonyManager telephonyManager = mApp.getSystemService(
6815 TelephonyManager.class);
6816 String subscriberId = telephonyManager.getSubscriberId(subId);
6817 if (subscriberId == null) {
6818 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006819 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006820 + subId);
6821 }
6822 return null;
6823 }
6824
6825 final SubscriptionInfo info = SubscriptionController.getInstance()
6826 .getSubscriptionInfo(subId);
6827 final ParcelUuid groupUuid = info.getGroupUuid();
6828 // If it doesn't belong to any group, return just subscriberId of itself.
6829 if (groupUuid == null) {
6830 return new String[]{subscriberId};
6831 }
6832
6833 // Get all subscriberIds from the group.
6834 final List<String> mergedSubscriberIds = new ArrayList<>();
6835 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006836 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006837 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006838 for (SubscriptionInfo subInfo : groupInfos) {
6839 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6840 if (subscriberId != null) {
6841 mergedSubscriberIds.add(subscriberId);
6842 }
6843 }
6844
6845 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6846 } finally {
6847 Binder.restoreCallingIdentity(identity);
6848
6849 }
6850 }
6851
6852 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006853 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006854 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006855 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856
6857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 final Phone phone = getPhone(subId);
6860 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6861 } finally {
6862 Binder.restoreCallingIdentity(identity);
6863 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006864 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006865
6866 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006867 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006868 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6869 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006870 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6871 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872
6873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 final Phone phone = getPhone(subId);
6876 if (phone == null) {
6877 return false;
6878 }
6879 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6880 cdmaNonRoamingList);
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006883 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006884 }
6885
6886 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006887 @Deprecated
6888 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6889 enforceModifyPermission();
6890
6891 int returnValue = 0;
6892 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006893 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006894 if(result.exception == null) {
6895 if (result.result != null) {
6896 byte[] responseData = (byte[])(result.result);
6897 if(responseData.length > oemResp.length) {
6898 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6899 responseData.length + "bytes. Buffer Size is " +
6900 oemResp.length + "bytes.");
6901 }
6902 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6903 returnValue = responseData.length;
6904 }
6905 } else {
6906 CommandException ex = (CommandException) result.exception;
6907 returnValue = ex.getCommandError().ordinal();
6908 if(returnValue > 0) returnValue *= -1;
6909 }
6910 } catch (RuntimeException e) {
6911 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6912 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6913 if(returnValue > 0) returnValue *= -1;
6914 }
6915
6916 return returnValue;
6917 }
6918
6919 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006920 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006921 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006922 try {
6923 TelephonyPermissions
6924 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6925 mApp, phone.getSubId(), "getRadioAccessFamily");
6926 } catch (SecurityException e) {
6927 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6928 throw e;
6929 }
chen xub97461a2018-10-26 14:17:57 -07006930 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006931 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006932 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006933 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006934 final long identity = Binder.clearCallingIdentity();
6935 try {
chen xub97461a2018-10-26 14:17:57 -07006936 TelephonyPermissions
6937 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6938 mApp, phone.getSubId(), "getRadioAccessFamily");
6939 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 } finally {
6941 Binder.restoreCallingIdentity(identity);
6942 }
chen xub97461a2018-10-26 14:17:57 -07006943 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006944 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006945
6946 @Override
6947 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006948 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006949 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950
6951 final long identity = Binder.clearCallingIdentity();
6952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006953 ImsManager.getInstance(defaultPhone.getContext(),
6954 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 } finally {
6956 Binder.restoreCallingIdentity(identity);
6957 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006958 }
6959
6960 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006961 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006962 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006963 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6964 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006965 return false;
6966 }
Svet Ganovb320e182015-04-16 12:30:10 -07006967
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006968 final long identity = Binder.clearCallingIdentity();
6969 try {
6970 // Check the user preference and the system-level IMS setting. Even if the user has
6971 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6972 // In the long run, we may instead need to check if there exists a connection service
6973 // which can support video calling.
6974 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006975 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976 return imsManager.isVtEnabledByPlatform()
6977 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6978 && imsManager.isVtEnabledByUser();
6979 } finally {
6980 Binder.restoreCallingIdentity(identity);
6981 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006982 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006983
Andrew Leea1239f22015-03-02 17:44:07 -08006984 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006985 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6986 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006987 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006988 mApp, subId, callingPackage, callingFeatureId,
6989 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 return false;
6991 }
6992
6993 final long identity = Binder.clearCallingIdentity();
6994 try {
6995 CarrierConfigManager configManager =
6996 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006997 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6999 } finally {
7000 Binder.restoreCallingIdentity(identity);
7001 }
Andrew Leea1239f22015-03-02 17:44:07 -08007002 }
7003
7004 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007005 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007006 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007007 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 return false;
7009 }
7010
7011 final long identity = Binder.clearCallingIdentity();
7012 try {
7013 CarrierConfigManager configManager =
7014 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007015 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007016 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7017 } finally {
7018 Binder.restoreCallingIdentity(identity);
7019 }
Andrew Leea1239f22015-03-02 17:44:07 -08007020 }
7021
Andrew Lee9431b832015-03-09 18:46:45 -07007022 @Override
7023 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007024 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007025 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007026 }
7027
7028 @Override
7029 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 final long identity = Binder.clearCallingIdentity();
7031 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007032 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 } finally {
7034 Binder.restoreCallingIdentity(identity);
7035 }
Andrew Lee9431b832015-03-09 18:46:45 -07007036 }
7037
Hall Liuf6668912018-10-31 17:05:23 -07007038 /**
7039 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7040 * support for the feature and device firmware support.
7041 *
7042 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7043 */
7044 @Override
7045 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007047 final Phone phone = getPhone(subscriptionId);
7048 if (phone == null) {
7049 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7050 return false;
7051 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007053 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7055 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007056 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 return isCarrierSupported && isDeviceSupported;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
7060 }
Hall Liu98187582018-01-22 19:15:32 -08007061 }
7062
Hall Liuf6668912018-10-31 17:05:23 -07007063 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007064 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7065 * RTT setting, will return true if the device and carrier both support RTT.
7066 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007067 */
7068 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007069 final long identity = Binder.clearCallingIdentity();
7070 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007071 boolean isRttSupported = isRttSupported(subscriptionId);
7072 boolean isUserRttSettingOn = Settings.Secure.getInt(
7073 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7074 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7075 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7076 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007077 } finally {
7078 Binder.restoreCallingIdentity(identity);
7079 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007080 }
7081
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007082 @Deprecated
7083 @Override
7084 public String getDeviceId(String callingPackage) {
7085 return getDeviceIdWithFeature(callingPackage, null);
7086 }
7087
Sanket Padawe7310cc72015-01-14 09:53:20 -08007088 /**
7089 * Returns the unique device ID of phone, for example, the IMEI for
7090 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7091 *
7092 * <p>Requires Permission:
7093 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7094 */
7095 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007096 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007097 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007098 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007099 return null;
7100 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007101 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007102 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007103 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007104 return null;
7105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 return phone.getDeviceId();
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
7112 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007113 }
7114
Ping Sunc67b7c22016-03-02 19:16:45 +08007115 /**
7116 * {@hide}
7117 * Returns the IMS Registration Status on a particular subid
7118 *
7119 * @param subId
7120 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007121 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007122 Phone phone = getPhone(subId);
7123 if (phone != null) {
7124 return phone.isImsRegistered();
7125 } else {
7126 return false;
7127 }
7128 }
7129
Santos Cordon7a1885b2015-02-03 11:15:19 -08007130 @Override
7131 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007132 final long identity = Binder.clearCallingIdentity();
7133 try {
7134 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7135 } finally {
7136 Binder.restoreCallingIdentity(identity);
7137 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007138 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007139
Tyler Gunnf70ed162019-04-03 15:28:53 -07007140 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007141 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007142 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007143 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007144 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007145 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7146 }
7147 final long identity = Binder.clearCallingIdentity();
7148 try {
7149 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7150 } finally {
7151 Binder.restoreCallingIdentity(identity);
7152 }
7153 }
7154
7155 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007156 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007157 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7158 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007159 final long identity = Binder.clearCallingIdentity();
7160 try {
7161 Phone phone = getPhone(subscriptionId);
7162 if (phone == null) {
7163 return null;
7164 }
7165 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7166 } finally {
7167 Binder.restoreCallingIdentity(identity);
7168 }
7169 }
7170
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007171 /**
7172 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007173 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007174 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007175 final long identity = Binder.clearCallingIdentity();
7176 try {
7177 Phone phone = getPhone(subId);
7178 if (phone != null) {
7179 return phone.isWifiCallingEnabled();
7180 } else {
7181 return false;
7182 }
7183 } finally {
7184 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007186 }
7187
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007188 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007189 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007190 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007191 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 final long identity = Binder.clearCallingIdentity();
7193 try {
7194 Phone phone = getPhone(subId);
7195 if (phone != null) {
7196 return phone.isVideoEnabled();
7197 } else {
7198 return false;
7199 }
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007202 }
7203 }
7204
7205 /**
7206 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7207 * defined in {@link ImsRegistrationImplBase}.
7208 */
7209 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007210 final long identity = Binder.clearCallingIdentity();
7211 try {
7212 Phone phone = getPhone(subId);
7213 if (phone != null) {
7214 return phone.getImsRegistrationTech();
7215 } else {
7216 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7217 }
7218 } finally {
7219 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007220 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007221 }
7222
Stuart Scott8eef64f2015-04-08 15:13:54 -07007223 @Override
7224 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007225 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007226 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7227 return;
7228 }
7229
Svet Ganovcc087f82015-05-12 20:35:54 -07007230 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007231
Svet Ganovcc087f82015-05-12 20:35:54 -07007232 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007233 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7234 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007235 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007236 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007237 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007238 setAllowedNetworkTypesForReason(subId,
7239 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7240 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7241 setAllowedNetworkTypesForReason(subId,
7242 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7243 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7244 setAllowedNetworkTypesForReason(subId,
7245 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7246 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007247 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7248 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007249 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007250 // There has been issues when Sms raw table somehow stores orphan
7251 // fragments. They lead to garbled message when new fragments come
7252 // in and combined with those stale ones. In case this happens again,
7253 // user can reset all network settings which will clean up this table.
7254 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007255 // Clean up IMS settings as well here.
7256 int slotId = getSlotIndex(subId);
7257 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7258 ImsManager.getInstance(mApp, slotId).factoryReset();
7259 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007260
7261 // Erase modem config if erase modem on network setting is enabled.
7262 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7263 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7264 if (configValue != null && Boolean.parseBoolean(configValue)) {
7265 sendEraseModemConfig(getDefaultPhone());
7266 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007267 } finally {
7268 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007269 }
7270 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007271
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007272 private void cleanUpSmsRawTable(Context context) {
7273 ContentResolver resolver = context.getContentResolver();
7274 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7275 resolver.delete(uri, null, null);
7276 }
7277
Narayan Kamath1c496c22015-04-16 14:40:19 +01007278 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007279 public String getSimLocaleForSubscriber(int subId) {
7280 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7281 final Phone phone = getPhone(subId);
7282 if (phone == null) {
7283 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007284 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007285 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007286 final long identity = Binder.clearCallingIdentity();
7287 try {
chen xu5d3637b2019-01-21 23:31:38 -08007288 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007289 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007290 if (info == null) {
7291 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7292 return null;
7293 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007294 // Try and fetch the locale from the carrier properties or from the SIM language
7295 // preferences (EF-PL and EF-LI)...
7296 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007298 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7299 if (localeFromDefaultSim != null) {
7300 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7301 if (DBG) log("Using locale from subId: " + subId + " locale: "
7302 + localeFromDefaultSim);
7303 return localeFromDefaultSim.toLanguageTag();
7304 } else {
7305 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306 }
7307 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007308
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007309 // The SIM language preferences only store a language (e.g. fr = French), not an
7310 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7311 // the SIM and carrier preferences does not include a country we add the country
7312 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007313 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007315 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007316 return mccLocale.toLanguageTag();
7317 }
7318
7319 if (DBG) log("No locale found - returning null");
7320 return null;
7321 } finally {
7322 Binder.restoreCallingIdentity(identity);
7323 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007324 }
7325
7326 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007327 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007328 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007329 }
7330
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007331 /**
7332 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7333 */
7334 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007335 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007336 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007337 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007338
Chenjie Yu1ba97252018-01-11 18:16:20 -08007339 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007340 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007341
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007342 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007343 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7344 * representing the state of the modem.
7345 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007346 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7347 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007348 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007349 */
7350 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007351 public void requestModemActivityInfo(ResultReceiver result) {
7352 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007353 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354
7355 final long identity = Binder.clearCallingIdentity();
7356 try {
sqian1a1be542020-03-05 11:37:28 -08007357 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007358 } finally {
7359 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007360 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007361 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007362
Siddharth Rayb8114062018-06-17 15:02:38 -07007363 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7364 // less than total activity duration.
7365 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7366 if (info == null) {
7367 return false;
7368 }
7369 int activityDurationMs =
7370 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7371 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007372 int[] txTimeMs = info.getTransmitTimeMillis();
7373 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7374 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007375 }
7376 return (info.isValid()
7377 && (info.getSleepTimeMillis() <= activityDurationMs)
7378 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007379 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007380 && (totalTxTimeMs <= activityDurationMs));
7381 }
7382
Jack Yu85bd38a2015-11-09 11:34:32 -08007383 /**
7384 * {@hide}
7385 * Returns the service state information on specified subscription.
7386 */
7387 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007388 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7389 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007391 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007392 return null;
7393 }
7394
Hall Liuf19c44f2018-11-27 14:38:17 -08007395 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7396 LocationAccessPolicy.checkLocationPermission(mApp,
7397 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7398 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007399 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007400 .setCallingPid(Binder.getCallingPid())
7401 .setCallingUid(Binder.getCallingUid())
7402 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007403 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007404 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7405 .build());
7406
7407 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7408 LocationAccessPolicy.checkLocationPermission(mApp,
7409 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7410 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007411 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007412 .setCallingPid(Binder.getCallingPid())
7413 .setCallingUid(Binder.getCallingUid())
7414 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007415 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007416 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7417 .build());
7418 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7419 boolean hasFinePermission =
7420 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7421 boolean hasCoarsePermission =
7422 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7423
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007424 final long identity = Binder.clearCallingIdentity();
7425 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007426 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7427 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7428 Rlog.d(LOG_TAG,
7429 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7430 return null;
7431 }
7432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 final Phone phone = getPhone(subId);
7434 if (phone == null) {
7435 return null;
7436 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007437
Hall Liuf19c44f2018-11-27 14:38:17 -08007438 ServiceState ss = phone.getServiceState();
7439
7440 // Scrub out the location info in ServiceState depending on what level of access
7441 // the caller has.
7442 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007443 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7444 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
7447 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007448 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007449
7450 /**
7451 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7452 *
7453 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7454 * voicemail ringtone.
7455 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7456 * PhoneAccount.
7457 */
7458 @Override
7459 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007460 final long identity = Binder.clearCallingIdentity();
7461 try {
7462 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7463 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007464 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007467 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007471 }
7472
7473 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007474 * Sets the per-account voicemail ringtone.
7475 *
7476 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7477 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7478 *
7479 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7480 * voicemail ringtone.
7481 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7482 * PhoneAccount.
7483 */
7484 @Override
7485 public void setVoicemailRingtoneUri(String callingPackage,
7486 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007487 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007489 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7490 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7492 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7493 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007494 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007495
7496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7499 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007500 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007501 }
7502 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7503 } finally {
7504 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007505 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007506 }
7507
7508 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007509 * Returns whether vibration is set for voicemail notification in Phone settings.
7510 *
7511 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7512 * voicemail vibration setting.
7513 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7514 */
7515 @Override
7516 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7520 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007528 }
7529
Youhan Wange64578a2016-05-02 15:32:42 -07007530 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007531 * Sets the per-account voicemail vibration.
7532 *
7533 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7534 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7535 *
7536 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7537 * voicemail vibration setting.
7538 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7539 * specific PhoneAccount.
7540 */
7541 @Override
7542 public void setVoicemailVibrationEnabled(String callingPackage,
7543 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007545 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007546 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7547 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7549 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7550 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007551 }
7552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7556 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 }
7559 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007562 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007563 }
7564
7565 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007566 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7567 *
7568 * @throws SecurityException if the caller does not have the required permission
7569 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007570 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007571 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007572 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007573 }
7574
7575 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007576 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7577 * permission.
7578 *
7579 * @throws SecurityException if the caller does not have the required permission
7580 */
7581 private void enforceSendSmsPermission() {
7582 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7583 }
7584
7585 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007586 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007587 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007588 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007589 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007590 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 final long identity = Binder.clearCallingIdentity();
7592 try {
7593 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007594 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007595 if (componentName == null) {
7596 throw new SecurityException(
7597 "Caller not current active visual voicemail package[null]");
7598 }
7599 String vvmPackage = componentName.getPackageName();
7600 if (!callingPackage.equals(vvmPackage)) {
7601 throw new SecurityException("Caller not current active visual voicemail package["
7602 + vvmPackage + "]");
7603 }
7604 } finally {
7605 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007606 }
7607 }
7608
7609 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007610 * Return the application ID for the app type.
7611 *
7612 * @param subId the subscription ID that this request applies to.
7613 * @param appType the uicc app type.
7614 * @return Application ID for specificied app type, or null if no uicc.
7615 */
7616 @Override
7617 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007618 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007619 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007620
7621 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007622 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007623 if (phone == null) {
7624 return null;
7625 }
7626 String aid = null;
7627 try {
7628 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7629 .getApplicationByType(appType).getAid();
7630 } catch (Exception e) {
7631 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7632 }
7633 return aid;
7634 } finally {
7635 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007636 }
Youhan Wange64578a2016-05-02 15:32:42 -07007637 }
7638
Youhan Wang4001d252016-05-11 10:29:41 -07007639 /**
7640 * Return the Electronic Serial Number.
7641 *
7642 * @param subId the subscription ID that this request applies to.
7643 * @return ESN or null if error.
7644 */
7645 @Override
7646 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007647 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007648 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649
7650 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007651 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 if (phone == null) {
7653 return null;
7654 }
7655 String esn = null;
7656 try {
7657 esn = phone.getEsn();
7658 } catch (Exception e) {
7659 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7660 }
7661 return esn;
7662 } finally {
7663 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007664 }
Youhan Wang4001d252016-05-11 10:29:41 -07007665 }
7666
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007667 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007668 * Return the Preferred Roaming List Version.
7669 *
7670 * @param subId the subscription ID that this request applies to.
7671 * @return PRLVersion or null if error.
7672 */
7673 @Override
7674 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007675 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007676 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677
7678 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007679 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 if (phone == null) {
7681 return null;
7682 }
7683 String cdmaPrlVersion = null;
7684 try {
7685 cdmaPrlVersion = phone.getCdmaPrlVersion();
7686 } catch (Exception e) {
7687 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7688 }
7689 return cdmaPrlVersion;
7690 } finally {
7691 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007692 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007693 }
7694
7695 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007696 * Get snapshot of Telephony histograms
7697 * @return List of Telephony histograms
7698 * @hide
7699 */
7700 @Override
7701 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007702 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7703 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 return RIL.getTelephonyRILTimingHistograms();
7708 } finally {
7709 Binder.restoreCallingIdentity(identity);
7710 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007711 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007712
7713 /**
7714 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007715 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7716 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007717 * Require system privileges. In the future we may add this to carrier APIs.
7718 *
Michele Berionne482f8202018-11-27 18:57:59 -08007719 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007720 */
7721 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007722 @TelephonyManager.SetCarrierRestrictionResult
7723 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007724 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007725 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007726
Michele Berionne482f8202018-11-27 18:57:59 -08007727 if (carrierRestrictionRules == null) {
7728 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007729 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007730
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 final long identity = Binder.clearCallingIdentity();
7732 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007733 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007734 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007735 } finally {
7736 Binder.restoreCallingIdentity(identity);
7737 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007738 }
7739
7740 /**
7741 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007742 * Get the allowed carrier list and the excluded carrier list, including the priority between
7743 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007744 * Require system privileges. In the future we may add this to carrier APIs.
7745 *
Michele Berionne482f8202018-11-27 18:57:59 -08007746 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007747 */
7748 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007749 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007750 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007751 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007752
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007755 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7756 if (response instanceof CarrierRestrictionRules) {
7757 return (CarrierRestrictionRules) response;
7758 }
7759 // Response is an Exception of some kind,
7760 // which is signalled to the user as a NULL retval
7761 return null;
7762 } catch (Exception e) {
7763 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7764 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007768 }
7769
fionaxu59545b42016-05-25 15:53:37 -07007770 /**
fionaxu59545b42016-05-25 15:53:37 -07007771 * Action set from carrier signalling broadcast receivers to enable/disable radio
7772 * @param subId the subscription ID that this action applies to.
7773 * @param enabled control enable or disable radio.
7774 * {@hide}
7775 */
7776 @Override
7777 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7778 enforceModifyPermission();
7779 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780
7781 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007782 if (phone == null) {
7783 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7784 return;
7785 }
7786 try {
7787 phone.carrierActionSetRadioEnabled(enabled);
7788 } catch (Exception e) {
7789 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007790 } finally {
7791 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007792 }
7793 }
7794
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007795 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007796 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7797 * network status based on which carrier apps could apply actions accordingly,
7798 * enable/disable default url handler for example.
7799 *
7800 * @param subId the subscription ID that this action applies to.
7801 * @param report control start/stop reporting the default network status.
7802 * {@hide}
7803 */
7804 @Override
7805 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7806 enforceModifyPermission();
7807 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007808
7809 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007810 if (phone == null) {
7811 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7812 return;
7813 }
7814 try {
7815 phone.carrierActionReportDefaultNetworkStatus(report);
7816 } catch (Exception e) {
7817 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007818 } finally {
7819 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007820 }
7821 }
7822
7823 /**
fionaxud9622282017-07-17 17:51:30 -07007824 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7825 * @param subId the subscription ID that this action applies to.
7826 * {@hide}
7827 */
7828 @Override
7829 public void carrierActionResetAll(int subId) {
7830 enforceModifyPermission();
7831 final Phone phone = getPhone(subId);
7832 if (phone == null) {
7833 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7834 return;
7835 }
7836 try {
7837 phone.carrierActionResetAll();
7838 } catch (Exception e) {
7839 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7840 }
7841 }
7842
7843 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007844 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7845 * bug report is being generated.
7846 */
7847 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007848 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007849 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7850 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007851 writer.println("Permission Denial: can't dump Phone from pid="
7852 + Binder.getCallingPid()
7853 + ", uid=" + Binder.getCallingUid()
7854 + "without permission "
7855 + android.Manifest.permission.DUMP);
7856 return;
7857 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007858 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007859 }
Jack Yueb89b242016-06-22 13:27:47 -07007860
Brad Ebingerdac2f002018-04-03 15:17:52 -07007861 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007862 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7863 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7864 @NonNull String[] args) {
7865 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7866 this, in.getFileDescriptor(), out.getFileDescriptor(),
7867 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007868 }
7869
Jack Yueb89b242016-06-22 13:27:47 -07007870 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007871 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007872 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007873 * @param reason the reason the data enable change is taking place
7874 * @param enabled True if enabling the data, otherwise disabling.
7875 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007876 */
7877 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007878 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007879 boolean enabled) {
7880 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7881 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7882 try {
7883 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007884 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007885 } catch (SecurityException se) {
7886 enforceModifyPermission();
7887 }
7888 } else {
7889 enforceModifyPermission();
7890 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007891
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
7894 Phone phone = getPhone(subId);
7895 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007896 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7897 phone.carrierActionSetMeteredApnsEnabled(enabled);
7898 } else {
7899 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7900 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007901 }
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007904 }
7905 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007906
7907 /**
7908 * Get Client request stats
7909 * @return List of Client Request Stats
7910 * @hide
7911 */
7912 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007913 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7914 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007915 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007916 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007917 return null;
7918 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007919 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 if (phone != null) {
7924 return phone.getClientRequestStats();
7925 }
7926
7927 return null;
7928 } finally {
7929 Binder.restoreCallingIdentity(identity);
7930 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007931 }
7932
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007933 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007934 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007935 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007936 }
Jack Yueb4124c2017-02-16 15:32:43 -08007937
7938 /**
Grace Chen70990072017-03-24 17:21:30 -07007939 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007940 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007941 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007942 * @param state State of SIM (power down, power up, pass through)
7943 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7944 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7945 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007946 *
7947 **/
7948 @Override
Grace Chen70990072017-03-24 17:21:30 -07007949 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007950 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007951 Phone phone = PhoneFactory.getPhone(slotIndex);
7952
vagdeviaf9a5b92018-08-15 16:01:53 -07007953 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007955 final long identity = Binder.clearCallingIdentity();
7956 try {
7957 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007958 phone.setSimPowerState(state, null, workSource);
7959 }
7960 } finally {
7961 Binder.restoreCallingIdentity(identity);
7962 }
7963 }
7964
7965 /**
7966 * Set SIM card power state.
7967 *
7968 * @param slotIndex SIM slot id.
7969 * @param state State of SIM (power down, power up, pass through)
7970 * @param callback callback to trigger after success or failure
7971 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7972 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7973 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7974 *
7975 **/
7976 @Override
7977 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7978 IIntegerConsumer callback) {
7979 enforceModifyPermission();
7980 Phone phone = PhoneFactory.getPhone(slotIndex);
7981
7982 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7983
7984 final long identity = Binder.clearCallingIdentity();
7985 try {
7986 if (phone != null) {
7987 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7988 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007989 }
7990 } finally {
7991 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007992 }
7993 }
Shuo Qiandd210312017-04-12 22:11:33 +00007994
Tyler Gunn65d45c22017-06-05 11:22:26 -07007995 private boolean isUssdApiAllowed(int subId) {
7996 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007997 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007998 if (configManager == null) {
7999 return false;
8000 }
8001 PersistableBundle pb = configManager.getConfigForSubId(subId);
8002 if (pb == null) {
8003 return false;
8004 }
8005 return pb.getBoolean(
8006 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8007 }
8008
Shuo Qiandd210312017-04-12 22:11:33 +00008009 /**
8010 * Check if phone is in emergency callback mode
8011 * @return true if phone is in emergency callback mode
8012 * @param subId sub id
8013 */
goneil9c5f4872017-12-05 14:07:56 -08008014 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008015 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008016 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008017 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008018
8019 final long identity = Binder.clearCallingIdentity();
8020 try {
8021 if (phone != null) {
8022 return phone.isInEcm();
8023 } else {
8024 return false;
8025 }
8026 } finally {
8027 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008028 }
8029 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008030
8031 /**
8032 * Get the current signal strength information for the given subscription.
8033 * Because this information is not updated when the device is in a low power state
8034 * it should not be relied-upon to be current.
8035 * @param subId Subscription index
8036 * @return the most recent cached signal strength info from the modem
8037 */
8038 @Override
8039 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008040 final long identity = Binder.clearCallingIdentity();
8041 try {
8042 Phone p = getPhone(subId);
8043 if (p == null) {
8044 return null;
8045 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008046
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008047 return p.getSignalStrength();
8048 } finally {
8049 Binder.restoreCallingIdentity(identity);
8050 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008051 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008052
Pengquan Meng77b7f132018-08-22 14:49:57 -07008053 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008054 * Get the current modem radio state for the given slot.
8055 * @param slotIndex slot index.
8056 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008057 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008058 * @return the current radio power state from the modem
8059 */
8060 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008061 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008062 Phone phone = PhoneFactory.getPhone(slotIndex);
8063 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008064 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8065 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008066 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8067 }
8068
8069 final long identity = Binder.clearCallingIdentity();
8070 try {
8071 return phone.getRadioPowerState();
8072 } finally {
8073 Binder.restoreCallingIdentity(identity);
8074 }
8075 }
8076 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8077 }
8078
8079 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008080 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8081 *
8082 * <p>Requires one of the following permissions:
8083 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8084 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8085 * privileges.
8086 *
8087 * @param subId subscription id
8088 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8089 * {@code false}.
8090 */
8091 @Override
8092 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008093 try {
8094 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8095 null);
8096 } catch (Exception e) {
8097 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8098 mApp, subId, "isDataRoamingEnabled");
8099 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008100
Pengquan Menga1bb6272018-09-06 09:59:22 -07008101 boolean isEnabled = false;
8102 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008103 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008104 Phone phone = getPhone(subId);
8105 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008106 } finally {
8107 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008108 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008109 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008110 }
8111
8112
8113 /**
8114 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8115 *
8116 * <p> Requires permission:
8117 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8118 * privileges.
8119 *
8120 * @param subId subscription id
8121 * @param isEnabled {@code true} means enable, {@code false} means disable.
8122 */
8123 @Override
8124 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008125 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8126 mApp, subId, "setDataRoamingEnabled");
8127
Pengquan Menga1bb6272018-09-06 09:59:22 -07008128 final long identity = Binder.clearCallingIdentity();
8129 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008130 Phone phone = getPhone(subId);
8131 if (phone != null) {
8132 phone.setDataRoamingEnabled(isEnabled);
8133 }
8134 } finally {
8135 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008136 }
8137 }
8138
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008139 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008140 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008141 TelephonyPermissions
8142 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008143 mApp, subId, "isManualNetworkSelectionAllowed");
8144
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008145 boolean isAllowed = true;
8146 final long identity = Binder.clearCallingIdentity();
8147 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008148 Phone phone = getPhone(subId);
8149 if (phone != null) {
8150 isAllowed = phone.isCspPlmnEnabled();
8151 }
8152 } finally {
8153 Binder.restoreCallingIdentity(identity);
8154 }
8155 return isAllowed;
8156 }
8157
8158 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008159 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008160 // Verify that tha callingPackage belongs to the calling UID
8161 mApp.getSystemService(AppOpsManager.class)
8162 .checkPackage(Binder.getCallingUid(), callingPackage);
8163
Jordan Liu1e142fc2019-04-22 15:10:43 -07008164 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008165 try {
8166 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008167 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008168 } catch (SecurityException e) {
8169 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8170 // has carrier privileges on an active UICC
8171 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8172 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008173 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008174 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008175 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008176
8177 final long identity = Binder.clearCallingIdentity();
8178 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008179 UiccController uiccController = UiccController.getInstance();
8180 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008181 if (hasReadPermission) {
8182 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008183 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008184
8185 // Remove private info if the caller doesn't have access
8186 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8187 for (UiccCardInfo cardInfo : cardInfos) {
8188 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8189 // is available
8190 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8191 if (card == null || card.getUiccProfile() == null) {
8192 // assume no access if the card or profile is unavailable
8193 filteredInfos.add(cardInfo.getUnprivileged());
8194 continue;
8195 }
8196 UiccProfile profile = card.getUiccProfile();
8197 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8198 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8199 filteredInfos.add(cardInfo);
8200 } else {
8201 filteredInfos.add(cardInfo.getUnprivileged());
8202 }
8203 }
8204 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 }
8209
8210 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008211 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008212 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008214 final long identity = Binder.clearCallingIdentity();
8215 try {
8216 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8217 if (slots == null) {
8218 Rlog.i(LOG_TAG, "slots is null.");
8219 return null;
8220 }
8221
8222 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8223 for (int i = 0; i < slots.length; i++) {
8224 UiccSlot slot = slots[i];
8225 if (slot == null) {
8226 continue;
8227 }
8228
Jordan Liu7be7e652019-05-06 18:55:02 +00008229 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008230 UiccCard card = slot.getUiccCard();
8231 if (card != null) {
8232 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008233 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008234 cardId = slot.getEid();
8235 if (TextUtils.isEmpty(cardId)) {
8236 cardId = slot.getIccId();
8237 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008238 }
8239
Jordan Liu857451f2019-05-09 16:35:35 -07008240 if (cardId != null) {
8241 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8242 // if cardId is an EID, it's all digits so this is fine
8243 cardId = IccUtils.stripTrailingFs(cardId);
8244 }
8245
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008246 int cardState = 0;
8247 switch (slot.getCardState()) {
8248 case CARDSTATE_ABSENT:
8249 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8250 break;
8251 case CARDSTATE_PRESENT:
8252 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8253 break;
8254 case CARDSTATE_ERROR:
8255 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8256 break;
8257 case CARDSTATE_RESTRICTED:
8258 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8259 break;
8260 default:
8261 break;
8262
8263 }
8264
8265 infos[i] = new UiccSlotInfo(
8266 slot.isActive(),
8267 slot.isEuicc(),
8268 cardId,
8269 cardState,
8270 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008271 slot.isExtendedApduSupported(),
8272 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008273 }
8274 return infos;
8275 } finally {
8276 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008277 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008278 }
8279
8280 @Override
8281 public boolean switchSlots(int[] physicalSlots) {
8282 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008283
8284 final long identity = Binder.clearCallingIdentity();
8285 try {
8286 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008290 }
Jack Yu4c988042018-02-27 15:30:01 -08008291
8292 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008293 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008294 final long identity = Binder.clearCallingIdentity();
8295 try {
8296 return UiccController.getInstance().getCardIdForDefaultEuicc();
8297 } finally {
8298 Binder.restoreCallingIdentity(identity);
8299 }
8300 }
8301
Pengquan Meng85728fb2018-03-12 16:31:21 -07008302 /**
goneil47ffb6e2018-04-06 15:40:58 -07008303 * A test API to reload the UICC profile.
8304 *
8305 * <p>Requires that the calling app has permission
8306 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8307 * @hide
8308 */
8309 @Override
8310 public void refreshUiccProfile(int subId) {
8311 enforceModifyPermission();
8312
8313 final long identity = Binder.clearCallingIdentity();
8314 try {
8315 Phone phone = getPhone(subId);
8316 if (phone == null) {
8317 return;
8318 }
8319 UiccCard uiccCard = phone.getUiccCard();
8320 if (uiccCard == null) {
8321 return;
8322 }
8323 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8324 if (uiccProfile == null) {
8325 return;
8326 }
8327 uiccProfile.refresh();
8328 } finally {
8329 Binder.restoreCallingIdentity(identity);
8330 }
8331 }
8332
8333 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008334 * Returns false if the mobile data is disabled by default, otherwise return true.
8335 */
8336 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008337 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008338 }
8339
8340 /**
8341 * Returns true if the data roaming is enabled by default, i.e the system property
8342 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8343 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8344 */
8345 private boolean getDefaultDataRoamingEnabled(int subId) {
8346 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008347 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008348 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008349 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8350 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8351 return isDataRoamingEnabled;
8352 }
8353
8354 /**
8355 * Returns the default network type for the given {@code subId}, if the default network type is
8356 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8357 */
8358 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008359 List<Integer> list = TelephonyProperties.default_network();
8360 int phoneId = mSubscriptionController.getPhoneId(subId);
8361 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8362 return list.get(phoneId);
8363 }
8364 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008365 }
fionaxua13278b2018-03-21 00:08:13 -07008366
8367 @Override
8368 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008369 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008370 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008371
8372 final long identity = Binder.clearCallingIdentity();
8373 try {
8374 final Phone phone = getPhone(subId);
8375 if (phone == null) {
8376 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8377 return;
8378 }
chen xueaba88a2019-03-15 13:15:10 -07008379 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8380 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008381 if (carrierPrivilegeRules == null) {
8382 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8383 } else {
8384 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8385 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008386 } finally {
8387 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008388 }
fionaxua13278b2018-03-21 00:08:13 -07008389 }
8390
8391 @Override
8392 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008393 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008394
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
8397 final Phone phone = getPhone(subId);
8398 if (phone == null) {
8399 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8400 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8401 }
8402 return phone.getCarrierIdListVersion();
8403 } finally {
8404 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008405 }
fionaxua13278b2018-03-21 00:08:13 -07008406 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008407
8408 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008409 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8410 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008411 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008412 mApp, subId, callingPackage, callingFeatureId,
8413 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008414 return -1;
8415 }
8416
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008424
8425 @Override
8426 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008427 TelephonyPermissions
8428 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008429 mApp, subId, "getCdmaRoamingMode");
8430
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8434 } finally {
8435 Binder.restoreCallingIdentity(identity);
8436 }
8437 }
8438
8439 @Override
8440 public boolean setCdmaRoamingMode(int subId, int mode) {
8441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8442 mApp, subId, "setCdmaRoamingMode");
8443
8444 final long identity = Binder.clearCallingIdentity();
8445 try {
8446 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8447 } finally {
8448 Binder.restoreCallingIdentity(identity);
8449 }
8450 }
8451
8452 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008453 public int getCdmaSubscriptionMode(int subId) {
8454 TelephonyPermissions
8455 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8456 mApp, subId, "getCdmaSubscriptionMode");
8457
8458 final long identity = Binder.clearCallingIdentity();
8459 try {
8460 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8461 } finally {
8462 Binder.restoreCallingIdentity(identity);
8463 }
8464 }
8465
8466 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008467 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8468 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8469 mApp, subId, "setCdmaSubscriptionMode");
8470
8471 final long identity = Binder.clearCallingIdentity();
8472 try {
8473 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8474 } finally {
8475 Binder.restoreCallingIdentity(identity);
8476 }
8477 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008478
sqianc5eccab2018-10-19 18:46:41 -07008479 @Override
sqian8c685422019-02-22 15:55:18 -08008480 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008481 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008482 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008483 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8484 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008485 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8486 }
8487 final long identity = Binder.clearCallingIdentity();
8488 try {
sqian854d44b2018-12-12 16:48:18 -08008489 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8490 for (Phone phone: PhoneFactory.getPhones()) {
8491 if (phone.getEmergencyNumberTracker() != null
8492 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8493 emergencyNumberListInternal.put(
8494 phone.getSubId(),
8495 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8496 }
sqian11b7a0e2018-12-05 18:48:28 -08008497 }
sqian854d44b2018-12-12 16:48:18 -08008498 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008499 } finally {
8500 Binder.restoreCallingIdentity(identity);
8501 }
sqianc5eccab2018-10-19 18:46:41 -07008502 }
8503
8504 @Override
sqian8c685422019-02-22 15:55:18 -08008505 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008506 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008507 if (!exactMatch) {
8508 TelephonyPermissions
8509 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008510 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008511 }
8512 final long identity = Binder.clearCallingIdentity();
8513 try {
sqian854d44b2018-12-12 16:48:18 -08008514 for (Phone phone: PhoneFactory.getPhones()) {
8515 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008516 && phone.getEmergencyNumberTracker()
8517 .isEmergencyNumber(number, exactMatch)) {
8518 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008519 }
sqian11b7a0e2018-12-05 18:48:28 -08008520 }
8521 return false;
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
8524 }
8525 }
8526
sqianf4ca7ed2019-01-15 18:32:07 -08008527 /**
8528 * Update emergency number list for test mode.
8529 */
8530 @Override
8531 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8532 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8533 "updateEmergencyNumberListTestMode");
8534
8535 final long identity = Binder.clearCallingIdentity();
8536 try {
8537 for (Phone phone: PhoneFactory.getPhones()) {
8538 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8539 if (tracker != null) {
8540 tracker.executeEmergencyNumberTestModeCommand(action, num);
8541 }
8542 }
8543 } finally {
8544 Binder.restoreCallingIdentity(identity);
8545 }
8546 }
8547
8548 /**
8549 * Get the full emergency number list for test mode.
8550 */
8551 @Override
8552 public List<String> getEmergencyNumberListTestMode() {
8553 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8554 "getEmergencyNumberListTestMode");
8555
8556 final long identity = Binder.clearCallingIdentity();
8557 try {
8558 Set<String> emergencyNumbers = new HashSet<>();
8559 for (Phone phone: PhoneFactory.getPhones()) {
8560 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8561 if (tracker != null) {
8562 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8563 emergencyNumbers.add(num.getNumber());
8564 }
8565 }
8566 }
8567 return new ArrayList<>(emergencyNumbers);
8568 } finally {
8569 Binder.restoreCallingIdentity(identity);
8570 }
8571 }
8572
chen xud6b45bd2018-10-30 22:27:10 -07008573 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008574 public int getEmergencyNumberDbVersion(int subId) {
8575 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8576
8577 final long identity = Binder.clearCallingIdentity();
8578 try {
8579 final Phone phone = getPhone(subId);
8580 if (phone == null) {
8581 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8582 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8583 }
8584 return phone.getEmergencyNumberDbVersion();
8585 } finally {
8586 Binder.restoreCallingIdentity(identity);
8587 }
8588 }
8589
8590 @Override
8591 public void notifyOtaEmergencyNumberDbInstalled() {
8592 enforceModifyPermission();
8593
8594 final long identity = Binder.clearCallingIdentity();
8595 try {
8596 for (Phone phone: PhoneFactory.getPhones()) {
8597 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8598 if (tracker != null) {
8599 tracker.updateOtaEmergencyNumberDatabase();
8600 }
8601 }
8602 } finally {
8603 Binder.restoreCallingIdentity(identity);
8604 }
8605 }
8606
8607 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008608 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008609 enforceActiveEmergencySessionPermission();
8610
8611 final long identity = Binder.clearCallingIdentity();
8612 try {
8613 for (Phone phone: PhoneFactory.getPhones()) {
8614 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8615 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008616 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8617 }
8618 }
8619 } finally {
8620 Binder.restoreCallingIdentity(identity);
8621 }
8622 }
8623
8624 @Override
8625 public void resetOtaEmergencyNumberDbFilePath() {
8626 enforceActiveEmergencySessionPermission();
8627
8628 final long identity = Binder.clearCallingIdentity();
8629 try {
8630 for (Phone phone: PhoneFactory.getPhones()) {
8631 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8632 if (tracker != null) {
8633 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008634 }
8635 }
8636 } finally {
8637 Binder.restoreCallingIdentity(identity);
8638 }
8639 }
8640
8641 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008642 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8643 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8644 Phone phone = getPhone(subId);
8645 if (phone == null) {
8646 return null;
8647 }
8648 final long identity = Binder.clearCallingIdentity();
8649 try {
8650 UiccProfile profile = UiccController.getInstance()
8651 .getUiccProfileForPhone(phone.getPhoneId());
8652 if (profile != null) {
8653 return profile.getCertsFromCarrierPrivilegeAccessRules();
8654 }
8655 } finally {
8656 Binder.restoreCallingIdentity(identity);
8657 }
8658 return null;
8659 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008660
8661 /**
8662 * Enable or disable a modem stack.
8663 */
8664 @Override
8665 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8666 enforceModifyPermission();
8667
8668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 Phone phone = PhoneFactory.getPhone(slotIndex);
8671 if (phone == null) {
8672 return false;
8673 } else {
8674 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8675 }
8676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
8679 }
Michelecea4cf22018-12-21 15:00:11 -08008680
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008681 /**
8682 * Whether a modem stack is enabled or not.
8683 */
8684 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008685 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8686 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008687 Phone phone = PhoneFactory.getPhone(slotIndex);
8688 if (phone == null) return false;
8689
8690 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008691 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8692 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008693 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8694 }
8695
8696 final long identity = Binder.clearCallingIdentity();
8697 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008698 try {
8699 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8700 } catch (NoSuchElementException ex) {
8701 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8702 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008703 } finally {
8704 Binder.restoreCallingIdentity(identity);
8705 }
8706 }
8707
Michelecea4cf22018-12-21 15:00:11 -08008708 @Override
Michele0ea7d782019-03-19 14:58:42 -07008709 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008710 enforceModifyPermission();
8711
8712 final long identity = Binder.clearCallingIdentity();
8713 try {
8714 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008715 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008716 .commit();
8717 } finally {
8718 Binder.restoreCallingIdentity(identity);
8719 }
8720 }
8721
8722 @Override
Michele0ea7d782019-03-19 14:58:42 -07008723 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008724 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008726 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8727 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008728 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008729 }
Michelecea4cf22018-12-21 15:00:11 -08008730
8731 final long identity = Binder.clearCallingIdentity();
8732 try {
Michele0ea7d782019-03-19 14:58:42 -07008733 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008734 } finally {
8735 Binder.restoreCallingIdentity(identity);
8736 }
8737 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008738
Michele0ea7d782019-03-19 14:58:42 -07008739 @TelephonyManager.IsMultiSimSupportedResult
8740 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008741 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8742 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8743 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008744 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8745 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008746 }
8747 // Check if the hardware supports multisim functionality. If usage of multisim is not
8748 // supported by the modem, indicate that it is restricted.
8749 PhoneCapability staticCapability =
8750 mPhoneConfigurationManager.getStaticPhoneCapability();
8751 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008752 loge("isMultiSimSupportedInternal: no static configuration available");
8753 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008754 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008755 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008756 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8757 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008758 }
8759 // Check if support of multiple SIMs is restricted by carrier
8760 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008761 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008762 }
8763
Michele0ea7d782019-03-19 14:58:42 -07008764 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008765 }
8766
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008767 /**
8768 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008769 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8770 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8771 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008772 * @param numOfSims number of active sims we want to switch to
8773 */
8774 @Override
8775 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008776 if (numOfSims == 1) {
8777 enforceModifyPermission();
8778 } else {
8779 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8780 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8781 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008782 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008783
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008784 try {
Michele30b57b22019-03-01 12:01:14 -08008785 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008786 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008787 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8788 return;
8789 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008790 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8791 } finally {
8792 Binder.restoreCallingIdentity(identity);
8793 }
8794 }
8795
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008796 @Override
8797 public boolean isApplicationOnUicc(int subId, int appType) {
8798 enforceReadPrivilegedPermission("isApplicationOnUicc");
8799 Phone phone = getPhone(subId);
8800 if (phone == null) {
8801 return false;
8802 }
8803 final long identity = Binder.clearCallingIdentity();
8804 try {
8805 UiccCard uiccCard = phone.getUiccCard();
8806 if (uiccCard == null) {
8807 return false;
8808 }
8809 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8810 if (uiccProfile == null) {
8811 return false;
8812 }
8813 if (TelephonyManager.APPTYPE_SIM <= appType
8814 && appType <= TelephonyManager.APPTYPE_ISIM) {
8815 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8816 }
8817 return false;
8818 } finally {
8819 Binder.restoreCallingIdentity(identity);
8820 }
8821 }
8822
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008823 /**
chen xub4baa772019-04-03 10:23:41 -07008824 * Get whether making changes to modem configurations will trigger reboot.
8825 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008826 */
8827 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008828 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8829 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008831 mApp, subId, callingPackage, callingFeatureId,
8832 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008833 return false;
8834 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008835 final long identity = Binder.clearCallingIdentity();
8836 try {
8837 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8838 } finally {
8839 Binder.restoreCallingIdentity(identity);
8840 }
8841 }
8842
Nathan Harold29f5f052019-02-15 13:41:57 -08008843 private void updateModemStateMetrics() {
8844 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8845 // TODO: check the state for each modem if the api is ready.
8846 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8847 }
8848
Pengquan Meng3889a572019-01-23 11:16:29 -08008849 @Override
8850 public int[] getSlotsMapping() {
8851 enforceReadPrivilegedPermission("getSlotsMapping");
8852
8853 final long identity = Binder.clearCallingIdentity();
8854 try {
8855 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8856 // All logical slots should have a mapping to a physical slot.
8857 int[] logicalSlotsMapping = new int[phoneCount];
8858 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8859 for (int i = 0; i < slotInfos.length; i++) {
8860 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8861 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8862 }
8863 }
8864 return logicalSlotsMapping;
8865 } finally {
8866 Binder.restoreCallingIdentity(identity);
8867 }
8868 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008869
8870 /**
8871 * Get the IRadio HAL Version
8872 */
8873 @Override
8874 public int getRadioHalVersion() {
8875 Phone phone = getDefaultPhone();
8876 if (phone == null) return -1;
8877 HalVersion hv = phone.getHalVersion();
8878 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8879 return hv.major * 100 + hv.minor;
8880 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008881
8882 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008883 * Get the current calling package name.
8884 * @return the current calling package name
8885 */
8886 @Override
8887 public String getCurrentPackageName() {
8888 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8889 }
8890
8891 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008892 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8893 * corresponding network requests on a subId.
8894 *
8895 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008896 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008897 * 2) APN is un-metered for this subscription, or
8898 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008899 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008900 *
8901 * @return whether data is allowed for a apn type.
8902 *
8903 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008904 */
8905 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008906 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008907 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8908 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008909
8910 // Now that all security checks passes, perform the operation as ourselves.
8911 final long identity = Binder.clearCallingIdentity();
8912 try {
8913 Phone phone = getPhone(subId);
8914 if (phone == null) return false;
8915
Jack Yu41407ee2019-05-13 16:54:09 -07008916 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008917 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8918 } finally {
8919 Binder.restoreCallingIdentity(identity);
8920 }
8921 }
8922
8923 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008924 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008925 enforceReadPrivilegedPermission("isApnMetered");
8926
8927 // Now that all security checks passes, perform the operation as ourselves.
8928 final long identity = Binder.clearCallingIdentity();
8929 try {
8930 Phone phone = getPhone(subId);
8931 if (phone == null) return true; // By default return true.
8932
Jack Yu41407ee2019-05-13 16:54:09 -07008933 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008934 } finally {
8935 Binder.restoreCallingIdentity(identity);
8936 }
8937 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008938
8939 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008940 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8941 int subscriptionId, IBooleanConsumer resultCallback) {
8942 enforceModifyPermission();
8943 long token = Binder.clearCallingIdentity();
8944 try {
8945 Phone phone = getPhone(subscriptionId);
8946 if (phone == null) {
8947 try {
8948 if (resultCallback != null) {
8949 resultCallback.accept(false);
8950 }
8951 } catch (RemoteException e) {
8952 // ignore
8953 }
8954 return;
8955 }
8956 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8957 Pair.create(specifiers, (x) -> {
8958 try {
8959 if (resultCallback != null) {
8960 resultCallback.accept(x);
8961 }
8962 } catch (RemoteException e) {
8963 // ignore
8964 }
8965 });
8966 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8967 } finally {
8968 Binder.restoreCallingIdentity(token);
8969 }
8970 }
8971
8972 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008973 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8974 TelephonyPermissions
8975 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8976 mApp, subId, "getSystemSelectionChannels");
8977 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8978 final long identity = Binder.clearCallingIdentity();
8979 try {
8980 List<RadioAccessSpecifier> specifiers =
8981 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8982 null, subId, workSource);
8983 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8984 return specifiers;
8985 } finally {
8986 Binder.restoreCallingIdentity(identity);
8987 }
8988 }
8989
8990 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008991 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008992 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008993 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8994 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8995 if (iccRecords == null) {
8996 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8997 return false;
8998 }
8999 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9000 }
9001
9002 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009003 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9004 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009005 if (callingPackage == null) {
9006 callingPackage = getCurrentPackageName();
9007 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009008 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9009 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009010 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9011 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009012 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9013 }
9014 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9015 Intent intent = new Intent();
9016 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9017 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9018 // Bring up choose default SMS subscription dialog right now
9019 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9020 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9021 mApp.startActivity(intent);
9022 }
chen xud5ca2d52019-05-28 15:20:57 -07009023
9024 @Override
9025 public String getMmsUAProfUrl(int subId) {
9026 //TODO investigate if this API should require proper permission check in R b/133791609
9027 final long identity = Binder.clearCallingIdentity();
9028 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009029 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9030 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9031 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9032 return carrierUAProfUrl;
9033 }
chen xud5ca2d52019-05-28 15:20:57 -07009034 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9035 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9036 } finally {
9037 Binder.restoreCallingIdentity(identity);
9038 }
9039 }
9040
9041 @Override
9042 public String getMmsUserAgent(int subId) {
9043 //TODO investigate if this API should require proper permission check in R b/133791609
9044 final long identity = Binder.clearCallingIdentity();
9045 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009046 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9047 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9048 if (!TextUtils.isEmpty(carrierUserAgent)) {
9049 return carrierUserAgent;
9050 }
chen xud5ca2d52019-05-28 15:20:57 -07009051 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9052 .getString(com.android.internal.R.string.config_mms_user_agent);
9053 } finally {
9054 Binder.restoreCallingIdentity(identity);
9055 }
9056 }
Jack Yub07d4972019-05-28 16:12:25 -07009057
9058 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009059 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9060 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9061
9062 final long identity = Binder.clearCallingIdentity();
9063 try {
9064 Phone phone = getPhone(subscriptionId);
9065 if (phone == null) return false;
9066
9067 switch (policy) {
9068 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9069 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9070 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9071 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9072 default:
9073 throw new IllegalArgumentException(policy + " is not a valid policy");
9074 }
9075 } finally {
9076 Binder.restoreCallingIdentity(identity);
9077 }
9078 }
9079
9080 @Override
9081 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9082 boolean enabled) {
9083 enforceModifyPermission();
9084
9085 final long identity = Binder.clearCallingIdentity();
9086 try {
9087 Phone phone = getPhone(subscriptionId);
9088 if (phone == null) return;
9089
9090 switch (policy) {
9091 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9092 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9093 break;
9094 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9095 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9096 break;
9097 default:
9098 throw new IllegalArgumentException(policy + " is not a valid policy");
9099 }
9100 } finally {
9101 Binder.restoreCallingIdentity(identity);
9102 }
9103 }
9104
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009105 /**
Hall Liub48cf452020-09-25 11:13:49 -07009106 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009107 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9108 * otherwise.
9109 */
9110 @Override
9111 public void setCepEnabled(boolean isCepEnabled) {
9112 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9113
9114 final long identity = Binder.clearCallingIdentity();
9115 try {
9116 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9117 for (Phone phone : PhoneFactory.getPhones()) {
9118 Phone defaultPhone = phone.getImsPhone();
9119 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9120 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9121 ImsPhoneCallTracker imsPhoneCallTracker =
9122 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9123 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9124 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9125 + imsPhone.getMsisdn());
9126 }
9127 }
9128 } finally {
9129 Binder.restoreCallingIdentity(identity);
9130 }
9131 }
allenwtsu46dcc572020-01-08 18:24:03 +08009132
9133 /**
9134 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9135 *
9136 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9137 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9138 * before being read.
9139 */
9140 @Override
9141 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9142 isCompressed) {
9143 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9144 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9146 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9147 }
9148 if (!isImsAvailableOnDevice()) {
9149 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9150 "IMS not available on device.");
9151 }
9152
9153 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009154 try {
Hui Wang068ab862020-10-31 05:12:53 +00009155 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9156 } finally {
9157 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009158 }
9159 }
zoey chenf95ca592019-12-30 16:11:23 +08009160
9161 @Override
9162 public boolean isIccLockEnabled(int subId) {
9163 enforceReadPrivilegedPermission("isIccLockEnabled");
9164
9165 // Now that all security checks passes, perform the operation as ourselves.
9166 final long identity = Binder.clearCallingIdentity();
9167 try {
9168 Phone phone = getPhone(subId);
9169 if (phone != null && phone.getIccCard() != null) {
9170 return phone.getIccCard().getIccLockEnabled();
9171 } else {
9172 return false;
9173 }
9174 } finally {
9175 Binder.restoreCallingIdentity(identity);
9176 }
9177 }
9178
9179 /**
zoey chene02881a2019-12-30 16:11:23 +08009180 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009181 *
zoey chene02881a2019-12-30 16:11:23 +08009182 * @return an integer representing the status of IccLock enabled or disabled in the following
9183 * three cases:
9184 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9185 * successfully.
9186 * - Positive number and zero for remaining password attempts.
9187 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009188 *
9189 */
9190 @Override
9191 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9192 enforceModifyPermission();
9193
9194 Phone phone = getPhone(subId);
9195 if (phone == null) {
9196 return 0;
9197 }
9198 // Now that all security checks passes, perform the operation as ourselves.
9199 final long identity = Binder.clearCallingIdentity();
9200 try {
9201 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9202 new Pair<Boolean, String>(enabled, password), phone, null);
9203 return attemptsRemaining;
9204
9205 } catch (Exception e) {
9206 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9207 } finally {
9208 Binder.restoreCallingIdentity(identity);
9209 }
9210 return 0;
9211 }
9212
9213 /**
9214 * Change the ICC password used in ICC pin lock.
9215 *
zoey chene02881a2019-12-30 16:11:23 +08009216 * @return an integer representing the status of IccLock changed in the following three cases:
9217 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9218 * - Positive number and zero for remaining password attempts.
9219 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009220 *
9221 */
9222 @Override
9223 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9224 enforceModifyPermission();
9225
9226 Phone phone = getPhone(subId);
9227 if (phone == null) {
9228 return 0;
9229 }
9230 // Now that all security checks passes, perform the operation as ourselves.
9231 final long identity = Binder.clearCallingIdentity();
9232 try {
9233 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9234 new Pair<String, String>(oldPassword, newPassword), phone, null);
9235 return attemptsRemaining;
9236
9237 } catch (Exception e) {
9238 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9239 } finally {
9240 Binder.restoreCallingIdentity(identity);
9241 }
9242 return 0;
9243 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009244
Peter Wangdafb9ac2020-01-15 14:13:38 -08009245 /**
9246 * Request for receiving user activity notification
9247 */
9248 @Override
9249 public void requestUserActivityNotification() {
9250 if (!mNotifyUserActivity.get()
9251 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9252 mNotifyUserActivity.set(true);
9253 }
9254 }
9255
9256 /**
9257 * Called when userActivity is signalled in the power manager.
9258 * This is safe to call from any thread, with any window manager locks held or not.
9259 */
9260 @Override
9261 public void userActivity() {
9262 // ***************************************
9263 // * Inherited from PhoneWindowManager *
9264 // ***************************************
9265 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9266 // WITH ITS LOCKS HELD.
9267 //
9268 // This code must be VERY careful about the locks
9269 // it acquires.
9270 // In fact, the current code acquires way too many,
9271 // and probably has lurking deadlocks.
9272
9273 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9274 throw new SecurityException("Only the OS may call notifyUserActivity()");
9275 }
9276
9277 if (mNotifyUserActivity.getAndSet(false)) {
9278 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9279 USER_ACTIVITY_NOTIFICATION_DELAY);
9280 }
9281 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009282
Malcolm Chen884180b2020-04-13 11:59:40 -07009283 @Override
9284 public boolean canConnectTo5GInDsdsMode() {
9285 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9286 }
Jack Yud10cdd42020-09-28 20:28:01 -07009287
9288 @Override
9289 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9290 String callingFeatureId) {
9291 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9292 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9293 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9294 }
9295
9296 Phone phone = getPhone(subId);
9297 if (phone == null) {
9298 throw new RuntimeException("phone is not available");
9299 }
9300 // Now that all security checks passes, perform the operation as ourselves.
9301 final long identity = Binder.clearCallingIdentity();
9302 try {
9303 return phone.getEquivalentHomePlmns();
9304 } finally {
9305 Binder.restoreCallingIdentity(identity);
9306 }
9307 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009308
Hui Wang0866fcc2020-10-12 12:14:23 -07009309 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009310 public boolean isRadioInterfaceCapabilitySupported(
9311 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009312 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009313 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9314 if (radioInterfaceCapabilities == null) {
9315 throw new RuntimeException("radio interface capabilities are not available");
9316 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009317 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009318 }
9319 }
9320
9321 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009322 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9323 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009324 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9325 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9326 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9327 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9328 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009329 if (DBG) {
9330 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9331 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9332 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9333 }
9334
9335 if (!SubscriptionManager.isValidSubscriptionId(subId)
9336 || appType < TelephonyManager.APPTYPE_UNKNOWN
9337 || appType > TelephonyManager.APPTYPE_ISIM
9338 || nafUrl == null || securityProtocol == null || callback == null) {
9339 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9340 if (callback != null) {
9341 try {
9342 callback.onAuthenticationFailure(
9343 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9344 } catch (RemoteException exception) {
9345 log("Fail to notify onAuthenticationFailure due to " + exception);
9346 }
9347 return;
9348 }
9349 }
9350
9351 final long token = Binder.clearCallingIdentity();
9352 try {
9353 getGbaManager(subId).bootstrapAuthenticationRequest(
9354 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9355 forceBootStrapping, callback));
9356 } finally {
9357 Binder.restoreCallingIdentity(token);
9358 }
9359 }
9360
Jack Nudelman24d51a52020-11-24 12:08:04 -08009361 /**
9362 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9363 * requested radio power state will actually be set. See {@link
9364 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9365 *
9366 * @param subId the subscription ID of the phone requesting to set the radio power state.
9367 * @param enable {@code true} if trying to turn radio on.
9368 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9369 * false}.
9370 */
9371 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9372 Phone phone = getPhone(subId);
9373 if (phone != null) {
9374 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9375 return true;
9376 }
9377 return false;
9378 }
9379
9380 private int handleDataThrottlingRequest(int subId,
9381 DataThrottlingRequest dataThrottlingRequest) {
9382 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9383 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9384 if (!setRadioPowerForThermal(subId, true)) {
9385 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9386 }
9387
9388 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9389
9390 int thermalMitigationResult =
9391 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9392 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9393 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9394 }
9395 return thermalMitigationResult;
9396 }
9397
9398 /**
9399 * Thermal mitigation request to control functionalities at modem.
9400 *
9401 * @param subId the id of the subscription.
9402 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9403 *
9404 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9405 */
9406 @Override
9407 @ThermalMitigationResult
9408 public int sendThermalMitigationRequest(
9409 int subId,
9410 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9411 enforceModifyPermission();
9412
9413 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9414 final long identity = Binder.clearCallingIdentity();
9415
9416 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9417 try {
9418 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9419 switch (thermalMitigationAction) {
9420 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9421 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009422 handleDataThrottlingRequest(subId,
9423 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009424 break;
9425 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9426 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9427 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9428 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9429 }
9430
9431 // Ensure that radio is on. If not able to power on due to phone being
9432 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9433 if (!setRadioPowerForThermal(subId, true)) {
9434 thermalMitigationResult =
9435 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9436 break;
9437 }
9438
9439 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9440 false);
9441 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9442 break;
9443 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9444 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9445 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9446 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9447 }
9448
9449 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9450 if (registry != null) {
9451 TelephonyConnectionService service =
9452 registry.getTelephonyConnectionService();
9453 Phone phone = getPhone(subId);
9454 if (phone == null) {
9455 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009456 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009457 break;
9458 }
9459
9460 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009461 != TelephonyManager.CALL_STATE_IDLE
9462 || phone.isInEmergencySmsMode() || phone.isInEcm()
9463 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009464 String errorMessage = "Phone state is not valid. call state = "
9465 + PhoneConstantConversions.convertCallState(phone.getState())
9466 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9467 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9468 errorMessage += service == null
9469 ? " TelephonyConnectionService is null"
9470 : " isEmergencyCallPending = "
9471 + service.isEmergencyCallPending();
9472 Log.e(LOG_TAG, errorMessage);
9473 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009474 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009475 break;
9476 }
9477 } else {
9478 thermalMitigationResult =
9479 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9480 break;
9481 }
9482
9483 // Turn radio off. If not able to power off due to phone being unavailable,
9484 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9485 if (!setRadioPowerForThermal(subId, false)) {
9486 thermalMitigationResult =
9487 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9488 break;
9489 }
9490 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009491 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009492 break;
9493 default:
9494 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9495 + "not exist. Requested action: " + thermalMitigationAction);
9496 }
9497 } catch (IllegalArgumentException e) {
9498 throw e;
9499 } catch (Exception e) {
9500 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9501 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9502 } finally {
9503 Binder.restoreCallingIdentity(identity);
9504 }
9505
9506 if (DBG) {
9507 log("thermalMitigationRequest returning with thermalMitigationResult: "
9508 + thermalMitigationResult);
9509 }
9510
9511 return thermalMitigationResult;
9512 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009513
9514 /**
9515 * Set the GbaService Package Name that Telephony will bind to.
9516 *
9517 * @param subId The sim that the GbaService is associated with.
9518 * @param packageName The name of the package to be replaced with.
9519 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9520 */
9521 @Override
9522 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9523 enforceModifyPermission();
9524
9525 final long identity = Binder.clearCallingIdentity();
9526 try {
9527 return getGbaManager(subId).overrideServicePackage(packageName);
9528 } finally {
9529 Binder.restoreCallingIdentity(identity);
9530 }
9531 }
9532
9533 /**
9534 * Return the package name of the currently bound GbaService.
9535 *
9536 * @param subId The sim that the GbaService is associated with.
9537 * @return the package name of the GbaService configuration, null if GBA is not supported.
9538 */
9539 @Override
9540 public String getBoundGbaService(int subId) {
9541 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9542
9543 final long identity = Binder.clearCallingIdentity();
9544 try {
9545 return getGbaManager(subId).getServicePackage();
9546 } finally {
9547 Binder.restoreCallingIdentity(identity);
9548 }
9549 }
9550
9551 /**
9552 * Set the release time for telephony to unbind GbaService.
9553 *
9554 * @param subId The sim that the GbaService is associated with.
9555 * @param interval The release time to unbind GbaService by millisecond.
9556 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9557 */
9558 @Override
9559 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9560 enforceModifyPermission();
9561
9562 final long identity = Binder.clearCallingIdentity();
9563 try {
9564 return getGbaManager(subId).overrideReleaseTime(interval);
9565 } finally {
9566 Binder.restoreCallingIdentity(identity);
9567 }
9568 }
9569
9570 /**
9571 * Return the release time for telephony to unbind GbaService.
9572 *
9573 * @param subId The sim that the GbaService is associated with.
9574 * @return The release time to unbind GbaService by millisecond.
9575 */
9576 @Override
9577 public int getGbaReleaseTime(int subId) {
9578 enforceReadPrivilegedPermission("getGbaReleaseTime");
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 return getGbaManager(subId).getReleaseTime();
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 private GbaManager getGbaManager(int subId) {
9589 GbaManager instance = GbaManager.getInstance(subId);
9590 if (instance == null) {
9591 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9592 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9593 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9594 }
9595 return instance;
9596 }
Hui Wang068ab862020-10-31 05:12:53 +00009597
9598 /**
9599 * indicate whether the device and the carrier can support
9600 * RCS VoLTE single registration.
9601 */
9602 @Override
9603 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009604 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9605 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9606 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9607 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009608
9609 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9610 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9611 }
9612
9613 final long identity = Binder.clearCallingIdentity();
9614 try {
9615 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9616 if (rpm != null) {
9617 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9618 }
9619 return false;
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
9625 /**
9626 * Register RCS provisioning callback.
9627 */
9628 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009629 public void registerRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009630 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009631 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009632 Binder.getCallingUid(), "registerRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009633 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9634 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009635
9636 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9637 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9638 }
9639 if (!isImsAvailableOnDevice()) {
9640 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9641 "IMS not available on device.");
9642 }
9643
9644 final long identity = Binder.clearCallingIdentity();
9645 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009646 if (!RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009647 .registerRcsProvisioningCallback(subId, callback)) {
Hui Wang713d45f2021-01-11 20:04:53 -08009648 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9649 "Service not available for the subscription.");
9650 }
Hui Wang068ab862020-10-31 05:12:53 +00009651 } finally {
9652 Binder.restoreCallingIdentity(identity);
9653 }
9654 }
9655
9656 /**
9657 * Unregister RCS provisioning callback.
9658 */
9659 @Override
Hui Wang3cac7e52021-01-27 14:45:25 -08009660 public void unregisterRcsProvisioningCallback(int subId,
Hui Wang068ab862020-10-31 05:12:53 +00009661 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009662 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
Hui Wang3cac7e52021-01-27 14:45:25 -08009663 Binder.getCallingUid(), "unregisterRcsProvisioningCallback",
Brad Ebinger4df7e242021-02-17 23:23:21 +00009664 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9665 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009666
9667 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9668 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9669 }
9670 if (!isImsAvailableOnDevice()) {
9671 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9672 "IMS not available on device.");
9673 }
9674
9675 final long identity = Binder.clearCallingIdentity();
9676 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009677 RcsProvisioningMonitor.getInstance()
Hui Wang3cac7e52021-01-27 14:45:25 -08009678 .unregisterRcsProvisioningCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009679 } finally {
9680 Binder.restoreCallingIdentity(identity);
9681 }
9682 }
9683
9684 /**
9685 * trigger RCS reconfiguration.
9686 */
9687 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009688 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9689 "triggerRcsReconfiguration",
9690 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009691
9692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9694 }
9695 if (!isImsAvailableOnDevice()) {
9696 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9697 "IMS not available on device.");
9698 }
9699
9700 final long identity = Binder.clearCallingIdentity();
9701 try {
9702 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9703 } finally {
9704 Binder.restoreCallingIdentity(identity);
9705 }
9706 }
9707
9708 /**
9709 * Provide the client configuration parameters of the RCS application.
9710 */
9711 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009712 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9713 "setRcsClientConfiguration",
9714 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009715
9716 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9717 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9718 }
9719 if (!isImsAvailableOnDevice()) {
9720 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9721 "IMS not available on device.");
9722 }
9723
9724 final long identity = Binder.clearCallingIdentity();
9725
9726 try {
9727 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9728 if (configBinder == null) {
9729 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9730 } else {
9731 configBinder.setRcsClientConfiguration(rcc);
9732 }
9733 } catch (RemoteException e) {
9734 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9735 } finally {
9736 Binder.restoreCallingIdentity(identity);
9737 }
9738 }
9739
9740 /**
Hui Wang19a21872021-02-19 20:45:36 -08009741 * Enables or disables the test mode for RCS VoLTE single registration.
9742 */
9743 @Override
9744 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9745 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9746 "setRcsSingleRegistrationTestModeEnabled");
9747
9748 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9749 }
9750
9751 /**
9752 * Gets the test mode for RCS VoLTE single registration.
9753 */
9754 @Override
9755 public boolean getRcsSingleRegistrationTestModeEnabled() {
9756 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9757 "getRcsSingleRegistrationTestModeEnabled");
9758
9759 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9760 }
9761
9762 /**
Hui Wang068ab862020-10-31 05:12:53 +00009763 * Overrides the config of RCS VoLTE single registration enabled for the device.
9764 */
9765 @Override
9766 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9767 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9768 "setDeviceSingleRegistrationEnabledOverride");
9769 enforceModifyPermission();
9770
9771 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9772 : Boolean.parseBoolean(enabledStr);
9773 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009774 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009775 }
9776
9777 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009778 * Sends a device to device communication message. Only usable via shell.
9779 * @param message message to send.
9780 * @param value message value.
9781 */
9782 @Override
9783 public void sendDeviceToDeviceMessage(int message, int value) {
9784 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9785 "setCarrierSingleRegistrationEnabledOverride");
9786 enforceModifyPermission();
9787
9788 final long identity = Binder.clearCallingIdentity();
9789 try {
9790 TelephonyConnectionService service =
9791 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9792 if (service == null) {
9793 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9794 return;
9795 }
9796 service.sendTestDeviceToDeviceMessage(message, value);
9797 } finally {
9798 Binder.restoreCallingIdentity(identity);
9799 }
9800 }
9801
9802
9803 /**
Hui Wang068ab862020-10-31 05:12:53 +00009804 * Gets the config of RCS VoLTE single registration enabled for the device.
9805 */
9806 @Override
9807 public boolean getDeviceSingleRegistrationEnabled() {
9808 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9809 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9810 }
9811
9812 /**
9813 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9814 */
9815 @Override
9816 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9817 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9818 "setCarrierSingleRegistrationEnabledOverride");
9819 enforceModifyPermission();
9820
9821 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9822 : Boolean.parseBoolean(enabledStr);
9823 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9824 subId, enabled);
9825 }
9826
9827 /**
9828 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9829 */
9830 @Override
9831 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9832 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9833 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9834 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009835
9836 /**
9837 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9838 * their mobile plan.
9839 */
9840 @Override
9841 public String getMobileProvisioningUrl() {
9842 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9843 final long identity = Binder.clearCallingIdentity();
9844 try {
9845 return getDefaultPhone().getMobileProvisioningUrl();
9846 } finally {
9847 Binder.restoreCallingIdentity(identity);
9848 }
9849 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009850
James.cf Linbcdf8b32021-01-14 16:44:13 +08009851 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009852 * Get the EAB contact from the EAB database.
9853 */
9854 @Override
9855 public String getContactFromEab(String contact) {
9856 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9857 enforceModifyPermission();
9858 final long identity = Binder.clearCallingIdentity();
9859 try {
9860 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9861 } finally {
9862 Binder.restoreCallingIdentity(identity);
9863 }
9864 }
9865
9866 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009867 * Remove the EAB contacts from the EAB database.
9868 */
9869 @Override
9870 public int removeContactFromEab(int subId, String contacts) {
9871 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9872 enforceModifyPermission();
9873 final long identity = Binder.clearCallingIdentity();
9874 try {
9875 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9876 } finally {
9877 Binder.restoreCallingIdentity(identity);
9878 }
9879 }
9880
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009881 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009882 public boolean getDeviceUceEnabled() {
9883 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9884 final long identity = Binder.clearCallingIdentity();
9885 try {
9886 return mApp.getDeviceUceEnabled();
9887 } finally {
9888 Binder.restoreCallingIdentity(identity);
9889 }
9890 }
9891
9892 @Override
9893 public void setDeviceUceEnabled(boolean isEnabled) {
9894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 mApp.setDeviceUceEnabled(isEnabled);
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
9900 }
9901 }
9902
9903 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009904 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9905 String callingPackage) {
9906 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9907 mApp, subId, "setSignalStrengthUpdateRequest");
9908
9909 final int callingUid = Binder.getCallingUid();
9910 // Verify that tha callingPackage belongs to the calling UID
9911 mApp.getSystemService(AppOpsManager.class)
9912 .checkPackage(callingUid, callingPackage);
9913
9914 validateSignalStrengthUpdateRequest(request, callingUid);
9915
9916 final long identity = Binder.clearCallingIdentity();
9917 try {
9918 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9919 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9920
9921 if (result instanceof IllegalStateException) {
9922 throw (IllegalStateException) result;
9923 }
9924 } finally {
9925 Binder.restoreCallingIdentity(identity);
9926 }
9927 }
9928
9929 @Override
9930 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9931 String callingPackage) {
9932 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9933 mApp, subId, "clearSignalStrengthUpdateRequest");
9934
9935 final int callingUid = Binder.getCallingUid();
9936 // Verify that tha callingPackage belongs to the calling UID
9937 mApp.getSystemService(AppOpsManager.class)
9938 .checkPackage(callingUid, callingPackage);
9939
9940 final long identity = Binder.clearCallingIdentity();
9941 try {
9942 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9943 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9944
9945 if (result instanceof IllegalStateException) {
9946 throw (IllegalStateException) result;
9947 }
9948 } finally {
9949 Binder.restoreCallingIdentity(identity);
9950 }
9951 }
9952
9953 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9954 int callingUid) {
9955 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9956 // phone/system process do not have further restriction on request
9957 return;
9958 }
9959
9960 // Applications has restrictions on how to use the request:
9961 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9962 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9963 // This is not system caller which has been checked above
9964 throw new IllegalArgumentException(
9965 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9966 }
9967
9968 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9969 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9970 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9971 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9972 || info.isEnabled()) {
9973 throw new IllegalArgumentException(
9974 "Only system can set hide fields in SignalThresholdInfo");
9975 }
9976
9977 // Thresholds length for each RAN need in range. This has been validated in
9978 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9979 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9980 final int[] thresholds = info.getThresholds();
9981 Objects.requireNonNull(thresholds);
9982 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9983 || thresholds.length
9984 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9985 throw new IllegalArgumentException(
9986 "thresholds length is out of range: " + thresholds.length);
9987 }
9988 }
9989 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009990
9991 /**
9992 * Prepare TelephonyManager for an unattended reboot. The reboot is
9993 * required to be done shortly after the API is invoked.
9994 */
9995 @Override
9996 @TelephonyManager.PrepareUnattendedRebootResult
9997 public int prepareForUnattendedReboot() {
9998 enforceRebootPermission();
9999
10000 final long identity = Binder.clearCallingIdentity();
10001 try {
10002 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10003 } finally {
10004 Binder.restoreCallingIdentity(identity);
10005 }
10006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010007}