blob: 75234bee4cf55e2812d35d83626fe74c440c9b6e [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Brad Ebinger4df7e242021-02-17 23:23:21 +000024import android.Manifest;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080025import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080026import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070027import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080029import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070030import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070031import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070032import android.content.Context;
33import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070034import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080055import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070057import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070058import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070059import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070060import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080061import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070062import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090063import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080064import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080065import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070066import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070067import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080068import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070070import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070071import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080072import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070073import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080074import android.telephony.CellIdentityCdma;
75import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070076import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070077import android.telephony.CellInfoGsm;
78import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070079import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080080import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070081import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070082import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070083import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080084import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070085import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080086import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070087import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080088import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080089import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070090import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080091import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070092import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080093import android.telephony.SignalStrength;
Rambo Wanga5cc9b72021-01-07 10:51:54 -080094import android.telephony.SignalStrengthUpdateRequest;
95import android.telephony.SignalThresholdInfo;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080096import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080097import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080098import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070099import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -0800101import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800102import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -0800103import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000104import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700105import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700106import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800107import android.telephony.data.ApnSetting;
108import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700109import android.telephony.gba.GbaAuthRequest;
110import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700111import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000113import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700114import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800116import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700117import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800118import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700119import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000120import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700121import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800122import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800123import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800124import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800125import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700126import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800127import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700128import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700129import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800130import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800131
Andrew Lee312e8172014-10-23 17:01:36 -0700132import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800133import com.android.ims.internal.IImsServiceFeatureCallback;
James.cf Linbcdf8b32021-01-14 16:44:13 +0800134import com.android.ims.rcs.uce.eab.EabUtil;
sqian80370722020-01-29 15:02:51 -0800135import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700137import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700138import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800139import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700140import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700141import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800142import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700144import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800145import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800146import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700147import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700148import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800149import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800151import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700153import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700154import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700155import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700156import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800157import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700158import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700159import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700160import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700161import com.android.internal.telephony.RIL;
Jack Yu5f7092c2018-04-13 14:05:37 -0700162import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700163import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700164import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800165import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800166import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800167import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700168import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800169import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700170import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800171import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700172import com.android.internal.telephony.imsphone.ImsPhone;
173import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800174import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900175import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700176import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800177import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800179import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700180import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800181import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700182import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800183import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000184import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800185import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700186import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700187import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800188import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700189import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700190import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800191import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700192import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700193import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800194import com.android.services.telephony.TelecomAccountRegistry;
195import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800196import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800197
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700198import java.io.FileDescriptor;
199import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800201import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800202import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800203import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800204import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100205import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800206import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700207import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800208import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800209import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800210import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800211import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212
213/**
214 * Implementation of the ITelephony interface.
215 */
Santos Cordon117fee72014-05-16 17:56:12 -0700216public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700217 private static final String LOG_TAG = "PhoneInterfaceManager";
218 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
219 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800220 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700221
222 // Message codes used with mMainThreadHandler
223 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700224 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
225 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700226 private static final int CMD_OPEN_CHANNEL = 9;
227 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
228 private static final int CMD_CLOSE_CHANNEL = 11;
229 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800230 private static final int CMD_NV_READ_ITEM = 13;
231 private static final int EVENT_NV_READ_ITEM_DONE = 14;
232 private static final int CMD_NV_WRITE_ITEM = 15;
233 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
234 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
235 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700236 private static final int CMD_RESET_MODEM_CONFIG = 19;
237 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
SongFerngWang9e060372020-12-21 16:41:52 +0800238 private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21;
239 private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800240 private static final int CMD_SEND_ENVELOPE = 25;
241 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000242 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
243 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700244 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
245 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
246 private static final int CMD_EXCHANGE_SIM_IO = 31;
247 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800248 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
249 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700250 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
251 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700252 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
253 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700254 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
255 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
256 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
257 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700258 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
259 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
260 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
261 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700262 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800263 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
264 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000265 private static final int CMD_SWITCH_SLOTS = 50;
266 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700267 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
268 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
269 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
270 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
271 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
272 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
273 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
274 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700275 private static final int CMD_GET_ALL_CELL_INFO = 60;
276 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
277 private static final int CMD_GET_CELL_LOCATION = 62;
278 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700279 private static final int CMD_MODEM_REBOOT = 64;
280 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700281 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
282 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800283 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
284 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700285 private static final int CMD_GET_MODEM_STATUS = 70;
286 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700287 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
288 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700289 private static final int CMD_ERASE_MODEM_CONFIG = 74;
290 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800291 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
292 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
293 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
294 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800295 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
296 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800297 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800298 private static final int CMD_GET_CALL_FORWARDING = 83;
299 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
300 private static final int CMD_SET_CALL_FORWARDING = 85;
301 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
302 private static final int CMD_GET_CALL_WAITING = 87;
303 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
304 private static final int CMD_SET_CALL_WAITING = 89;
305 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700306 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
307 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
308 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
309 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700310 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
311 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800312 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
313 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800314 private static final int CMD_SET_DATA_THROTTLING = 99;
315 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800316 private static final int CMD_SET_SIM_POWER = 101;
317 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800318 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
319 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
320 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
321 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
SongFerngWang9e060372020-12-21 16:41:52 +0800322 private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107;
323 private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108;
Michele Berionned9fbae52020-11-13 02:36:59 +0000324 private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700325
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800326 // Parameters of select command.
327 private static final int SELECT_COMMAND = 0xA4;
328 private static final int SELECT_P1 = 0x04;
329 private static final int SELECT_P2 = 0;
330 private static final int SELECT_P3 = 0x10;
331
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700332 /** The singleton instance. */
333 private static PhoneInterfaceManager sInstance;
334
Wink Saville3ab207e2014-11-20 13:07:20 -0800335 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800336 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800337 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700338 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800339 private AppOpsManager mAppOps;
340 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800341 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800342 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700343 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700344
Peter Wangdafb9ac2020-01-15 14:13:38 -0800345 /** User Activity */
346 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800347 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
348
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700349 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
350
Derek Tan97ebb422014-09-05 16:55:38 -0700351 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
352 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800353 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800354 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700355
Michelecea4cf22018-12-21 15:00:11 -0800356 // String to store multi SIM allowed
357 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
358
Derek Tan740e1672017-06-27 14:56:27 -0700359 // The AID of ISD-R.
360 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
361
yinxub1bed742017-04-17 11:45:04 -0700362 private NetworkScanRequestTracker mNetworkScanRequestTracker;
363
David Kelly5e06a7f2018-03-12 14:10:59 +0000364 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
365 private static final int MANUFACTURER_CODE_LENGTH = 8;
366
Jack Nudelman24d51a52020-11-24 12:08:04 -0800367 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
368
Derek Tan89e89d42014-07-08 17:00:10 -0700369 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700370 * Experiment flag to enable erase modem config on reset network, default value is false
371 */
372 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
373 "reset_network_erase_modem_config_enabled";
374
Rambo Wang0f050d82021-02-12 11:43:36 -0800375 private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds
376
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700377 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700378 * A request object to use for transmitting data to an ICC.
379 */
380 private static final class IccAPDUArgument {
381 public int channel, cla, command, p1, p2, p3;
382 public String data;
383
384 public IccAPDUArgument(int channel, int cla, int command,
385 int p1, int p2, int p3, String data) {
386 this.channel = channel;
387 this.cla = cla;
388 this.command = command;
389 this.p1 = p1;
390 this.p2 = p2;
391 this.p3 = p3;
392 this.data = data;
393 }
394 }
395
396 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700397 * A request object to use for transmitting data to an ICC.
398 */
399 private static final class ManualNetworkSelectionArgument {
400 public OperatorInfo operatorInfo;
401 public boolean persistSelection;
402
403 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
404 this.operatorInfo = operatorInfo;
405 this.persistSelection = persistSelection;
406 }
407 }
408
409 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
411 * request after sending. The main thread will notify the request when it is complete.
412 */
413 private static final class MainThreadRequest {
414 /** The argument to use for the request */
415 public Object argument;
416 /** The result of the request that is run on the main thread */
417 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800418 // The subscriber id that this request applies to. Defaults to
419 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
420 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700421
Nathan Harold92bed182018-10-12 18:16:49 -0700422 // In cases where subId is unavailable, the caller needs to specify the phone.
423 public Phone phone;
424
vagdeviaf9a5b92018-08-15 16:01:53 -0700425 public WorkSource workSource;
426
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700427 public MainThreadRequest(Object argument) {
428 this.argument = argument;
429 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800430
Nathan Harold92bed182018-10-12 18:16:49 -0700431 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
432 this.argument = argument;
433 if (phone != null) {
434 this.phone = phone;
435 }
436 this.workSource = workSource;
437 }
438
vagdeviaf9a5b92018-08-15 16:01:53 -0700439 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800440 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800441 if (subId != null) {
442 this.subId = subId;
443 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700444 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800445 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446 }
447
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800448 private static final class IncomingThirdPartyCallArgs {
449 public final ComponentName component;
450 public final String callId;
451 public final String callerDisplayName;
452
453 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
454 String callerDisplayName) {
455 this.component = component;
456 this.callId = callId;
457 this.callerDisplayName = callerDisplayName;
458 }
459 }
460
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700461 /**
462 * A handler that processes messages on the main thread in the phone process. Since many
463 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
464 * inbound binder threads to the main thread in the phone process. The Binder thread
465 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
466 * on, which will be notified when the operation completes and will contain the result of the
467 * request.
468 *
469 * <p>If a MainThreadRequest object is provided in the msg.obj field,
470 * note that request.result must be set to something non-null for the calling thread to
471 * unblock.
472 */
473 private final class MainThreadHandler extends Handler {
474 @Override
475 public void handleMessage(Message msg) {
476 MainThreadRequest request;
477 Message onCompleted;
478 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800479 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700480 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800481 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482
483 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700484 case CMD_HANDLE_USSD_REQUEST: {
485 request = (MainThreadRequest) msg.obj;
486 final Phone phone = getPhoneFromRequest(request);
487 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
488 String ussdRequest = ussdObject.first;
489 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700490
Pengquan Menga1bb6272018-09-06 09:59:22 -0700491 if (!isUssdApiAllowed(request.subId)) {
492 // Carrier does not support use of this API, return failure.
493 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
494 UssdResponse response = new UssdResponse(ussdRequest, null);
495 Bundle returnData = new Bundle();
496 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
497 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700498
Pengquan Menga1bb6272018-09-06 09:59:22 -0700499 request.result = true;
500 notifyRequester(request);
501 return;
502 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700503
Pengquan Menga1bb6272018-09-06 09:59:22 -0700504 try {
505 request.result = phone != null
506 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
507 } catch (CallStateException cse) {
508 request.result = false;
509 }
510 // Wake up the requesting thread
511 notifyRequester(request);
512 break;
pkanwar32d516d2016-10-14 19:37:38 -0700513 }
514
Yorke Lee716f67e2015-06-17 15:39:16 -0700515 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700516 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700517 final Phone phone = getPhoneFromRequest(request);
518 request.result = phone != null ?
519 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
520 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700521 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700522 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700523 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700527 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduLogicalChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700534 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
536 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700537 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700538 iccArgument.channel, iccArgument.cla, iccArgument.command,
539 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700540 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 break;
543
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700544 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
549 } else {
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
551 if (ar.result == null) {
552 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800553 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700554 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800555 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700556 } else {
557 loge("iccTransmitApduLogicalChannel: Unknown exception");
558 }
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700561 break;
562
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
564 request = (MainThreadRequest) msg.obj;
565 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 if (uiccCard == null) {
568 loge("iccTransmitApduBasicChannel: No UICC");
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
573 request);
574 uiccCard.iccTransmitApduBasicChannel(
575 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
576 iccArgument.p3, iccArgument.data, onCompleted);
577 }
578 break;
579
580 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
583 if (ar.exception == null && ar.result != null) {
584 request.result = ar.result;
585 } else {
586 request.result = new IccIoResult(0x6F, 0, (byte[])null);
587 if (ar.result == null) {
588 loge("iccTransmitApduBasicChannel: Empty response");
589 } else if (ar.exception instanceof CommandException) {
590 loge("iccTransmitApduBasicChannel: CommandException: " +
591 ar.exception);
592 } else {
593 loge("iccTransmitApduBasicChannel: Unknown exception");
594 }
595 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700597 break;
598
599 case CMD_EXCHANGE_SIM_IO:
600 request = (MainThreadRequest) msg.obj;
601 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800602 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700603 if (uiccCard == null) {
604 loge("iccExchangeSimIO: No UICC");
605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700606 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700607 } else {
608 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
609 request);
610 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
611 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
612 iccArgument.data, onCompleted);
613 }
614 break;
615
616 case EVENT_EXCHANGE_SIM_IO_DONE:
617 ar = (AsyncResult) msg.obj;
618 request = (MainThreadRequest) ar.userObj;
619 if (ar.exception == null && ar.result != null) {
620 request.result = ar.result;
621 } else {
622 request.result = new IccIoResult(0x6f, 0, (byte[])null);
623 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700624 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700625 break;
626
Derek Tan4d5e5c12014-02-04 11:54:58 -0800627 case CMD_SEND_ENVELOPE:
628 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800629 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700630 if (uiccCard == null) {
631 loge("sendEnvelopeWithStatus: No UICC");
632 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700633 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700634 } else {
635 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
636 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
637 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800638 break;
639
640 case EVENT_SEND_ENVELOPE_DONE:
641 ar = (AsyncResult) msg.obj;
642 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700643 if (ar.exception == null && ar.result != null) {
644 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700646 request.result = new IccIoResult(0x6F, 0, (byte[])null);
647 if (ar.result == null) {
648 loge("sendEnvelopeWithStatus: Empty response");
649 } else if (ar.exception instanceof CommandException) {
650 loge("sendEnvelopeWithStatus: CommandException: " +
651 ar.exception);
652 } else {
653 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
654 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800655 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700656 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800657 break;
658
Shishir Agrawal566b7612013-10-28 14:41:00 -0700659 case CMD_OPEN_CHANNEL:
660 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800661 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800662 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700663 if (uiccCard == null) {
664 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800665 request.result = new IccOpenLogicalChannelResponse(-1,
666 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700667 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700668 } else {
669 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800670 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
671 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700672 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
675 case EVENT_OPEN_CHANNEL_DONE:
676 ar = (AsyncResult) msg.obj;
677 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700678 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700680 int[] result = (int[]) ar.result;
681 int channelId = result[0];
682 byte[] selectResponse = null;
683 if (result.length > 1) {
684 selectResponse = new byte[result.length - 1];
685 for (int i = 1; i < result.length; ++i) {
686 selectResponse[i - 1] = (byte) result[i];
687 }
688 }
689 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700690 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700692 if (ar.result == null) {
693 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700694 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 if (ar.exception != null) {
696 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
697 }
698
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700699 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700700 if (ar.exception instanceof CommandException) {
701 CommandException.Error error =
702 ((CommandException) (ar.exception)).getCommandError();
703 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700704 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700705 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700706 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700707 }
708 }
709 openChannelResp = new IccOpenLogicalChannelResponse(
710 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700712 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700713 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700714 break;
715
716 case CMD_CLOSE_CHANNEL:
717 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800718 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700719 if (uiccCard == null) {
720 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900721 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700722 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700723 } else {
724 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
725 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
726 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700727 break;
728
729 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800730 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
731 break;
732
733 case CMD_NV_READ_ITEM:
734 request = (MainThreadRequest) msg.obj;
735 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800736 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
737 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700741 ar = (AsyncResult) msg.obj;
742 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800743 if (ar.exception == null && ar.result != null) {
744 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800746 request.result = "";
747 if (ar.result == null) {
748 loge("nvReadItem: Empty response");
749 } else if (ar.exception instanceof CommandException) {
750 loge("nvReadItem: CommandException: " +
751 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700752 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800753 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700754 }
755 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700756 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700757 break;
758
Jake Hambye994d462014-02-03 13:10:13 -0800759 case CMD_NV_WRITE_ITEM:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
762 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800763 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700764 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800765 break;
766
767 case EVENT_NV_WRITE_ITEM_DONE:
768 handleNullReturnEvent(msg, "nvWriteItem");
769 break;
770
771 case CMD_NV_WRITE_CDMA_PRL:
772 request = (MainThreadRequest) msg.obj;
773 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800774 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800775 break;
776
777 case EVENT_NV_WRITE_CDMA_PRL_DONE:
778 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
779 break;
780
chen xu6dac5ab2018-10-26 17:39:23 -0700781 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800782 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700783 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800784 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800785 break;
786
chen xu6dac5ab2018-10-26 17:39:23 -0700787 case EVENT_RESET_MODEM_CONFIG_DONE:
788 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800789 break;
790
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700791 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
792 request = (MainThreadRequest) msg.obj;
793 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
794 request);
795 Phone phone = getPhoneFromRequest(request);
796 if (phone != null) {
797 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
798 } else {
799 loge("isNRDualConnectivityEnabled: No phone object");
800 request.result = false;
801 notifyRequester(request);
802 }
803 break;
804 }
805
806 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
807 ar = (AsyncResult) msg.obj;
808 request = (MainThreadRequest) ar.userObj;
809 if (ar.exception == null && ar.result != null) {
810 request.result = ar.result;
811 } else {
812 // request.result must be set to something non-null
813 // for the calling thread to unblock
814 if (request.result != null) {
815 request.result = ar.result;
816 } else {
817 request.result = false;
818 }
819 if (ar.result == null) {
820 loge("isNRDualConnectivityEnabled: Empty response");
821 } else if (ar.exception instanceof CommandException) {
822 loge("isNRDualConnectivityEnabled: CommandException: "
823 + ar.exception);
824 } else {
825 loge("isNRDualConnectivityEnabled: Unknown exception");
826 }
827 }
828 notifyRequester(request);
829 break;
830
831 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
832 request = (MainThreadRequest) msg.obj;
833 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
834 Phone phone = getPhoneFromRequest(request);
835 if (phone != null) {
836 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
837 request.workSource);
838 } else {
839 loge("enableNrDualConnectivity: No phone object");
840 request.result =
841 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
842 notifyRequester(request);
843 }
844 break;
845 }
846
847 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
848 ar = (AsyncResult) msg.obj;
849 request = (MainThreadRequest) ar.userObj;
850 if (ar.exception == null) {
851 request.result =
852 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
853 } else {
854 request.result =
855 TelephonyManager
856 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
857 if (ar.exception instanceof CommandException) {
858 CommandException.Error error =
859 ((CommandException) (ar.exception)).getCommandError();
860 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
861 request.result =
862 TelephonyManager
863 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
864 }
865 loge("enableNrDualConnectivity" + ": CommandException: "
866 + ar.exception);
867 } else {
868 loge("enableNrDualConnectivity" + ": Unknown exception");
869 }
870 }
871 notifyRequester(request);
872 break;
873 }
874
SongFerngWang9e060372020-12-21 16:41:52 +0800875 case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK:
Jake Hamby7c27be32014-03-03 13:25:59 -0800876 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800877 onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE,
878 request);
879 getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800880 break;
881
SongFerngWang9e060372020-12-21 16:41:52 +0800882 case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE:
Jake Hamby7c27be32014-03-03 13:25:59 -0800883 ar = (AsyncResult) msg.obj;
884 request = (MainThreadRequest) ar.userObj;
885 if (ar.exception == null && ar.result != null) {
886 request.result = ar.result; // Integer
887 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530888 // request.result must be set to something non-null
889 // for the calling thread to unblock
890 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800891 if (ar.result == null) {
SongFerngWang9e060372020-12-21 16:41:52 +0800892 loge("getAllowedNetworkTypesBitmask: Empty response");
Jake Hamby7c27be32014-03-03 13:25:59 -0800893 } else if (ar.exception instanceof CommandException) {
SongFerngWang9e060372020-12-21 16:41:52 +0800894 loge("getAllowedNetworkTypesBitmask: CommandException: "
895 + ar.exception);
Jake Hamby7c27be32014-03-03 13:25:59 -0800896 } else {
SongFerngWang9e060372020-12-21 16:41:52 +0800897 loge("getAllowedNetworkTypesBitmask: Unknown exception");
Jake Hamby7c27be32014-03-03 13:25:59 -0800898 }
899 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700900 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800901 break;
902
SongFerngWang9e060372020-12-21 16:41:52 +0800903 case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON:
Jake Hamby7c27be32014-03-03 13:25:59 -0800904 request = (MainThreadRequest) msg.obj;
SongFerngWang9e060372020-12-21 16:41:52 +0800905 onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE,
906 request);
907 Pair<Integer, Long> reasonWithNetworkTypes =
908 (Pair<Integer, Long>) request.argument;
909 getPhoneFromRequest(request).setAllowedNetworkTypes(
910 reasonWithNetworkTypes.first,
911 reasonWithNetworkTypes.second,
912 onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800913 break;
914
SongFerngWang9e060372020-12-21 16:41:52 +0800915 case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE:
916 handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason");
Jake Hamby7c27be32014-03-03 13:25:59 -0800917 break;
918
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000919 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
920 request = (MainThreadRequest)msg.obj;
921 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800922 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000923 break;
924
925 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
926 ar = (AsyncResult)msg.obj;
927 request = (MainThreadRequest)ar.userObj;
928 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700929 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000930 break;
931
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800932 case CMD_SET_VOICEMAIL_NUMBER:
933 request = (MainThreadRequest) msg.obj;
934 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
935 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800936 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
937 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800938 break;
939
940 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
941 handleNullReturnEvent(msg, "setVoicemailNumber");
942 break;
943
Stuart Scott54788802015-03-30 13:18:01 -0700944 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
945 request = (MainThreadRequest) msg.obj;
946 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
947 request);
948 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
949 break;
950
951 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
952 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
953 break;
954
Shishir Agrawal302c8692015-06-19 13:49:39 -0700955 case CMD_PERFORM_NETWORK_SCAN:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
958 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
959 break;
960
Hall Liua1acea22020-09-18 19:04:59 -0700961 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800962 request = (MainThreadRequest) msg.obj;
963 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700964 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
965 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
966 request.argument;
967 int callForwardingReason = args.first;
968 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800969 break;
Hall Liua1acea22020-09-18 19:04:59 -0700970 }
971 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800972 ar = (AsyncResult) msg.obj;
973 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700974 TelephonyManager.CallForwardingInfoCallback callback =
975 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
976 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800977 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700978 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800979 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
980 for (CallForwardInfo callForwardInfo : callForwardInfos) {
981 // Service Class is a bit mask per 3gpp 27.007. Search for
982 // any service for voice call.
983 if ((callForwardInfo.serviceClass
984 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700985 callForwardingInfo = new CallForwardingInfo(true,
986 callForwardInfo.reason,
987 callForwardInfo.number,
988 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800989 break;
990 }
991 }
992 // Didn't find a call forward info for voice call.
993 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700994 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
995 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800996 }
Hall Liua1acea22020-09-18 19:04:59 -0700997 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800998 } else {
999 if (ar.result == null) {
1000 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
1001 }
1002 if (ar.exception != null) {
1003 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
1004 }
Hall Liuae527aa2020-09-29 17:10:18 -07001005 int errorCode = TelephonyManager
1006 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001007 if (ar.exception instanceof CommandException) {
1008 CommandException.Error error =
1009 ((CommandException) (ar.exception)).getCommandError();
1010 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001011 errorCode = TelephonyManager
1012 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001013 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001014 errorCode = TelephonyManager
1015 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001016 }
1017 }
Hall Liua1acea22020-09-18 19:04:59 -07001018 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001019 }
sqian80370722020-01-29 15:02:51 -08001020 break;
Hall Liua1acea22020-09-18 19:04:59 -07001021 }
sqian80370722020-01-29 15:02:51 -08001022
Hall Liua1acea22020-09-18 19:04:59 -07001023 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001026 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001027 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001028 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1029 request.argument).first;
1030 request.phone.setCallForwardingOption(
1031 callForwardingInfoToSet.isEnabled()
1032 ? CommandsInterface.CF_ACTION_ENABLE
1033 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001034 callForwardingInfoToSet.getReason(),
1035 callForwardingInfoToSet.getNumber(),
1036 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1037 break;
Hall Liua1acea22020-09-18 19:04:59 -07001038 }
sqian80370722020-01-29 15:02:51 -08001039
Hall Liua1acea22020-09-18 19:04:59 -07001040 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001043 Consumer<Integer> callback =
1044 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1045 request.argument).second;
1046 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001047 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001048 int errorCode = TelephonyManager.CallForwardingInfoCallback
1049 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001050 if (ar.exception instanceof CommandException) {
1051 CommandException.Error error =
1052 ((CommandException) (ar.exception)).getCommandError();
1053 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001054 errorCode = TelephonyManager.CallForwardingInfoCallback
1055 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001056 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001057 errorCode = TelephonyManager.CallForwardingInfoCallback
1058 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001059 }
1060 }
1061 callback.accept(errorCode);
1062 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001063 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001064 }
sqian80370722020-01-29 15:02:51 -08001065 break;
Hall Liua1acea22020-09-18 19:04:59 -07001066 }
sqian80370722020-01-29 15:02:51 -08001067
Hall Liua1acea22020-09-18 19:04:59 -07001068 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001069 request = (MainThreadRequest) msg.obj;
1070 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1071 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1072 break;
Hall Liua1acea22020-09-18 19:04:59 -07001073 }
sqian80370722020-01-29 15:02:51 -08001074
Hall Liua1acea22020-09-18 19:04:59 -07001075 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001076 ar = (AsyncResult) msg.obj;
1077 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001078 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001079 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1080 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001081 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001082 // Service Class is a bit mask per 3gpp 27.007.
1083 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001084 if (callForwardResults.length > 1
1085 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001086 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001087 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001088 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1089 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001090 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001091 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001092 }
1093 } else {
1094 if (ar.result == null) {
1095 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1096 }
1097 if (ar.exception != null) {
1098 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1099 }
1100 if (ar.exception instanceof CommandException) {
1101 CommandException.Error error =
1102 ((CommandException) (ar.exception)).getCommandError();
1103 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 callForwardingStatus =
1105 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1106 }
1107 }
1108 }
Hall Liua1acea22020-09-18 19:04:59 -07001109 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001110 break;
Hall Liua1acea22020-09-18 19:04:59 -07001111 }
sqian80370722020-01-29 15:02:51 -08001112
Hall Liua1acea22020-09-18 19:04:59 -07001113 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001114 request = (MainThreadRequest) msg.obj;
1115 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001116 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1117 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001118 break;
Hall Liua1acea22020-09-18 19:04:59 -07001119 }
sqian80370722020-01-29 15:02:51 -08001120
Hall Liua1acea22020-09-18 19:04:59 -07001121 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001124 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1125 Consumer<Integer> callback =
1126 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1127 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001128 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001129 if (ar.exception instanceof CommandException) {
1130 CommandException.Error error =
1131 ((CommandException) (ar.exception)).getCommandError();
1132 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1133 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1134 } else {
1135 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1136 }
1137 } else {
1138 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1139 }
1140 } else {
1141 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1142 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001143 }
sqian80370722020-01-29 15:02:51 -08001144 break;
Hall Liua1acea22020-09-18 19:04:59 -07001145 }
sqian80370722020-01-29 15:02:51 -08001146
Shishir Agrawal302c8692015-06-19 13:49:39 -07001147 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 CellNetworkScanResult cellScanResult;
1151 if (ar.exception == null && ar.result != null) {
1152 cellScanResult = new CellNetworkScanResult(
1153 CellNetworkScanResult.STATUS_SUCCESS,
1154 (List<OperatorInfo>) ar.result);
1155 } else {
1156 if (ar.result == null) {
1157 loge("getCellNetworkScanResults: Empty response");
1158 }
1159 if (ar.exception != null) {
1160 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1161 }
1162 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1163 if (ar.exception instanceof CommandException) {
1164 CommandException.Error error =
1165 ((CommandException) (ar.exception)).getCommandError();
1166 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1167 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1168 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1169 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1170 }
1171 }
1172 cellScanResult = new CellNetworkScanResult(errorCode, null);
1173 }
1174 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001175 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 break;
1177
1178 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1179 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001180 ManualNetworkSelectionArgument selArg =
1181 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001182 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1183 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001184 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1185 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001186 break;
1187
1188 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001189 ar = (AsyncResult) msg.obj;
1190 request = (MainThreadRequest) ar.userObj;
1191 if (ar.exception == null) {
1192 request.result = true;
1193 } else {
1194 request.result = false;
1195 loge("setNetworkSelectionModeManual " + ar.exception);
1196 }
1197 notifyRequester(request);
1198 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001199 break;
1200
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001201 case CMD_GET_MODEM_ACTIVITY_INFO:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001204 if (defaultPhone != null) {
1205 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001206 } else {
1207 ResultReceiver result = (ResultReceiver) request.argument;
1208 Bundle bundle = new Bundle();
1209 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1210 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1211 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001212 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001213 break;
1214
1215 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1216 ar = (AsyncResult) msg.obj;
1217 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001218 ResultReceiver result = (ResultReceiver) request.argument;
1219
1220 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001221 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001222 // Update the last modem activity info and the result of the request.
1223 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1224 if (isModemActivityInfoValid(info)) {
1225 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1226 int[] txTimeMs = info.getTransmitTimeMillis();
1227 int[] lastModemTxTimeMs = mLastModemActivityInfo
1228 .getTransmitTimeMillis();
1229 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1230 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1231 }
1232 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1233 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1234 + mLastModemActivityInfo.getSleepTimeMillis());
1235 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1236 + mLastModemActivityInfo.getIdleTimeMillis());
1237 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1238 mLastModemActivityInfo.setReceiveTimeMillis(
1239 info.getReceiveTimeMillis()
1240 + mLastModemActivityInfo.getReceiveTimeMillis());
1241 }
1242 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1243 mLastModemActivityInfo.getSleepTimeMillis(),
1244 mLastModemActivityInfo.getIdleTimeMillis(),
1245 mLastModemActivityInfo.getTransmitTimeMillis(),
1246 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001247 } else {
1248 if (ar.result == null) {
1249 loge("queryModemActivityInfo: Empty response");
1250 } else if (ar.exception instanceof CommandException) {
1251 loge("queryModemActivityInfo: CommandException: " +
1252 ar.exception);
1253 } else {
1254 loge("queryModemActivityInfo: Unknown exception");
1255 }
1256 }
sqian1a1be542020-03-05 11:37:28 -08001257 Bundle bundle = new Bundle();
1258 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1259 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001260 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001261 break;
1262
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 case CMD_SET_ALLOWED_CARRIERS:
1264 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001265 CarrierRestrictionRules argument =
1266 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001267 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001268 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001269 break;
1270
1271 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1272 ar = (AsyncResult) msg.obj;
1273 request = (MainThreadRequest) ar.userObj;
1274 if (ar.exception == null && ar.result != null) {
1275 request.result = ar.result;
1276 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001277 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1278 if (ar.exception instanceof CommandException) {
1279 loge("setAllowedCarriers: CommandException: " + ar.exception);
1280 CommandException.Error error =
1281 ((CommandException) (ar.exception)).getCommandError();
1282 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1283 request.result =
1284 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1285 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001286 } else {
1287 loge("setAllowedCarriers: Unknown exception");
1288 }
1289 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001290 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 break;
1292
1293 case CMD_GET_ALLOWED_CARRIERS:
1294 request = (MainThreadRequest) msg.obj;
1295 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001296 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001297 break;
1298
1299 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1300 ar = (AsyncResult) msg.obj;
1301 request = (MainThreadRequest) ar.userObj;
1302 if (ar.exception == null && ar.result != null) {
1303 request.result = ar.result;
1304 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001305 request.result = new IllegalStateException(
1306 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001307 if (ar.result == null) {
1308 loge("getAllowedCarriers: Empty response");
1309 } else if (ar.exception instanceof CommandException) {
1310 loge("getAllowedCarriers: CommandException: " +
1311 ar.exception);
1312 } else {
1313 loge("getAllowedCarriers: Unknown exception");
1314 }
1315 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001316 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001317 break;
1318
Nathan Haroldb3014052017-01-25 15:57:32 -08001319 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1320 ar = (AsyncResult) msg.obj;
1321 request = (MainThreadRequest) ar.userObj;
1322 if (ar.exception == null && ar.result != null) {
1323 request.result = ar.result;
1324 } else {
1325 request.result = new IllegalArgumentException(
1326 "Failed to retrieve Forbidden Plmns");
1327 if (ar.result == null) {
1328 loge("getForbiddenPlmns: Empty response");
1329 } else {
1330 loge("getForbiddenPlmns: Unknown exception");
1331 }
1332 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001333 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001334 break;
1335
1336 case CMD_GET_FORBIDDEN_PLMNS:
1337 request = (MainThreadRequest) msg.obj;
1338 uiccCard = getUiccCardFromRequest(request);
1339 if (uiccCard == null) {
1340 loge("getForbiddenPlmns() UiccCard is null");
1341 request.result = new IllegalArgumentException(
1342 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001343 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001344 break;
1345 }
1346 Integer appType = (Integer) request.argument;
1347 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1348 if (uiccApp == null) {
1349 loge("getForbiddenPlmns() no app with specified type -- "
1350 + appType);
1351 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001352 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001353 break;
1354 } else {
1355 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1356 + " specified type -- " + appType);
1357 }
1358 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1359 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1360 onCompleted);
1361 break;
1362
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001363 case CMD_SWITCH_SLOTS:
1364 request = (MainThreadRequest) msg.obj;
1365 int[] physicalSlots = (int[]) request.argument;
1366 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1367 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1368 break;
1369
1370 case EVENT_SWITCH_SLOTS_DONE:
1371 ar = (AsyncResult) msg.obj;
1372 request = (MainThreadRequest) ar.userObj;
1373 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001374 notifyRequester(request);
1375 break;
1376 case CMD_GET_NETWORK_SELECTION_MODE:
1377 request = (MainThreadRequest) msg.obj;
1378 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1379 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1380 break;
1381
1382 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1383 ar = (AsyncResult) msg.obj;
1384 request = (MainThreadRequest) ar.userObj;
1385 if (ar.exception != null) {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1387 } else {
1388 int mode = ((int[]) ar.result)[0];
1389 if (mode == 0) {
1390 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1391 } else {
1392 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1393 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001394 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001395 notifyRequester(request);
1396 break;
1397 case CMD_GET_CDMA_ROAMING_MODE:
1398 request = (MainThreadRequest) msg.obj;
1399 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1400 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1401 break;
1402 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 if (ar.exception != null) {
1406 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1407 } else {
1408 request.result = ((int[]) ar.result)[0];
1409 }
1410 notifyRequester(request);
1411 break;
1412 case CMD_SET_CDMA_ROAMING_MODE:
1413 request = (MainThreadRequest) msg.obj;
1414 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1415 int mode = (int) request.argument;
1416 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1417 break;
1418 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1419 ar = (AsyncResult) msg.obj;
1420 request = (MainThreadRequest) ar.userObj;
1421 request.result = ar.exception == null;
1422 notifyRequester(request);
1423 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001424 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1425 request = (MainThreadRequest) msg.obj;
1426 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1427 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1428 break;
1429 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1430 ar = (AsyncResult) msg.obj;
1431 request = (MainThreadRequest) ar.userObj;
1432 if (ar.exception != null) {
1433 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1434 } else {
1435 request.result = ((int[]) ar.result)[0];
1436 }
1437 notifyRequester(request);
1438 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1442 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001443 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1444 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001445 break;
1446 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1447 ar = (AsyncResult) msg.obj;
1448 request = (MainThreadRequest) ar.userObj;
1449 request.result = ar.exception == null;
1450 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001451 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001452 case CMD_GET_ALL_CELL_INFO:
1453 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001454 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001455 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001456 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 case EVENT_GET_ALL_CELL_INFO_DONE:
1458 ar = (AsyncResult) msg.obj;
1459 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001460 // If a timeout occurs, the response will be null
1461 request.result = (ar.exception == null && ar.result != null)
1462 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001463 synchronized (request) {
1464 request.notifyAll();
1465 }
1466 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001467 case CMD_REQUEST_CELL_INFO_UPDATE:
1468 request = (MainThreadRequest) msg.obj;
1469 request.phone.requestCellInfoUpdate(request.workSource,
1470 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1471 break;
1472 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1473 ar = (AsyncResult) msg.obj;
1474 request = (MainThreadRequest) ar.userObj;
1475 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1476 try {
1477 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001479 cb.onError(
1480 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1481 ar.exception.getClass().getName(),
1482 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001483 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001484 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001485 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001486 } else {
1487 // use the result as returned
1488 cb.onCellInfo((List<CellInfo>) ar.result);
1489 }
1490 } catch (RemoteException re) {
1491 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1492 }
1493 break;
Sarah Chincc055732020-11-18 13:39:35 -08001494 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001495 request = (MainThreadRequest) msg.obj;
1496 WorkSource ws = (WorkSource) request.argument;
1497 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001498 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001499 break;
Sarah Chincc055732020-11-18 13:39:35 -08001500 }
1501 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 ar = (AsyncResult) msg.obj;
1503 request = (MainThreadRequest) ar.userObj;
1504 if (ar.exception == null) {
1505 request.result = ar.result;
1506 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001507 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001508 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001509 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001510 }
1511
1512 synchronized (request) {
1513 request.notifyAll();
1514 }
1515 break;
Sarah Chincc055732020-11-18 13:39:35 -08001516 }
chen xu6dac5ab2018-10-26 17:39:23 -07001517 case CMD_MODEM_REBOOT:
1518 request = (MainThreadRequest) msg.obj;
1519 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001520 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001521 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001522 case EVENT_CMD_MODEM_REBOOT_DONE:
1523 handleNullReturnEvent(msg, "rebootModem");
1524 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001525 case CMD_REQUEST_ENABLE_MODEM:
1526 request = (MainThreadRequest) msg.obj;
1527 boolean enable = (boolean) request.argument;
1528 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001529 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001530 PhoneConfigurationManager.getInstance()
1531 .enablePhone(request.phone, enable, onCompleted);
1532 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001533 case EVENT_ENABLE_MODEM_DONE: {
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001534 ar = (AsyncResult) msg.obj;
1535 request = (MainThreadRequest) ar.userObj;
1536 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001537 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001538 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001539 if ((boolean) request.result) {
1540 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1541 updateModemStateMetrics();
1542 } else {
1543 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1544 + ar.exception);
1545 }
1546 notifyRequester(request);
1547 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001548 }
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001549 case CMD_GET_MODEM_STATUS:
1550 request = (MainThreadRequest) msg.obj;
1551 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1552 PhoneConfigurationManager.getInstance()
1553 .getPhoneStatusFromModem(request.phone, onCompleted);
1554 break;
1555 case EVENT_GET_MODEM_STATUS_DONE:
1556 ar = (AsyncResult) msg.obj;
1557 request = (MainThreadRequest) ar.userObj;
1558 int id = request.phone.getPhoneId();
1559 if (ar.exception == null && ar.result != null) {
1560 request.result = ar.result;
1561 //update the cache as modem status has changed
1562 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1563 (boolean) request.result);
1564 } else {
1565 // Return true if modem status cannot be retrieved. For most cases,
1566 // modem status is on. And for older version modems, GET_MODEM_STATUS
1567 // and disable modem are not supported. Modem is always on.
1568 // TODO: this should be fixed in R to support a third
1569 // status UNKNOWN b/131631629
1570 request.result = true;
1571 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1572 + ar.exception);
1573 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001574 notifyRequester(request);
1575 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001576 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1577 request = (MainThreadRequest) msg.obj;
1578 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1579 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1580 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1581 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1582 break;
1583 }
1584 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1585 ar = (AsyncResult) msg.obj;
1586 request = (MainThreadRequest) ar.userObj;
1587 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1588 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1589 args.second.accept(ar.exception == null);
1590 notifyRequester(request);
1591 break;
1592 }
Sarah Chincc055732020-11-18 13:39:35 -08001593 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1594 request = (MainThreadRequest) msg.obj;
1595 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1596 Phone phone = getPhoneFromRequest(request);
1597 if (phone != null) {
1598 phone.getSystemSelectionChannels(onCompleted);
1599 } else {
1600 loge("getSystemSelectionChannels: No phone object");
1601 request.result = new ArrayList<RadioAccessSpecifier>();
1602 notifyRequester(request);
1603 }
1604 break;
1605 }
1606 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1607 ar = (AsyncResult) msg.obj;
1608 request = (MainThreadRequest) ar.userObj;
1609 if (ar.exception == null && ar.result != null) {
1610 request.result = ar.result;
1611 } else {
1612 request.result = new IllegalArgumentException(
1613 "Failed to retrieve system selection channels");
1614 if (ar.result == null) {
1615 loge("getSystemSelectionChannels: Empty response");
1616 } else {
1617 loge("getSystemSelectionChannels: Unknown exception");
1618 }
1619 }
1620 notifyRequester(request);
1621 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001622 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1623 ar = (AsyncResult) msg.obj;
1624 request = (MainThreadRequest) ar.userObj;
1625 if (ar.exception == null && ar.result != null) {
1626 request.result = ar.result;
1627 } else {
1628 request.result = -1;
1629 loge("Failed to set Forbidden Plmns");
1630 if (ar.result == null) {
1631 loge("setForbidenPlmns: Empty response");
1632 } else if (ar.exception != null) {
1633 loge("setForbiddenPlmns: Exception: " + ar.exception);
1634 request.result = -1;
1635 } else {
1636 loge("setForbiddenPlmns: Unknown exception");
1637 }
1638 }
1639 notifyRequester(request);
1640 break;
1641 case CMD_SET_FORBIDDEN_PLMNS:
1642 request = (MainThreadRequest) msg.obj;
1643 uiccCard = getUiccCardFromRequest(request);
1644 if (uiccCard == null) {
1645 loge("setForbiddenPlmns: UiccCard is null");
1646 request.result = -1;
1647 notifyRequester(request);
1648 break;
1649 }
1650 Pair<Integer, List<String>> setFplmnsArgs =
1651 (Pair<Integer, List<String>>) request.argument;
1652 appType = setFplmnsArgs.first;
1653 List<String> fplmns = setFplmnsArgs.second;
1654 uiccApp = uiccCard.getApplicationByType(appType);
1655 if (uiccApp == null) {
1656 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1657 request.result = -1;
1658 loge("Failed to get UICC App");
1659 notifyRequester(request);
1660 } else {
1661 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1662 ((SIMRecords) uiccApp.getIccRecords())
1663 .setForbiddenPlmns(onCompleted, fplmns);
1664 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001665 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001666 case CMD_ERASE_MODEM_CONFIG:
1667 request = (MainThreadRequest) msg.obj;
1668 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1669 defaultPhone.eraseModemConfig(onCompleted);
1670 break;
1671 case EVENT_ERASE_MODEM_CONFIG_DONE:
1672 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001673 break;
zoey chenf95ca592019-12-30 16:11:23 +08001674
1675 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1676 request = (MainThreadRequest) msg.obj;
1677 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1678 Pair<String, String> changed = (Pair<String, String>) request.argument;
1679 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1680 changed.first, changed.second, onCompleted);
1681 break;
1682 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1683 ar = (AsyncResult) msg.obj;
1684 request = (MainThreadRequest) ar.userObj;
1685 if (ar.exception == null) {
1686 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001687 // If the operation is successful, update the PIN storage
1688 Pair<String, String> passwords = (Pair<String, String>) request.argument;
1689 int phoneId = getPhoneFromRequest(request).getPhoneId();
1690 UiccController.getInstance().getPinStorage()
1691 .storePin(passwords.second, phoneId);
zoey chenf95ca592019-12-30 16:11:23 +08001692 } else {
1693 request.result = msg.arg1;
1694 }
1695 notifyRequester(request);
1696 break;
1697
Michele Berionned9fbae52020-11-13 02:36:59 +00001698 case CMD_SET_ICC_LOCK_ENABLED: {
zoey chenf95ca592019-12-30 16:11:23 +08001699 request = (MainThreadRequest) msg.obj;
1700 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1701 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1702 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1703 enabled.first, enabled.second, onCompleted);
1704 break;
Michele Berionned9fbae52020-11-13 02:36:59 +00001705 }
zoey chenf95ca592019-12-30 16:11:23 +08001706 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1707 ar = (AsyncResult) msg.obj;
1708 request = (MainThreadRequest) ar.userObj;
1709 if (ar.exception == null) {
1710 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
Michele Berionned9fbae52020-11-13 02:36:59 +00001711 // If the operation is successful, update the PIN storage
1712 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1713 int phoneId = getPhoneFromRequest(request).getPhoneId();
1714 if (enabled.first) {
1715 UiccController.getInstance().getPinStorage()
1716 .storePin(enabled.second, phoneId);
1717 } else {
1718 UiccController.getInstance().getPinStorage().clearPin(phoneId);
1719 }
zoey chenf95ca592019-12-30 16:11:23 +08001720 } else {
1721 request.result = msg.arg1;
1722 }
Michele Berionned9fbae52020-11-13 02:36:59 +00001723
1724
zoey chenf95ca592019-12-30 16:11:23 +08001725 notifyRequester(request);
1726 break;
1727
Peter Wangdafb9ac2020-01-15 14:13:38 -08001728 case MSG_NOTIFY_USER_ACTIVITY:
1729 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001730 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001731 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1732 getDefaultPhone().getContext().sendBroadcastAsUser(
1733 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1734 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001735
1736 case CMD_SET_DATA_THROTTLING: {
1737 request = (MainThreadRequest) msg.obj;
1738 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1739 DataThrottlingRequest dataThrottlingRequest =
1740 (DataThrottlingRequest) request.argument;
1741 Phone phone = getPhoneFromRequest(request);
1742 if (phone != null) {
1743 phone.setDataThrottling(onCompleted,
1744 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1745 dataThrottlingRequest.getCompletionDurationMillis());
1746 } else {
1747 loge("setDataThrottling: No phone object");
1748 request.result =
1749 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1750 notifyRequester(request);
1751 }
1752
1753 break;
1754 }
1755 case EVENT_SET_DATA_THROTTLING_DONE:
1756 ar = (AsyncResult) msg.obj;
1757 request = (MainThreadRequest) ar.userObj;
1758
1759 if (ar.exception == null) {
1760 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1761 } else if (ar.exception instanceof CommandException) {
1762 loge("setDataThrottling: CommandException: " + ar.exception);
1763 CommandException.Error error =
1764 ((CommandException) (ar.exception)).getCommandError();
1765
1766 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1767 request.result = TelephonyManager
1768 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1769 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1770 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1771 } else {
1772 request.result =
1773 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1774 }
1775 } else {
1776 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1777 }
1778 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1779 notifyRequester(request);
1780 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001781
1782 case CMD_SET_SIM_POWER: {
1783 request = (MainThreadRequest) msg.obj;
1784 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1785 request = (MainThreadRequest) msg.obj;
1786 int stateToSet =
1787 ((Pair<Integer, IIntegerConsumer>)
1788 request.argument).first;
1789 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1790 break;
1791 }
1792 case EVENT_SET_SIM_POWER_DONE: {
1793 ar = (AsyncResult) msg.obj;
1794 request = (MainThreadRequest) ar.userObj;
1795 IIntegerConsumer callback =
1796 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1797 if (ar.exception != null) {
1798 loge("setSimPower exception: " + ar.exception);
1799 int errorCode = TelephonyManager.CallForwardingInfoCallback
1800 .RESULT_ERROR_UNKNOWN;
1801 if (ar.exception instanceof CommandException) {
1802 CommandException.Error error =
1803 ((CommandException) (ar.exception)).getCommandError();
1804 if (error == CommandException.Error.SIM_ERR) {
1805 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1806 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1807 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1808 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1809 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1810 } else {
1811 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1812 }
1813 }
1814 try {
1815 callback.accept(errorCode);
1816 } catch (RemoteException e) {
1817 // Ignore if the remote process is no longer available to call back.
1818 Log.w(LOG_TAG, "setSimPower: callback not available.");
1819 }
1820 } else {
1821 try {
1822 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1823 } catch (RemoteException e) {
1824 // Ignore if the remote process is no longer available to call back.
1825 Log.w(LOG_TAG, "setSimPower: callback not available.");
1826 }
1827 }
1828 break;
1829 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001830 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1831 request = (MainThreadRequest) msg.obj;
1832
1833 final Phone phone = getPhoneFromRequest(request);
1834 if (phone == null || phone.getServiceStateTracker() == null) {
1835 request.result = new IllegalStateException("Phone or SST is null");
1836 notifyRequester(request);
1837 break;
1838 }
1839
1840 Pair<Integer, SignalStrengthUpdateRequest> pair =
1841 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1842 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1843 request);
1844 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1845 request.subId, pair.first /*callingUid*/,
1846 pair.second /*request*/, onCompleted);
1847 break;
1848 }
1849 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1850 ar = (AsyncResult) msg.obj;
1851 request = (MainThreadRequest) ar.userObj;
1852 // request.result will be the exception of ar if present, true otherwise.
1853 // Be cautious not to leave result null which will wait() forever
1854 request.result = ar.exception != null ? ar.exception : true;
1855 notifyRequester(request);
1856 break;
1857 }
1858 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1859 request = (MainThreadRequest) msg.obj;
1860
1861 Phone phone = getPhoneFromRequest(request);
1862 if (phone == null || phone.getServiceStateTracker() == null) {
1863 request.result = new IllegalStateException("Phone or SST is null");
1864 notifyRequester(request);
1865 break;
1866 }
1867
1868 Pair<Integer, SignalStrengthUpdateRequest> pair =
1869 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1870 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1871 request);
1872 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1873 request.subId, pair.first /*callingUid*/,
1874 pair.second /*request*/, onCompleted);
1875 break;
1876 }
1877 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1878 ar = (AsyncResult) msg.obj;
1879 request = (MainThreadRequest) ar.userObj;
1880 request.result = ar.exception != null ? ar.exception : true;
1881 notifyRequester(request);
1882 break;
1883 }
Jordan Liud5366d92020-11-24 14:50:34 -08001884
Michele Berionned9fbae52020-11-13 02:36:59 +00001885 case CMD_PREPARE_UNATTENDED_REBOOT:
1886 request = (MainThreadRequest) msg.obj;
1887 request.result =
1888 UiccController.getInstance().getPinStorage().prepareUnattendedReboot();
1889 notifyRequester(request);
1890 break;
1891
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 default:
1893 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1894 break;
1895 }
1896 }
Jake Hambye994d462014-02-03 13:10:13 -08001897
Pengquan Menga1bb6272018-09-06 09:59:22 -07001898 private void notifyRequester(MainThreadRequest request) {
1899 synchronized (request) {
1900 request.notifyAll();
1901 }
1902 }
1903
Jake Hambye994d462014-02-03 13:10:13 -08001904 private void handleNullReturnEvent(Message msg, String command) {
1905 AsyncResult ar = (AsyncResult) msg.obj;
1906 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1907 if (ar.exception == null) {
1908 request.result = true;
1909 } else {
1910 request.result = false;
1911 if (ar.exception instanceof CommandException) {
1912 loge(command + ": CommandException: " + ar.exception);
1913 } else {
1914 loge(command + ": Unknown exception");
1915 }
1916 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001917 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001918 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001919 }
1920
1921 /**
1922 * Posts the specified command to be executed on the main thread,
1923 * waits for the request to complete, and returns the result.
1924 * @see #sendRequestAsync
1925 */
1926 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001927 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1928 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001929 }
1930
1931 /**
1932 * Posts the specified command to be executed on the main thread,
1933 * waits for the request to complete, and returns the result.
1934 * @see #sendRequestAsync
1935 */
1936 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1937 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001938 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001939 }
1940
1941 /**
1942 * Posts the specified command to be executed on the main thread,
1943 * waits for the request to complete, and returns the result.
1944 * @see #sendRequestAsync
1945 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001946 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001947 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1948 }
1949
1950 /**
1951 * Posts the specified command to be executed on the main thread,
1952 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1953 * if not timeout or null otherwise.
1954 * @see #sendRequestAsync
1955 */
1956 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1957 long timeoutInMs) {
1958 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001959 }
1960
1961 /**
1962 * Posts the specified command to be executed on the main thread,
1963 * waits for the request to complete, and returns the result.
1964 * @see #sendRequestAsync
1965 */
Nathan Harold92bed182018-10-12 18:16:49 -07001966 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001967 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001968 }
1969
1970 /**
1971 * Posts the specified command to be executed on the main thread,
1972 * waits for the request to complete, and returns the result.
1973 * @see #sendRequestAsync
1974 */
1975 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001976 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1977 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001978 }
1979
1980 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001981 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1982 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1983 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001984 * @see #sendRequestAsync
1985 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001986 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1987 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001988 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1989 throw new RuntimeException("This method will deadlock if called from the main thread.");
1990 }
1991
Nathan Harold92bed182018-10-12 18:16:49 -07001992 MainThreadRequest request = null;
1993 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1994 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1995 } else if (phone != null) {
1996 request = new MainThreadRequest(argument, phone, workSource);
1997 } else {
1998 request = new MainThreadRequest(argument, subId, workSource);
1999 }
2000
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002001 Message msg = mMainThreadHandler.obtainMessage(command, request);
2002 msg.sendToTarget();
2003
Rambo Wang0f050d82021-02-12 11:43:36 -08002004
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002005 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08002006 if (timeoutInMs >= 0) {
2007 // Wait for at least timeoutInMs before returning null request result
2008 long now = SystemClock.elapsedRealtime();
2009 long deadline = now + timeoutInMs;
2010 while (request == null && now < deadline) {
2011 try {
2012 request.wait(deadline - now);
2013 } catch (InterruptedException e) {
2014 // Do nothing, go back and check if request is completed or timeout
2015 } finally {
2016 now = SystemClock.elapsedRealtime();
2017 }
2018 }
2019 } else {
2020 // Wait for the request to complete
2021 while (request.result == null) {
2022 try {
2023 request.wait();
2024 } catch (InterruptedException e) {
2025 // Do nothing, go back and wait until the request is complete
2026 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002027 }
2028 }
2029 }
Rambo Wang0f050d82021-02-12 11:43:36 -08002030 if (request.result == null) {
2031 Log.wtf(LOG_TAG,
2032 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2033 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002034 return request.result;
2035 }
2036
2037 /**
2038 * Asynchronous ("fire and forget") version of sendRequest():
2039 * Posts the specified command to be executed on the main thread, and
2040 * returns immediately.
2041 * @see #sendRequest
2042 */
2043 private void sendRequestAsync(int command) {
2044 mMainThreadHandler.sendEmptyMessage(command);
2045 }
2046
2047 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002048 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002049 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002050 */
2051 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002052 sendRequestAsync(command, argument, null, null);
2053 }
2054
2055 /**
2056 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2057 * @see {@link #sendRequest(int,Object)}
2058 */
2059 private void sendRequestAsync(
2060 int command, Object argument, Phone phone, WorkSource workSource) {
2061 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002062 Message msg = mMainThreadHandler.obtainMessage(command, request);
2063 msg.sendToTarget();
2064 }
2065
2066 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002067 * Initialize the singleton PhoneInterfaceManager instance.
2068 * This is only done once, at startup, from PhoneApp.onCreate().
2069 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002070 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002071 synchronized (PhoneInterfaceManager.class) {
2072 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002073 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 } else {
2075 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2076 }
2077 return sInstance;
2078 }
2079 }
2080
2081 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002082 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002083 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002085 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002086 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2088 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002089 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002090 mTelephonySharedPreferences =
2091 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002092 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002093 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002094 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002095
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 publish();
2097 }
2098
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002099 private Phone getDefaultPhone() {
2100 Phone thePhone = getPhone(getDefaultSubscription());
2101 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2102 }
2103
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002104 private void publish() {
2105 if (DBG) log("publish: " + this);
2106
Peter Wangc035ce42020-01-08 21:00:22 -08002107 TelephonyFrameworkInitializer
2108 .getTelephonyServiceManager()
2109 .getTelephonyServiceRegisterer()
2110 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002111 }
2112
Stuart Scott584921c2015-01-15 17:10:34 -08002113 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002114 if (request.phone != null) {
2115 return request.phone;
2116 } else {
2117 return getPhoneFromSubId(request.subId);
2118 }
2119 }
2120
2121 private Phone getPhoneFromSubId(int subId) {
2122 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2123 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002124 }
2125
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002126 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2127 Phone phone = getPhoneFromRequest(request);
2128 return phone == null ? null :
2129 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2130 }
2131
Wink Saville36469e72014-06-11 15:17:00 -07002132 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002134 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002135 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002136
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002137 private void sendEraseModemConfig(Phone phone) {
2138 if (phone != null) {
2139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2140 mApp, phone.getSubId(), "eraseModemConfig");
2141 final long identity = Binder.clearCallingIdentity();
2142 try {
2143 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2144 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
2147 }
2148 }
2149 }
2150
Peter Wang050bb052020-01-13 23:33:09 -08002151 private boolean isImsAvailableOnDevice() {
2152 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2153 if (pm == null) {
2154 // For some reason package manger is not available.. This will fail internally anyway,
2155 // so do not throw error and allow.
2156 return true;
2157 }
2158 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2159 }
2160
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002161 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002162 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002163 }
2164
Wink Savilleb564aae2014-10-23 10:18:09 -07002165 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002166 if (DBG) log("dial: " + number);
2167 // No permission check needed here: This is just a wrapper around the
2168 // ACTION_DIAL intent, which is available to any app since it puts up
2169 // the UI before it does anything.
2170
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171 final long identity = Binder.clearCallingIdentity();
2172 try {
2173 String url = createTelUrl(number);
2174 if (url == null) {
2175 return;
2176 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002177
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 // PENDING: should we just silently fail if phone is offhook or ringing?
2179 PhoneConstants.State state = mCM.getState(subId);
2180 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2181 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2182 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2183 mApp.startActivity(intent);
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 }
2188 }
2189
2190 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002191 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002192 }
2193
Wink Savilleb564aae2014-10-23 10:18:09 -07002194 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 if (DBG) log("call: " + number);
2196
2197 // This is just a wrapper around the ACTION_CALL intent, but we still
2198 // need to do a permission check since we're calling startActivity()
2199 // from the context of the phone app.
2200 enforceCallPermission();
2201
Jordan Liu1617b712019-07-10 15:06:26 -07002202 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 != AppOpsManager.MODE_ALLOWED) {
2204 return;
2205 }
2206
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 String url = createTelUrl(number);
2210 if (url == null) {
2211 return;
2212 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 boolean isValid = false;
2215 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2216 if (slist != null) {
2217 for (SubscriptionInfo subInfoRecord : slist) {
2218 if (subInfoRecord.getSubscriptionId() == subId) {
2219 isValid = true;
2220 break;
2221 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002222 }
Wink Saville08874612014-08-31 19:19:58 -07002223 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 if (!isValid) {
2225 return;
2226 }
Wink Saville08874612014-08-31 19:19:58 -07002227
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002228 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2229 intent.putExtra(SUBSCRIPTION_KEY, subId);
2230 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2231 mApp.startActivity(intent);
2232 } finally {
2233 Binder.restoreCallingIdentity(identity);
2234 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002235 }
2236
Wink Savilleb564aae2014-10-23 10:18:09 -07002237 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002238 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002239 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2240 }
2241
Wink Savilleb564aae2014-10-23 10:18:09 -07002242 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002243 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002244 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2245 }
2246
Wink Savilleb564aae2014-10-23 10:18:09 -07002247 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002248 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002249
2250 final long identity = Binder.clearCallingIdentity();
2251 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002252 Phone phone = getPhone(subId);
2253 final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002254 checkSimPin.start();
2255 return checkSimPin.unlockSim(null, pin);
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
2258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Wink Savilleb564aae2014-10-23 10:18:09 -07002261 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002262 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263
2264 final long identity = Binder.clearCallingIdentity();
2265 try {
Michele Berionned9fbae52020-11-13 02:36:59 +00002266 Phone phone = getPhone(subId);
2267 final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 checkSimPuk.start();
2269 return checkSimPuk.unlockSim(puk, pin);
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
2272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002276 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002277 * a synchronous one.
2278 */
2279 private static class UnlockSim extends Thread {
2280
2281 private final IccCard mSimCard;
Michele Berionned9fbae52020-11-13 02:36:59 +00002282 private final int mPhoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002283
2284 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002285 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2286 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287
2288 // For replies from SimCard interface
2289 private Handler mHandler;
2290
2291 // For async handler to identify request type
2292 private static final int SUPPLY_PIN_COMPLETE = 100;
2293
Michele Berionned9fbae52020-11-13 02:36:59 +00002294 UnlockSim(int phoneId, IccCard simCard) {
2295 mPhoneId = phoneId;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002296 mSimCard = simCard;
2297 }
2298
2299 @Override
2300 public void run() {
2301 Looper.prepare();
2302 synchronized (UnlockSim.this) {
2303 mHandler = new Handler() {
2304 @Override
2305 public void handleMessage(Message msg) {
2306 AsyncResult ar = (AsyncResult) msg.obj;
2307 switch (msg.what) {
2308 case SUPPLY_PIN_COMPLETE:
2309 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2310 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002311 mRetryCount = msg.arg1;
2312 if (ar.exception != null) {
2313 if (ar.exception instanceof CommandException &&
2314 ((CommandException)(ar.exception)).getCommandError()
2315 == CommandException.Error.PASSWORD_INCORRECT) {
2316 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002317 } //When UiccCardApp dispose,handle message and return exception
2318 else if (ar.exception instanceof CommandException &&
2319 ((CommandException) (ar.exception)).getCommandError()
2320 == CommandException.Error.ABORTED) {
2321 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002322 } else {
2323 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2324 }
2325 } else {
2326 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2327 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002328 mDone = true;
2329 UnlockSim.this.notifyAll();
2330 }
2331 break;
2332 }
2333 }
2334 };
2335 UnlockSim.this.notifyAll();
2336 }
2337 Looper.loop();
2338 }
2339
2340 /*
2341 * Use PIN or PUK to unlock SIM card
2342 *
2343 * If PUK is null, unlock SIM card with PIN
2344 *
2345 * If PUK is not null, unlock SIM card with PUK and set PIN code
2346 */
Wink Saville9de0f752013-10-22 19:04:03 -07002347 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348
2349 while (mHandler == null) {
2350 try {
2351 wait();
2352 } catch (InterruptedException e) {
2353 Thread.currentThread().interrupt();
2354 }
2355 }
2356 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2357
2358 if (puk == null) {
2359 mSimCard.supplyPin(pin, callback);
2360 } else {
2361 mSimCard.supplyPuk(puk, pin, callback);
2362 }
2363
2364 while (!mDone) {
2365 try {
2366 Log.d(LOG_TAG, "wait for done");
2367 wait();
2368 } catch (InterruptedException e) {
2369 // Restore the interrupted status
2370 Thread.currentThread().interrupt();
2371 }
2372 }
2373 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002374 int[] resultArray = new int[2];
2375 resultArray[0] = mResult;
2376 resultArray[1] = mRetryCount;
Michele Berionned9fbae52020-11-13 02:36:59 +00002377
2378 if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) {
2379 UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId);
2380 }
2381
Wink Saville9de0f752013-10-22 19:04:03 -07002382 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002383 }
2384 }
2385
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002386 /**
2387 * This method has been removed due to privacy and stability concerns.
2388 */
2389 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002390 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002391 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2392 return;
Wink Saville36469e72014-06-11 15:17:00 -07002393 }
2394
Nathan Harold1f889d82020-06-04 17:05:26 -07002395 @Override
2396 public void updateServiceLocationWithPackageName(String callingPackage) {
2397 mApp.getSystemService(AppOpsManager.class)
2398 .checkPackage(Binder.getCallingUid(), callingPackage);
2399
Nathan Haroldf096d982020-11-18 17:18:06 -08002400 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002401 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2402 // Callers targeting S have no business invoking this method.
2403 return;
2404 }
2405
2406 LocationAccessPolicy.LocationPermissionResult locationResult =
2407 LocationAccessPolicy.checkLocationPermission(mApp,
2408 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2409 .setCallingPackage(callingPackage)
2410 .setCallingFeatureId(null)
2411 .setCallingPid(Binder.getCallingPid())
2412 .setCallingUid(Binder.getCallingUid())
2413 .setMethod("updateServiceLocation")
2414 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2415 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2416 .build());
2417 // Apps that lack location permission have no business calling this method;
2418 // however, because no permission was declared in the public API, denials must
2419 // all be "soft".
2420 switch (locationResult) {
2421 case DENIED_HARD: /* fall through */
2422 case DENIED_SOFT:
2423 return;
2424 }
2425
2426 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002427 final long identity = Binder.clearCallingIdentity();
2428 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002429 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002430 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002431 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432 }
2433 } finally {
2434 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002435 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002436 }
2437
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002438 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002439 @Override
2440 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002442 }
2443
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002444
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002445 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002446 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2447 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2448 callingFeatureId);
2449 }
2450
2451 @Deprecated
2452 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002453 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002454 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2455 }
2456
2457 @Override
2458 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2459 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002461 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002462 return false;
2463 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002464
2465 final long identity = Binder.clearCallingIdentity();
2466 try {
2467 return isRadioOnForSubscriber(subId);
2468 } finally {
2469 Binder.restoreCallingIdentity(identity);
2470 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002471 }
2472
2473 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002474 final long identity = Binder.clearCallingIdentity();
2475 try {
2476 final Phone phone = getPhone(subId);
2477 if (phone != null) {
2478 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2479 } else {
2480 return false;
2481 }
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
2486
2487 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002488 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002489 }
Wink Saville36469e72014-06-11 15:17:00 -07002490
Wink Savilleb564aae2014-10-23 10:18:09 -07002491 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002492 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493
2494 final long identity = Binder.clearCallingIdentity();
2495 try {
2496 final Phone phone = getPhone(subId);
2497 if (phone != null) {
2498 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2499 }
2500 } finally {
2501 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002502 }
Wink Saville36469e72014-06-11 15:17:00 -07002503 }
2504
2505 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002506 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002507 }
2508
Wink Savilleb564aae2014-10-23 10:18:09 -07002509 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002510 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002511
2512 final long identity = Binder.clearCallingIdentity();
2513 try {
2514 final Phone phone = getPhone(subId);
2515 if (phone == null) {
2516 return false;
2517 }
2518 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2519 toggleRadioOnOffForSubscriber(subId);
2520 }
2521 return true;
2522 } finally {
2523 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002525 }
Wink Saville36469e72014-06-11 15:17:00 -07002526
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002527 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002528 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002529 /*
2530 * If any of the Radios are available, it will need to be
2531 * shutdown. So return true if any Radio is available.
2532 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002533 final long identity = Binder.clearCallingIdentity();
2534 try {
2535 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2536 Phone phone = PhoneFactory.getPhone(i);
2537 if (phone != null && phone.isRadioAvailable()) return true;
2538 }
2539 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2540 return false;
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002543 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002544 }
2545
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002546 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002547 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548 enforceModifyPermission();
2549
2550 final long identity = Binder.clearCallingIdentity();
2551 try {
2552 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2553 logv("Shutting down Phone " + i);
2554 shutdownRadioUsingPhoneId(i);
2555 }
2556 } finally {
2557 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002558 }
2559 }
2560
2561 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002562 Phone phone = PhoneFactory.getPhone(phoneId);
2563 if (phone != null && phone.isRadioAvailable()) {
2564 phone.shutdownRadio();
2565 }
2566 }
2567
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002569 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002570
2571 final long identity = Binder.clearCallingIdentity();
2572 try {
2573 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2574 if (defaultPhone != null) {
2575 defaultPhone.setRadioPower(turnOn);
2576 return true;
2577 } else {
2578 loge("There's no default phone.");
2579 return false;
2580 }
2581 } finally {
2582 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002583 }
Wink Saville36469e72014-06-11 15:17:00 -07002584 }
2585
Wink Savilleb564aae2014-10-23 10:18:09 -07002586 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 final Phone phone = getPhone(subId);
2592 if (phone != null) {
2593 phone.setRadioPower(turnOn);
2594 return true;
2595 } else {
2596 return false;
2597 }
2598 } finally {
2599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002601 }
2602
Wink Saville36469e72014-06-11 15:17:00 -07002603 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002604 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002605 public boolean enableDataConnectivity() {
2606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607
2608 final long identity = Binder.clearCallingIdentity();
2609 try {
2610 int subId = mSubscriptionController.getDefaultDataSubId();
2611 final Phone phone = getPhone(subId);
2612 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002613 phone.getDataEnabledSettings().setDataEnabled(
2614 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002615 return true;
2616 } else {
2617 return false;
2618 }
2619 } finally {
2620 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002621 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002622 }
2623
Wink Saville36469e72014-06-11 15:17:00 -07002624 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002625 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002626 public boolean disableDataConnectivity() {
2627 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002628
2629 final long identity = Binder.clearCallingIdentity();
2630 try {
2631 int subId = mSubscriptionController.getDefaultDataSubId();
2632 final Phone phone = getPhone(subId);
2633 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002634 phone.getDataEnabledSettings().setDataEnabled(
2635 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 return true;
2637 } else {
2638 return false;
2639 }
2640 } finally {
2641 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002643 }
2644
Sanket Padawe356d7632015-06-22 14:03:32 -07002645 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002646 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 final Phone phone = getPhone(subId);
2650 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002651 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 } else {
2653 return false;
2654 }
2655 } finally {
2656 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002657 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002658 }
2659
2660 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002661 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002662 }
2663
pkanwarae03a6b2016-11-06 20:37:09 -08002664 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002665 enforceCallPermission();
2666
2667 final long identity = Binder.clearCallingIdentity();
2668 try {
2669 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2670 return;
2671 }
2672 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2673 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2674 } finally {
2675 Binder.restoreCallingIdentity(identity);
2676 }
pkanwar32d516d2016-10-14 19:37:38 -07002677 };
2678
Wink Savilleb564aae2014-10-23 10:18:09 -07002679 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002681
2682 final long identity = Binder.clearCallingIdentity();
2683 try {
2684 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2685 return false;
2686 }
2687 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2688 } finally {
2689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002690 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 }
2692
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002693 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002694 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002695 }
2696
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002697 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002698 final long identity = Binder.clearCallingIdentity();
2699 try {
2700 Phone phone = PhoneFactory.getPhone(slotIndex);
2701 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2702 PhoneConstantConversions.convertCallState(phone.getState());
2703 } finally {
2704 Binder.restoreCallingIdentity(identity);
2705 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 }
2707
Sanket Padawe356d7632015-06-22 14:03:32 -07002708 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002709 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002710 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2711 }
2712
2713 @Override
2714 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002715 final long identity = Binder.clearCallingIdentity();
2716 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002717 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002718 if (phone != null) {
2719 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2720 } else {
2721 return PhoneConstantConversions.convertDataState(
2722 PhoneConstants.DataState.DISCONNECTED);
2723 }
2724 } finally {
2725 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002726 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002727 }
2728
Sanket Padawe356d7632015-06-22 14:03:32 -07002729 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002730 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002731 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2732 }
2733
2734 @Override
2735 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002736 final long identity = Binder.clearCallingIdentity();
2737 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002738 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 if (phone != null) {
2740 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2741 } else {
2742 return TelephonyManager.DATA_ACTIVITY_NONE;
2743 }
2744 } finally {
2745 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002746 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002747 }
2748
2749 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002750 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002751 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002752 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002753
2754 LocationAccessPolicy.LocationPermissionResult locationResult =
2755 LocationAccessPolicy.checkLocationPermission(mApp,
2756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2757 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002759 .setCallingPid(Binder.getCallingPid())
2760 .setCallingUid(Binder.getCallingUid())
2761 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002762 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002763 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2764 .build());
2765 switch (locationResult) {
2766 case DENIED_HARD:
2767 throw new SecurityException("Not allowed to access cell location");
2768 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002769 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2770 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002773 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002774 final long identity = Binder.clearCallingIdentity();
2775 try {
2776 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002777 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002778 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002779 } finally {
2780 Binder.restoreCallingIdentity(identity);
2781 }
Svetoslav64fad262015-04-14 14:35:21 -07002782 }
2783
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002784 @Override
Jack Yu01425032020-02-22 19:38:58 -08002785 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002786 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2787 // registered cell info, so return a NULL country instead.
2788 final long identity = Binder.clearCallingIdentity();
2789 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002790 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2791 // Get default phone in this case.
2792 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2793 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002794 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002795 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002796 if (phone == null) return "";
2797 ServiceStateTracker sst = phone.getServiceStateTracker();
2798 if (sst == null) return "";
2799 LocaleTracker lt = sst.getLocaleTracker();
2800 if (lt == null) return "";
2801 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2802 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2803 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002804 } finally {
2805 Binder.restoreCallingIdentity(identity);
2806 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002807 }
2808
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002809 /**
2810 * This method was removed due to potential issues caused by performing partial
2811 * updates of service state, and lack of a credible use case.
2812 *
2813 * This has the ability to break the telephony implementation by disabling notification of
2814 * changes in device connectivity. DO NOT USE THIS!
2815 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002816 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002817 public void enableLocationUpdates() {
2818 mApp.enforceCallingOrSelfPermission(
2819 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002820 }
2821
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002822 /**
2823 * This method was removed due to potential issues caused by performing partial
2824 * updates of service state, and lack of a credible use case.
2825 *
2826 * This has the ability to break the telephony implementation by disabling notification of
2827 * changes in device connectivity. DO NOT USE THIS!
2828 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002829 @Override
2830 public void disableLocationUpdates() {
2831 mApp.enforceCallingOrSelfPermission(
2832 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002833 }
2834
2835 @Override
2836 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002837 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2838 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002839 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002840 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2841 throw new SecurityException(
2842 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2843 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002844
Jordan Liu1617b712019-07-10 15:06:26 -07002845 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002846 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2847 return null;
2848 }
Svetoslav64fad262015-04-14 14:35:21 -07002849
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002850 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002852 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002853 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002854
Nathan Haroldf180aac2018-06-01 18:43:55 -07002855 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2856 for (CellInfo ci : info) {
2857 if (ci instanceof CellInfoGsm) {
2858 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2859 } else if (ci instanceof CellInfoWcdma) {
2860 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2861 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002862 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002863 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002864 }
2865
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002866 private List<CellInfo> getCachedCellInfo() {
2867 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2868 for (Phone phone : PhoneFactory.getPhones()) {
2869 List<CellInfo> info = phone.getAllCellInfo();
2870 if (info != null) cellInfos.addAll(info);
2871 }
2872 return cellInfos;
2873 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002874
2875 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002876 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002877 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002878 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002879
2880 LocationAccessPolicy.LocationPermissionResult locationResult =
2881 LocationAccessPolicy.checkLocationPermission(mApp,
2882 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2883 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002884 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002885 .setCallingPid(Binder.getCallingPid())
2886 .setCallingUid(Binder.getCallingUid())
2887 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002888 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002889 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2890 .build());
2891 switch (locationResult) {
2892 case DENIED_HARD:
2893 throw new SecurityException("Not allowed to access cell info");
2894 case DENIED_SOFT:
2895 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002896 }
2897
Nathan Haroldf096d982020-11-18 17:18:06 -08002898 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002899 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2900 return getCachedCellInfo();
2901 }
2902
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002903 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002904 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002905 final long identity = Binder.clearCallingIdentity();
2906 try {
2907 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2908 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002909 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002910 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002911 if (info != null) cellInfos.addAll(info);
2912 }
2913 return cellInfos;
2914 } finally {
2915 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002916 }
2917 }
2918
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002919 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002920 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2921 String callingFeatureId) {
2922 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2923 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002924 }
2925
2926 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002927 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2928 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002930 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002931 }
2932
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002933 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2934 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002935 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002936 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002937
2938 LocationAccessPolicy.LocationPermissionResult locationResult =
2939 LocationAccessPolicy.checkLocationPermission(mApp,
2940 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2941 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002942 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002943 .setCallingPid(Binder.getCallingPid())
2944 .setCallingUid(Binder.getCallingUid())
2945 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002946 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2947 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002948 .build());
2949 switch (locationResult) {
2950 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002951 if (TelephonyPermissions
2952 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002953 // Safetynet logging for b/154934934
2954 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2955 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002956 throw new SecurityException("Not allowed to access cell info");
2957 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002958 if (TelephonyPermissions
2959 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002960 // Safetynet logging for b/154934934
2961 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2962 }
Nathan Harold5320c422019-05-09 10:26:08 -07002963 try {
2964 cb.onCellInfo(new ArrayList<CellInfo>());
2965 } catch (RemoteException re) {
2966 // Drop without consequences
2967 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002968 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002969 }
2970
Nathan Harolda939a962019-05-09 10:13:47 -07002971
2972 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002973 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2974
2975 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2976 }
2977
2978 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002979 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002980 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002981 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002982
2983 final long identity = Binder.clearCallingIdentity();
2984 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002985 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002989 }
2990
Shishir Agrawala9f32182016-04-12 12:00:16 -07002991 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002992 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002993 Phone phone = PhoneFactory.getPhone(slotIndex);
2994 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002995 return null;
2996 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002997 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002998 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002999 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003000 return null;
3001 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003002
3003 final long identity = Binder.clearCallingIdentity();
3004 try {
3005 return phone.getImei();
3006 } finally {
3007 Binder.restoreCallingIdentity(identity);
3008 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003009 }
3010
3011 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003012 public String getTypeAllocationCodeForSlot(int slotIndex) {
3013 Phone phone = PhoneFactory.getPhone(slotIndex);
3014 String tac = null;
3015 if (phone != null) {
3016 String imei = phone.getImei();
3017 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
3018 }
3019 return tac;
3020 }
3021
3022 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003023 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003024 Phone phone = PhoneFactory.getPhone(slotIndex);
3025 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07003026 return null;
3027 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003028
Jeff Davidson913390f2018-02-23 17:11:49 -08003029 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07003030 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003031 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003032 return null;
3033 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 return phone.getMeid();
3038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Jack Yu2af8d712017-03-15 17:14:14 -07003041 }
3042
3043 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003044 public String getManufacturerCodeForSlot(int slotIndex) {
3045 Phone phone = PhoneFactory.getPhone(slotIndex);
3046 String manufacturerCode = null;
3047 if (phone != null) {
3048 String meid = phone.getMeid();
3049 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3050 }
3051 return manufacturerCode;
3052 }
3053
3054 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003055 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3056 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003057 Phone phone = PhoneFactory.getPhone(slotIndex);
3058 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003059 return null;
3060 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003061 int subId = phone.getSubId();
3062 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003063 mApp, subId, callingPackage, callingFeatureId,
3064 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003065 return null;
3066 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003067
3068 final long identity = Binder.clearCallingIdentity();
3069 try {
3070 return phone.getDeviceSvn();
3071 } finally {
3072 Binder.restoreCallingIdentity(identity);
3073 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003074 }
3075
fionaxu43304da2017-11-27 22:51:16 -08003076 @Override
3077 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3082 } finally {
3083 Binder.restoreCallingIdentity(identity);
3084 }
fionaxu43304da2017-11-27 22:51:16 -08003085 }
3086
3087 @Override
3088 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089 final long identity = Binder.clearCallingIdentity();
3090 try {
3091 final Phone phone = getPhone(subId);
3092 return phone == null ? null : phone.getCarrierName();
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
fionaxu43304da2017-11-27 22:51:16 -08003096 }
3097
calvinpanffe225e2018-11-01 19:43:06 +08003098 @Override
chen xu0026ca62019-03-06 15:28:50 -08003099 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 final Phone phone = getPhone(subId);
3103 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003104 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003105 } finally {
3106 Binder.restoreCallingIdentity(identity);
3107 }
3108 }
3109
3110 @Override
chen xu0026ca62019-03-06 15:28:50 -08003111 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003112 final long identity = Binder.clearCallingIdentity();
3113 try {
3114 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003115 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003116 } finally {
3117 Binder.restoreCallingIdentity(identity);
3118 }
3119 }
3120
chen xu651eec72018-11-11 19:03:44 -08003121 @Override
chen xu864e11c2018-12-06 22:10:03 -08003122 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3123 if (!isSubscriptionMccMnc) {
3124 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3125 }
chen xu651eec72018-11-11 19:03:44 -08003126 final Phone phone = PhoneFactory.getPhone(slotIndex);
3127 if (phone == null) {
3128 return TelephonyManager.UNKNOWN_CARRIER_ID;
3129 }
3130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
3135 }
3136 }
3137
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003138 //
3139 // Internal helper methods.
3140 //
3141
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003142 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003143 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3144 *
3145 * @throws SecurityException if the caller does not have the required permission
3146 */
3147 private void enforceModifyPermission() {
3148 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3149 }
3150
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003151 /**
3152 * Make sure the caller is system.
3153 *
3154 * @throws SecurityException if the caller is not system.
3155 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003156 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003157 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3158 throw new SecurityException("Caller must be system");
3159 }
3160 }
3161
Shuo Qianf2b2df42019-11-13 17:43:31 -08003162 private void enforceActiveEmergencySessionPermission() {
3163 mApp.enforceCallingOrSelfPermission(
3164 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3165 }
3166
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003167 /**
3168 * Make sure the caller has the CALL_PHONE permission.
3169 *
3170 * @throws SecurityException if the caller does not have the required permission
3171 */
3172 private void enforceCallPermission() {
3173 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3174 }
3175
paulhu423b5f22019-08-23 19:17:33 +08003176 private void enforceSettingsPermission() {
3177 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003178 }
3179
Michele Berionned9fbae52020-11-13 02:36:59 +00003180 private void enforceRebootPermission() {
3181 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null);
3182 }
3183
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 private String createTelUrl(String number) {
3185 if (TextUtils.isEmpty(number)) {
3186 return null;
3187 }
3188
Jake Hambye994d462014-02-03 13:10:13 -08003189 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003190 }
3191
Ihab Awadf9e92732013-12-05 18:02:52 -08003192 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003193 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3194 }
3195
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003196 private static void logv(String msg) {
3197 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3198 }
3199
Ihab Awadf9e92732013-12-05 18:02:52 -08003200 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003201 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3202 }
3203
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003204 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003205 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003206 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003207 }
3208
Sanket Padawe356d7632015-06-22 14:03:32 -07003209 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003210 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003211 final long identity = Binder.clearCallingIdentity();
3212 try {
3213 final Phone phone = PhoneFactory.getPhone(slotIndex);
3214 if (phone == null) {
3215 return PhoneConstants.PHONE_TYPE_NONE;
3216 } else {
3217 return phone.getPhoneType();
3218 }
3219 } finally {
3220 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003221 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003222 }
3223
3224 /**
3225 * Returns the CDMA ERI icon index to display
3226 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003227 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003228 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3229 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3230 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003231 }
3232
Sanket Padawe356d7632015-06-22 14:03:32 -07003233 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003234 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3235 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003236 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003237 mApp, subId, callingPackage, callingFeatureId,
3238 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003239 return -1;
3240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003241
3242 final long identity = Binder.clearCallingIdentity();
3243 try {
3244 final Phone phone = getPhone(subId);
3245 if (phone != null) {
3246 return phone.getCdmaEriIconIndex();
3247 } else {
3248 return -1;
3249 }
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003253 }
3254
3255 /**
3256 * Returns the CDMA ERI icon mode,
3257 * 0 - ON
3258 * 1 - FLASHING
3259 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003261 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3262 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3263 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003264 }
3265
Sanket Padawe356d7632015-06-22 14:03:32 -07003266 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003267 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3268 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003269 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003270 mApp, subId, callingPackage, callingFeatureId,
3271 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003272 return -1;
3273 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003274
3275 final long identity = Binder.clearCallingIdentity();
3276 try {
3277 final Phone phone = getPhone(subId);
3278 if (phone != null) {
3279 return phone.getCdmaEriIconMode();
3280 } else {
3281 return -1;
3282 }
3283 } finally {
3284 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003285 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003286 }
3287
3288 /**
3289 * Returns the CDMA ERI text,
3290 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003291 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003292 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3293 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3294 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003295 }
3296
Sanket Padawe356d7632015-06-22 14:03:32 -07003297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003298 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3299 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003301 mApp, subId, callingPackage, callingFeatureId,
3302 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003303 return null;
3304 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003305
3306 final long identity = Binder.clearCallingIdentity();
3307 try {
3308 final Phone phone = getPhone(subId);
3309 if (phone != null) {
3310 return phone.getCdmaEriText();
3311 } else {
3312 return null;
3313 }
3314 } finally {
3315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003317 }
3318
3319 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003320 * Returns the CDMA MDN.
3321 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003322 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003323 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003324 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3325 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003326
3327 final long identity = Binder.clearCallingIdentity();
3328 try {
3329 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003330 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003331 return phone.getLine1Number();
3332 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003333 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003334 return null;
3335 }
3336 } finally {
3337 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003338 }
3339 }
3340
3341 /**
3342 * Returns the CDMA MIN.
3343 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003344 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003345 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3347 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348
3349 final long identity = Binder.clearCallingIdentity();
3350 try {
3351 final Phone phone = getPhone(subId);
3352 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3353 return phone.getCdmaMin();
3354 } else {
3355 return null;
3356 }
3357 } finally {
3358 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003359 }
3360 }
3361
Hall Liud892bec2018-11-30 14:51:45 -08003362 @Override
3363 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3364 INumberVerificationCallback callback, String callingPackage) {
3365 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3366 != PERMISSION_GRANTED) {
3367 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3368 }
3369 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3370
3371 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3372 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003373 throw new SecurityException("Calling package must be configured in the device config: "
3374 + "calling package: " + callingPackage
3375 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003376 }
3377
3378 if (range == null) {
3379 throw new NullPointerException("Range must be non-null");
3380 }
3381
3382 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003383 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003384
3385 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3386 }
3387
Junda Liuca05d5d2014-08-14 22:36:34 -07003388 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003389 * Returns true if CDMA provisioning needs to run.
3390 */
3391 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003392 final long identity = Binder.clearCallingIdentity();
3393 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003394 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003395 } finally {
3396 Binder.restoreCallingIdentity(identity);
3397 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003398 }
3399
3400 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003401 * Sets the voice mail number of a given subId.
3402 */
3403 @Override
3404 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003405 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3406 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3411 new Pair<String, String>(alphaTag, number), new Integer(subId));
3412 return success;
3413 } finally {
3414 Binder.restoreCallingIdentity(identity);
3415 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003416 }
3417
Ta-wei Yen87c49842016-05-13 21:19:52 -07003418 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003419 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3420 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003421 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3422 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003423 if (!TextUtils.equals(callingPackage, systemDialer)) {
3424 throw new SecurityException("caller must be system dialer");
3425 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003426
3427 final long identity = Binder.clearCallingIdentity();
3428 try {
3429 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3430 if (phoneAccountHandle == null) {
3431 return null;
3432 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003433 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003434 } finally {
3435 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003436 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003437 }
3438
3439 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003440 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3441 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003442 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003444 mApp, subId, callingPackage, callingFeatureId,
3445 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003446 return null;
3447 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003448
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003449 final long identity = Binder.clearCallingIdentity();
3450 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003451 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003452 } finally {
3453 Binder.restoreCallingIdentity(identity);
3454 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003455 }
3456
3457 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003458 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3459 VisualVoicemailSmsFilterSettings settings) {
3460 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003461
3462 final long identity = Binder.clearCallingIdentity();
3463 try {
3464 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003465 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003466 } finally {
3467 Binder.restoreCallingIdentity(identity);
3468 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003469 }
3470
3471 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003472 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3473 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003474
3475 final long identity = Binder.clearCallingIdentity();
3476 try {
3477 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003478 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003479 } finally {
3480 Binder.restoreCallingIdentity(identity);
3481 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003482 }
3483
3484 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003485 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3486 String callingPackage, int subId) {
3487 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003488
3489 final long identity = Binder.clearCallingIdentity();
3490 try {
3491 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003492 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003493 } finally {
3494 Binder.restoreCallingIdentity(identity);
3495 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003496 }
3497
3498 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003499 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003500 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003501
3502 final long identity = Binder.clearCallingIdentity();
3503 try {
3504 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003505 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003506 } finally {
3507 Binder.restoreCallingIdentity(identity);
3508 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003509 }
3510
3511 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003512 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3513 String callingAttributionTag, int subId, String number, int port, String text,
3514 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003515 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003516 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003517 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003518 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003519 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3520 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003521 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003522
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003523 /**
fionaxu0152e512016-11-14 13:36:14 -08003524 * Sets the voice activation state of a given subId.
3525 */
3526 @Override
3527 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003528 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3529 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003530
3531 final long identity = Binder.clearCallingIdentity();
3532 try {
3533 final Phone phone = getPhone(subId);
3534 if (phone != null) {
3535 phone.setVoiceActivationState(activationState);
3536 } else {
3537 loge("setVoiceActivationState fails with invalid subId: " + subId);
3538 }
3539 } finally {
3540 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003541 }
3542 }
3543
3544 /**
3545 * Sets the data activation state of a given subId.
3546 */
3547 @Override
3548 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003549 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3550 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003551
3552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 final Phone phone = getPhone(subId);
3555 if (phone != null) {
3556 phone.setDataActivationState(activationState);
3557 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003558 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003559 }
3560 } finally {
3561 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003562 }
3563 }
3564
3565 /**
3566 * Returns the voice activation state of a given subId.
3567 */
3568 @Override
3569 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003570 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003571
fionaxu0152e512016-11-14 13:36:14 -08003572 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003573 final long identity = Binder.clearCallingIdentity();
3574 try {
3575 if (phone != null) {
3576 return phone.getVoiceActivationState();
3577 } else {
3578 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003582 }
3583 }
3584
3585 /**
3586 * Returns the data activation state of a given subId.
3587 */
3588 @Override
3589 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591
fionaxu0152e512016-11-14 13:36:14 -08003592 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003593 final long identity = Binder.clearCallingIdentity();
3594 try {
3595 if (phone != null) {
3596 return phone.getDataActivationState();
3597 } else {
3598 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3599 }
3600 } finally {
3601 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003602 }
3603 }
3604
3605 /**
Wink Saville36469e72014-06-11 15:17:00 -07003606 * Returns the unread count of voicemails for a subId
3607 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003608 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003609 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3610 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003611 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003612 mApp, subId, callingPackage, callingFeatureId,
3613 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003614 return 0;
3615 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 final Phone phone = getPhone(subId);
3619 if (phone != null) {
3620 return phone.getVoiceMessageCount();
3621 } else {
3622 return 0;
3623 }
3624 } finally {
3625 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003626 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003627 }
3628
3629 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003630 * returns true, if the device is in a state where both voice and data
3631 * are supported simultaneously. This can change based on location or network condition.
3632 */
3633 @Override
3634 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 final Phone phone = getPhone(subId);
3638 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3639 } finally {
3640 Binder.restoreCallingIdentity(identity);
3641 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003642 }
3643
3644 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003645 * Send the dialer code if called from the current default dialer or the caller has
3646 * carrier privilege.
3647 * @param inputCode The dialer code to send
3648 */
3649 @Override
3650 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003651 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003652 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003653 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3654 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003655 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003656 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003657 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003658 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003659
3660 final long identity = Binder.clearCallingIdentity();
3661 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003662 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003663 } finally {
3664 Binder.restoreCallingIdentity(identity);
3665 }
fionaxu235cc5e2017-03-06 22:25:57 -08003666 }
3667
Pengquan Menga1bb6272018-09-06 09:59:22 -07003668 @Override
3669 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003670 TelephonyPermissions
3671 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3672 mApp, subId, "getNetworkSelectionMode");
3673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 if (!isActiveSubscription(subId)) {
3676 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3677 }
3678 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3679 } finally {
3680 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003681 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003682 }
3683
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003685 public boolean isInEmergencySmsMode() {
3686 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 for (Phone phone : PhoneFactory.getPhones()) {
3690 if (phone.isInEmergencySmsMode()) {
3691 return true;
3692 }
3693 }
3694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 return false;
3698 }
3699
shilu366312e2019-12-17 09:28:10 -08003700 /**
3701 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3702 * @param subId The subscription to use to check the configuration.
3703 * @param c The callback that will be used to send the result.
3704 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003705 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003706 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3707 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003708 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3709 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003710
Brad Ebinger77b832e2019-10-17 17:03:22 -07003711 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3712 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3713 "IMS not available on device.");
3714 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003715 final long token = Binder.clearCallingIdentity();
3716 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003717 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003718 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003719 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003720 } catch (ImsException e) {
3721 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 } finally {
3723 Binder.restoreCallingIdentity(token);
3724 }
3725 }
3726
shilu366312e2019-12-17 09:28:10 -08003727 /**
3728 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3729 * @param subId The subscription to use to check the configuration.
3730 * @param c The callback that will be used to send the result.
3731 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003733 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003734 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3735 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003736 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3737 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3738 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003739 final long token = Binder.clearCallingIdentity();
3740 try {
3741 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3742 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3743 .removeRegistrationCallbackForSubscription(c, subId);
3744 } catch (ImsException e) {
3745 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3746 + "is inactive, ignoring unregister.");
3747 // If the subscription is no longer active, just return, since the callback
3748 // will already have been removed internally.
3749 } finally {
3750 Binder.restoreCallingIdentity(token);
3751 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 }
3753
Brad Ebinger774ba362019-10-22 17:36:18 -07003754 /**
3755 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3756 */
3757 @Override
3758 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3759 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3760 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3761 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3762 "IMS not available on device.");
3763 }
3764 final long token = Binder.clearCallingIdentity();
3765 try {
3766 Phone phone = getPhone(subId);
3767 if (phone == null) {
3768 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3769 + subId + "'");
3770 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3771 }
3772 phone.getImsRegistrationState(regState -> {
3773 try {
3774 consumer.accept((regState == null)
3775 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3776 } catch (RemoteException e) {
3777 // Ignore if the remote process is no longer available to call back.
3778 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3779 }
3780 });
3781 } finally {
3782 Binder.restoreCallingIdentity(token);
3783 }
3784 }
3785
3786 /**
3787 * Get the transport type for the IMS service registration state.
3788 */
3789 @Override
3790 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003791 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3792 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003793 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3794 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3795 "IMS not available on device.");
3796 }
3797 final long token = Binder.clearCallingIdentity();
3798 try {
3799 Phone phone = getPhone(subId);
3800 if (phone == null) {
3801 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3802 + subId + "'");
3803 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3804 }
3805 phone.getImsRegistrationTech(regTech -> {
3806 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3807 int regTechConverted = (regTech == null)
3808 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3809 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3810 regTechConverted);
3811 try {
3812 consumer.accept(regTechConverted);
3813 } catch (RemoteException e) {
3814 // Ignore if the remote process is no longer available to call back.
3815 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3816 }
3817 });
3818 } finally {
3819 Binder.restoreCallingIdentity(token);
3820 }
3821 }
3822
shilu366312e2019-12-17 09:28:10 -08003823 /**
3824 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3825 * @param subId The subscription to use to check the configuration.
3826 * @param c The callback that will be used to send the result.
3827 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003828 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003829 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3830 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003831 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3832 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003833 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3834 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3835 "IMS not available on device.");
3836 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003837 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3838 final long token = Binder.clearCallingIdentity();
3839 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003840 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003841 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003842 } catch (ImsException e) {
3843 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003844 } finally {
3845 Binder.restoreCallingIdentity(token);
3846 }
3847 }
3848
shilu366312e2019-12-17 09:28:10 -08003849 /**
3850 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3851 * @param subId The subscription to use to check the configuration.
3852 * @param c The callback that will be used to send the result.
3853 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003854 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003855 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003856 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3857 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003858 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3859 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3860 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003861
3862 final long token = Binder.clearCallingIdentity();
3863 try {
3864 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3865 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003866 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003867 } catch (ImsException e) {
3868 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3869 + "is inactive, ignoring unregister.");
3870 // If the subscription is no longer active, just return, since the callback
3871 // will already have been removed internally.
3872 } finally {
3873 Binder.restoreCallingIdentity(token);
3874 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003875 }
3876
3877 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003878 public boolean isCapable(int subId, int capability, int regTech) {
3879 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003880 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3881 final long token = Binder.clearCallingIdentity();
3882 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003883 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003884 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003885 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003886 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3887 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003888 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003889 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3890 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003891 } finally {
3892 Binder.restoreCallingIdentity(token);
3893 }
3894 }
3895
3896 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003897 public boolean isAvailable(int subId, int capability, int regTech) {
3898 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 final long token = Binder.clearCallingIdentity();
3900 try {
3901 Phone phone = getPhone(subId);
3902 if (phone == null) return false;
3903 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003904 } catch (com.android.ims.ImsException e) {
3905 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3906 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(token);
3909 }
3910 }
3911
Brad Ebinger77b832e2019-10-17 17:03:22 -07003912 /**
3913 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3914 * subscription.
3915 * @param subId The subscription to use to check the configuration.
3916 * @param callback The callback that will be used to send the result.
3917 * @param capability The MmTelFeature capability that will be used to send the result.
3918 * @param transportType The transport type of the MmTelFeature capability.
3919 */
3920 @Override
3921 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3922 int transportType) {
3923 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3924 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3925 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3926 "IMS not available on device.");
3927 }
3928 final long token = Binder.clearCallingIdentity();
3929 try {
3930 int slotId = getSlotIndex(subId);
3931 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3932 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3933 + subId + "'");
3934 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3935 }
3936 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3937 transportType, aBoolean -> {
3938 try {
3939 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3940 } catch (RemoteException e) {
3941 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3942 + "running. Ignore");
3943 }
3944 });
3945 } finally {
3946 Binder.restoreCallingIdentity(token);
3947 }
3948 }
3949
shilu366312e2019-12-17 09:28:10 -08003950 /**
3951 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3952 * @param subId The subscription to use to check the configuration.
3953 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003954 @Override
3955 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003956 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3957 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003958
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3960 final long token = Binder.clearCallingIdentity();
3961 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003962 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003963 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003964 } catch (ImsException e) {
3965 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 } finally {
3967 Binder.restoreCallingIdentity(token);
3968 }
3969 }
3970
3971 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003972 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003973 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003974 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003978 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003980 } catch (ImsException e) {
3981 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003982 } finally {
3983 Binder.restoreCallingIdentity(identity);
3984 }
3985 }
3986
shilu366312e2019-12-17 09:28:10 -08003987 /**
3988 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3989 * @param subId The subscription to use to check the configuration.
3990 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003991 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003992 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003993 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3994 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 final long identity = Binder.clearCallingIdentity();
3996 try {
3997 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003998 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3999 } catch (ImsException e) {
4000 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 } finally {
4002 Binder.restoreCallingIdentity(identity);
4003 }
4004 }
4005
4006 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004007 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004008 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004009 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 final long identity = Binder.clearCallingIdentity();
4011 try {
4012 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004013 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004014 } catch (ImsException e) {
4015 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 } finally {
4017 Binder.restoreCallingIdentity(identity);
4018 }
4019 }
4020
shilu366312e2019-12-17 09:28:10 -08004021 /**
4022 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4023 * @param subId The subscription to use to check the configuration.
4024 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004025 @Override
4026 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004027 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4028 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004029 final long identity = Binder.clearCallingIdentity();
4030 try {
4031 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004032 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004033 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004034 } catch (ImsException e) {
4035 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 } finally {
4037 Binder.restoreCallingIdentity(identity);
4038 }
4039 }
4040
4041 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004042 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004044 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004045 final long identity = Binder.clearCallingIdentity();
4046 try {
4047 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004048 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004049 } catch (ImsException e) {
4050 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004051 } finally {
4052 Binder.restoreCallingIdentity(identity);
4053 }
4054 }
4055
shilu366312e2019-12-17 09:28:10 -08004056 /**
4057 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4058 * @param subId The subscription to use to check the configuration.
4059 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004060 @Override
4061 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004062 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4063 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004064 final long identity = Binder.clearCallingIdentity();
4065 try {
4066 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004067 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004069 } catch (ImsException e) {
4070 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004071 } finally {
4072 Binder.restoreCallingIdentity(identity);
4073 }
4074 }
4075
4076 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004077 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004078 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004079 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004080 final long identity = Binder.clearCallingIdentity();
4081 try {
4082 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004083 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004084 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004085 } catch (ImsException e) {
4086 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004087 } finally {
4088 Binder.restoreCallingIdentity(identity);
4089 }
4090 }
4091
4092 @Override
4093 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4095 "setVoWiFiNonPersistent");
4096 final long identity = Binder.clearCallingIdentity();
4097 try {
4098 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004099 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004100 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004101 } catch (ImsException e) {
4102 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004103 } finally {
4104 Binder.restoreCallingIdentity(identity);
4105 }
4106 }
4107
shilu366312e2019-12-17 09:28:10 -08004108 /**
4109 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4110 * @param subId The subscription to use to check the configuration.
4111 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004112 @Override
4113 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004114 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4115 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004116 final long identity = Binder.clearCallingIdentity();
4117 try {
4118 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004119 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004120 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004121 } catch (ImsException e) {
4122 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 } finally {
4124 Binder.restoreCallingIdentity(identity);
4125 }
4126 }
4127
4128 @Override
4129 public void setVoWiFiModeSetting(int subId, int mode) {
4130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4131 "setVoWiFiModeSetting");
4132 final long identity = Binder.clearCallingIdentity();
4133 try {
4134 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004135 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004136 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004137 } catch (ImsException e) {
4138 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004139 } finally {
4140 Binder.restoreCallingIdentity(identity);
4141 }
4142 }
4143
4144 @Override
4145 public int getVoWiFiRoamingModeSetting(int subId) {
4146 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4147 final long identity = Binder.clearCallingIdentity();
4148 try {
4149 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004150 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004151 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004152 } catch (ImsException e) {
4153 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 } finally {
4155 Binder.restoreCallingIdentity(identity);
4156 }
4157 }
4158
4159 @Override
4160 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4162 "setVoWiFiRoamingModeSetting");
4163 final long identity = Binder.clearCallingIdentity();
4164 try {
4165 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004166 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004167 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004168 } catch (ImsException e) {
4169 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004170 } finally {
4171 Binder.restoreCallingIdentity(identity);
4172 }
4173 }
4174
4175 @Override
4176 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4178 "setRttCapabilityEnabled");
4179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004182 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4183 } catch (ImsException e) {
4184 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004185 } finally {
4186 Binder.restoreCallingIdentity(identity);
4187 }
4188 }
4189
shilu366312e2019-12-17 09:28:10 -08004190 /**
4191 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4192 * @param subId The subscription to use to check the configuration.
4193 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004194 @Override
4195 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004196 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4197 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004198 final long identity = Binder.clearCallingIdentity();
4199 try {
4200 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004201 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004202 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (ImsException e) {
4204 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004205 } finally {
4206 Binder.restoreCallingIdentity(identity);
4207 }
4208 }
4209
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004210 @Override
4211 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4212 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4213 final long identity = Binder.clearCallingIdentity();
4214 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004215 if (!isImsAvailableOnDevice()) {
4216 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4217 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004218 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004220 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004221 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004222 } catch (ImsException e) {
4223 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004224 } finally {
4225 Binder.restoreCallingIdentity(identity);
4226 }
4227 }
4228
4229 @Override
4230 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4231 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4232 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004233 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4234 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4235 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004236 try {
4237 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004238 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004239 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004241 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4242 + "is inactive, ignoring unregister.");
4243 // If the subscription is no longer active, just return, since the callback will already
4244 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004245 } finally {
4246 Binder.restoreCallingIdentity(identity);
4247 }
4248 }
4249
allenwtsu99c623b2020-01-03 18:24:23 +08004250
4251 private void checkModifyPhoneStatePermission(int subId, String message) {
4252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4253 message);
4254 }
4255
4256 private boolean isImsProvisioningRequired(int subId, int capability,
4257 boolean isMmtelCapability) {
4258 Phone phone = getPhone(subId);
4259 if (phone == null) {
4260 loge("phone instance null for subid " + subId);
4261 return false;
4262 }
4263 if (isMmtelCapability) {
4264 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4265 return false;
4266 }
4267 } else {
4268 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4269 return false;
4270 }
4271 }
4272 return true;
4273 }
4274
4275 @Override
4276 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4277 boolean isProvisioned) {
4278 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4279
4280 final long identity = Binder.clearCallingIdentity();
4281 try {
4282 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4283 if (!isImsProvisioningRequired(subId, capability, false)) {
4284 return;
4285 }
4286
4287 // this capability requires provisioning, route to the correct API.
4288 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4289 switch (capability) {
4290 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4291 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4292 ims.setEabProvisioned(isProvisioned);
4293 break;
4294 default: {
4295 throw new IllegalArgumentException("Tried to set provisioning for "
4296 + "rcs capability '" + capability + "', which does not require "
4297 + "provisioning.");
4298 }
4299 }
4300 } finally {
4301 Binder.restoreCallingIdentity(identity);
4302 }
4303
4304 }
4305
4306
4307 @Override
4308 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4309 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4310 final long identity = Binder.clearCallingIdentity();
4311 try {
4312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4313 if (!isImsProvisioningRequired(subId, capability, false)) {
4314 return true;
4315 }
4316
4317 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4318 switch (capability) {
4319 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4320 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4321 return ims.isEabProvisionedOnDevice();
4322
4323 default: {
4324 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4325 + "capability '" + capability + "', which does not require "
4326 + "provisioning.");
4327 }
4328 }
4329
4330 } finally {
4331 Binder.restoreCallingIdentity(identity);
4332 }
4333 }
4334
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004335 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004336 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4337 boolean isProvisioned) {
4338 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4339 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4340 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4341 }
allenwtsu99c623b2020-01-03 18:24:23 +08004342 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004346 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004347 return;
4348 }
4349
4350 // this capability requires provisioning, route to the correct API.
4351 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4352 switch (capability) {
4353 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4354 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4355 ims.setVolteProvisioned(isProvisioned);
4356 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4357 ims.setWfcProvisioned(isProvisioned);
4358 }
4359 break;
4360 }
4361 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4362 // There is currently no difference in VT provisioning type.
4363 ims.setVtProvisioned(isProvisioned);
4364 break;
4365 }
4366 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4367 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4368 // change the capability of the feature instead if needed.
4369 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4370 == isProvisioned) {
4371 // No change in provisioning.
4372 return;
4373 }
4374 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4375 try {
4376 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004377 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004378 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4379 + ", Exception" + e.getMessage());
4380 }
4381 break;
4382 }
4383 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004384 throw new IllegalArgumentException("Tried to set provisioning for "
4385 + "MmTel capability '" + capability + "', which does not require "
4386 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004387 }
4388 }
4389
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
4392 }
4393 }
4394
4395 @Override
4396 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4397 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4398 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4399 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4400 }
4401 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4402 final long identity = Binder.clearCallingIdentity();
4403 try {
4404 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004405 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004406 return true;
4407 }
4408
4409 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4410 switch (capability) {
4411 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4412 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4413 return ims.isVolteProvisionedOnDevice();
4414 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4415 return ims.isWfcProvisionedOnDevice();
4416 }
4417 // This should never happen, since we are checking tech above to make sure it
4418 // is either LTE or IWLAN.
4419 throw new IllegalArgumentException("Invalid radio technology for voice "
4420 + "capability.");
4421 }
4422 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4423 // There is currently no difference in VT provisioning type.
4424 return ims.isVtProvisionedOnDevice();
4425 }
4426 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4427 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4428 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4429 }
4430 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004431 throw new IllegalArgumentException(
4432 "Tried to get provisioning for MmTel capability '" + capability
4433 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004434 }
4435 }
4436
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
4440 }
4441
4442 @Override
4443 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4444 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4445 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4446 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4447 }
4448 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4449 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4450 return (provisionedBits & capability) > 0;
4451 }
4452
4453 @Override
4454 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4455 boolean isProvisioned) {
4456 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4457 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4458 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4459 }
4460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4461 "setProvisioningStatusForCapability");
4462 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4463 // If the current provisioning status for capability already matches isProvisioned,
4464 // do nothing.
4465 if (((provisionedBits & capability) > 0) == isProvisioned) {
4466 return;
4467 }
4468 if (isProvisioned) {
4469 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4470 } else {
4471 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4472 }
4473 }
4474
4475 /**
4476 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4477 * technology. The bitfield should mirror the bitfield defined by
4478 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4479 */
4480 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4481 String key = getMmTelProvisioningKey(subId, tech);
4482 // Default is no capabilities are provisioned.
4483 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4484 }
4485
4486 /**
4487 * Sets the MmTel capability provisioning bitfield (defined by
4488 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4489 * technology specified.
4490 *
4491 * Note: This is a synchronous command and should not be called on UI thread.
4492 */
4493 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4494 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4495 String key = getMmTelProvisioningKey(subId, tech);
4496 editor.putInt(key, newField);
4497 editor.commit();
4498 }
4499
4500 private static String getMmTelProvisioningKey(int subId, int tech) {
4501 // resulting key is provision_ims_mmtel_{subId}_{tech}
4502 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4503 }
4504
4505 /**
4506 * Query CarrierConfig to see if the specified capability requires provisioning for the
4507 * carrier associated with the subscription id.
4508 */
4509 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4510 int capability) {
4511 CarrierConfigManager configManager = new CarrierConfigManager(context);
4512 PersistableBundle c = configManager.getConfigForSubId(subId);
4513 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004514 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004515 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4516 false);
4517 boolean requireVoiceVtProvisioning = c.getBoolean(
4518 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4519
4520 // First check to make sure that the capability requires provisioning.
4521 switch (capability) {
4522 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4523 // intentional fallthrough
4524 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4525 if (requireVoiceVtProvisioning) {
4526 // Voice and Video requires provisioning
4527 return true;
4528 }
4529 break;
4530 }
4531 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4532 if (requireUtProvisioning) {
4533 // UT requires provisioning
4534 return true;
4535 }
4536 break;
4537 }
4538 }
4539 return false;
4540 }
4541
allenwtsu99c623b2020-01-03 18:24:23 +08004542 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4543 int capability) {
4544 CarrierConfigManager configManager = new CarrierConfigManager(context);
4545 PersistableBundle c = configManager.getConfigForSubId(subId);
4546
4547 boolean requireRcsProvisioning = c.getBoolean(
4548 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4549
4550 // First check to make sure that the capability requires provisioning.
4551 switch (capability) {
4552 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4553 // intentional fallthrough
4554 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4555 if (requireRcsProvisioning) {
4556 // OPTION or PRESENCE requires provisioning
4557 return true;
4558 }
4559 break;
4560 }
4561 }
4562 return false;
4563 }
4564
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004565 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004567 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4568 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4569 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004570 enforceReadPrivilegedPermission("getImsProvisioningInt");
4571 final long identity = Binder.clearCallingIdentity();
4572 try {
4573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004574 int slotId = getSlotIndex(subId);
4575 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4576 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4577 + subId + "' for key:" + key);
4578 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4579 }
4580 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004581 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004582 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4583 + subId + "' for key:" + key);
4584 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004585 } finally {
4586 Binder.restoreCallingIdentity(identity);
4587 }
4588 }
4589
4590 @Override
4591 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4593 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4594 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004595 enforceReadPrivilegedPermission("getImsProvisioningString");
4596 final long identity = Binder.clearCallingIdentity();
4597 try {
4598 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004599 int slotId = getSlotIndex(subId);
4600 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4601 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4602 + subId + "' for key:" + key);
4603 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4604 }
4605 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004606 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4608 + subId + "' for key:" + key);
4609 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004610 } finally {
4611 Binder.restoreCallingIdentity(identity);
4612 }
4613 }
4614
4615 @Override
4616 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004617 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4618 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4619 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004620 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4621 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004622 final long identity = Binder.clearCallingIdentity();
4623 try {
4624 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004625 int slotId = getSlotIndex(subId);
4626 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4627 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4628 + subId + "' for key:" + key);
4629 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4630 }
4631 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004632 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004633 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4634 + "' for key:" + key);
4635 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004636 } finally {
4637 Binder.restoreCallingIdentity(identity);
4638 }
4639 }
4640
4641 @Override
4642 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004643 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4644 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4645 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004646 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4647 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004648 final long identity = Binder.clearCallingIdentity();
4649 try {
4650 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004651 int slotId = getSlotIndex(subId);
4652 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4653 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4654 + subId + "' for key:" + key);
4655 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4656 }
4657 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004658 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004659 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4660 + "' for key:" + key);
4661 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004662 } finally {
4663 Binder.restoreCallingIdentity(identity);
4664 }
4665 }
4666
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004667 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004668 int slotId = SubscriptionManager.getSlotIndex(subId);
4669 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004670 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4671 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004672 }
4673 return slotId;
4674 }
4675
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004676 private int getSlotIndex(int subId) {
4677 int slotId = SubscriptionManager.getSlotIndex(subId);
4678 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4679 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4680 }
4681 return slotId;
4682 }
4683
Wink Saville36469e72014-06-11 15:17:00 -07004684 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004685 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004686 */
4687 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004688 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4689 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004690 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004691 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004692 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004693 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004694 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004695 mApp, subId, callingPackage, callingFeatureId,
4696 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004697 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4698 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004699
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004700 final long identity = Binder.clearCallingIdentity();
4701 try {
4702 final Phone phone = getPhone(subId);
4703 if (phone != null) {
4704 return phone.getServiceState().getDataNetworkType();
4705 } else {
4706 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4707 }
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004710 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004711 }
4712
4713 /**
4714 * Returns the data network type
4715 */
4716 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004717 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4718 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4719 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004720 }
4721
4722 /**
4723 * Returns the data network type for a subId
4724 */
4725 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004726 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4727 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004728 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004729 mApp, subId, callingPackage, callingFeatureId,
4730 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004731 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4732 }
4733
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004734 final long identity = Binder.clearCallingIdentity();
4735 try {
4736 final Phone phone = getPhone(subId);
4737 if (phone != null) {
4738 return phone.getServiceState().getDataNetworkType();
4739 } else {
4740 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4741 }
4742 } finally {
4743 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004744 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004745 }
4746
4747 /**
Wink Saville36469e72014-06-11 15:17:00 -07004748 * Returns the Voice network type for a subId
4749 */
4750 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004751 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4752 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004753 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004754 mApp, subId, callingPackage, callingFeatureId,
4755 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004756 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4757 }
4758
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 final Phone phone = getPhone(subId);
4762 if (phone != null) {
4763 return phone.getServiceState().getVoiceNetworkType();
4764 } else {
4765 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4766 }
4767 } finally {
4768 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004770 }
4771
4772 /**
4773 * @return true if a ICC card is present
4774 */
4775 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004776 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004777 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4778 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004779 }
4780
4781 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004782 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004783 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004785 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004786 final long identity = Binder.clearCallingIdentity();
4787 try {
4788 final Phone phone = PhoneFactory.getPhone(slotIndex);
4789 if (phone != null) {
4790 return phone.getIccCard().hasIccCard();
4791 } else {
4792 return false;
4793 }
4794 } finally {
4795 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004797 }
4798
4799 /**
4800 * Return if the current radio is LTE on CDMA. This
4801 * is a tri-state return value as for a period of time
4802 * the mode may be unknown.
4803 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004804 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004805 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004806 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004807 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004809 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4810 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4811 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004812 }
4813
Sanket Padawe356d7632015-06-22 14:03:32 -07004814 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004815 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4816 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004817 try {
4818 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4819 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004820 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4821 }
4822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 final long identity = Binder.clearCallingIdentity();
4824 try {
4825 final Phone phone = getPhone(subId);
4826 if (phone == null) {
4827 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4828 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004829 return TelephonyProperties.lte_on_cdma_device()
4830 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 }
4832 } finally {
4833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004834 }
Wink Saville36469e72014-06-11 15:17:00 -07004835 }
4836
Wink Saville36469e72014-06-11 15:17:00 -07004837 /**
4838 * {@hide}
4839 * Returns Default subId, 0 in the case of single standby.
4840 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004841 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004842 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004843 }
4844
Shishir Agrawala9f32182016-04-12 12:00:16 -07004845 private int getSlotForDefaultSubscription() {
4846 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4847 }
4848
Wink Savilleb564aae2014-10-23 10:18:09 -07004849 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004850 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004851 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004852
Pengquan Menge92a50d2018-09-21 15:54:48 -07004853 private boolean isActiveSubscription(int subId) {
4854 return mSubscriptionController.isActiveSubId(subId);
4855 }
4856
Ihab Awadf2177b72013-11-25 13:33:23 -08004857 /**
4858 * @see android.telephony.TelephonyManager.WifiCallingChoices
4859 */
4860 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004861 final long identity = Binder.clearCallingIdentity();
4862 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004863 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004864 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4865 getWhenToMakeWifiCallsDefaultPreference());
4866 } finally {
4867 Binder.restoreCallingIdentity(identity);
4868 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004869 }
4870
4871 /**
4872 * @see android.telephony.TelephonyManager.WifiCallingChoices
4873 */
4874 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004878 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004883 }
4884
Sailesh Nepald1e68152013-12-12 19:08:02 -08004885 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004886 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004887 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004888 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004889
Jordan Liu4c733742019-02-28 12:03:40 -08004890 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4891 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4892 if (phoneId == -1) {
4893 throw new IllegalArgumentException("Given slot index: " + slotIndex
4894 + " does not correspond to an active phone");
4895 }
4896 return PhoneFactory.getPhone(phoneId);
4897 }
4898
Shishir Agrawal566b7612013-10-28 14:41:00 -07004899 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004900 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4901 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4903 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004905 if (DBG) {
4906 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4907 }
4908 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4909 p2);
4910 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004911
Jordan Liu4c733742019-02-28 12:03:40 -08004912
4913 @Override
4914 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4915 int slotIndex, String callingPackage, String aid, int p2) {
4916 enforceModifyPermission();
4917 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4918 if (DBG) {
4919 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4920 }
4921 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4922 callingPackage, aid, p2);
4923 }
4924
4925 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4926 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
4929 if (TextUtils.equals(ISDR_AID, aid)) {
4930 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004931 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4932 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004933 if (bestComponent == null
4934 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4935 loge("The calling package is not allowed to access ISD-R.");
4936 throw new SecurityException(
4937 "The calling package is not allowed to access ISD-R.");
4938 }
Derek Tan740e1672017-06-27 14:56:27 -07004939 }
Derek Tan740e1672017-06-27 14:56:27 -07004940
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004941 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004942 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4943 null /* workSource */);
4944 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 return response;
4946 } finally {
4947 Binder.restoreCallingIdentity(identity);
4948 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004949 }
4950
4951 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004952 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004953 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4954 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004955 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4956 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4957 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004958
Jordan Liu4c733742019-02-28 12:03:40 -08004959 @Override
4960 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4961 enforceModifyPermission();
4962 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4963 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4964 channel);
4965 }
4966
4967 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 if (channel < 0) {
4971 return false;
4972 }
Jordan Liu4c733742019-02-28 12:03:40 -08004973 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4974 null /* workSource */);
4975 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004976 return success;
4977 } finally {
4978 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004979 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004980 }
4981
4982 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004983 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004984 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004985 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4986 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004987 if (DBG) {
4988 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4989 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4990 + p3 + " data=" + data);
4991 }
4992 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4993 command, p1, p2, p3, data);
4994 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004995
Jordan Liu4c733742019-02-28 12:03:40 -08004996 @Override
4997 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4998 int command, int p1, int p2, int p3, String data) {
4999 enforceModifyPermission();
5000 if (DBG) {
5001 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
5002 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
5003 + p3 + " data=" + data);
5004 }
5005 return iccTransmitApduLogicalChannelWithPermission(
5006 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
5007 data);
5008 }
5009
5010 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
5011 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012 final long identity = Binder.clearCallingIdentity();
5013 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07005014 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015 return "";
5016 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005017
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005018 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005019 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
5020 null /* workSource */);
5021 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07005022
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023 // Append the returned status code to the end of the response payload.
5024 String s = Integer.toHexString(
5025 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5026 if (response.payload != null) {
5027 s = IccUtils.bytesToHexString(response.payload) + s;
5028 }
5029 return s;
5030 } finally {
5031 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005032 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07005033 }
Jake Hambye994d462014-02-03 13:10:13 -08005034
Evan Charltonc66da362014-05-16 14:06:40 -07005035 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005036 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
5037 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005038 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5039 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08005041 if (DBG) {
5042 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
5043 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5044 }
5045 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5046 cla, command, p1, p2, p3, data);
5047 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005048
Jordan Liu4c733742019-02-28 12:03:40 -08005049 @Override
5050 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5051 int command, int p1, int p2, int p3, String data) {
5052 enforceModifyPermission();
5053 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5054 if (DBG) {
5055 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5056 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5057 + " data=" + data);
5058 }
5059
5060 return iccTransmitApduBasicChannelWithPermission(
5061 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5062 p2, p3, data);
5063 }
5064
5065 // open APDU basic channel assuming the caller has sufficient permissions
5066 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5067 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005068 final long identity = Binder.clearCallingIdentity();
5069 try {
5070 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5071 && TextUtils.equals(ISDR_AID, data)) {
5072 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005073 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5074 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005075 if (bestComponent == null
5076 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5077 loge("The calling package is not allowed to select ISD-R.");
5078 throw new SecurityException(
5079 "The calling package is not allowed to select ISD-R.");
5080 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005081 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005082
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005083 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005084 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5085 null /* workSource */);
5086 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005087
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005088 // Append the returned status code to the end of the response payload.
5089 String s = Integer.toHexString(
5090 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5091 if (response.payload != null) {
5092 s = IccUtils.bytesToHexString(response.payload) + s;
5093 }
5094 return s;
5095 } finally {
5096 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005097 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005098 }
5099
5100 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005101 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005102 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005103 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5104 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005105
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106 final long identity = Binder.clearCallingIdentity();
5107 try {
5108 if (DBG) {
5109 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5110 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5111 }
5112
5113 IccIoResult response =
5114 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5115 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5116 subId);
5117
5118 if (DBG) {
5119 log("Exchange SIM_IO [R]" + response);
5120 }
5121
5122 byte[] result = null;
5123 int length = 2;
5124 if (response.payload != null) {
5125 length = 2 + response.payload.length;
5126 result = new byte[length];
5127 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5128 } else {
5129 result = new byte[length];
5130 }
5131
5132 result[length - 1] = (byte) response.sw2;
5133 result[length - 2] = (byte) response.sw1;
5134 return result;
5135 } finally {
5136 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005137 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005138 }
5139
Nathan Haroldb3014052017-01-25 15:57:32 -08005140 /**
5141 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5142 * on a particular subscription
5143 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005144 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5145 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005146 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005147 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005148 return null;
5149 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005150
5151 final long identity = Binder.clearCallingIdentity();
5152 try {
5153 if (appType != TelephonyManager.APPTYPE_USIM
5154 && appType != TelephonyManager.APPTYPE_SIM) {
5155 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5156 return null;
5157 }
5158 Object response = sendRequest(
5159 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5160 if (response instanceof String[]) {
5161 return (String[]) response;
5162 }
yincheng zhaod698b842019-09-06 17:06:54 -07005163 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005164 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005165 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005166 } finally {
5167 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005168 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005169 }
5170
yincheng zhaod698b842019-09-06 17:06:54 -07005171 /**
5172 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5173 * subscription.
5174 *
5175 * @param subId the id of the subscription.
5176 * @param appType the uicc app type, must be USIM or SIM.
5177 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5178 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005179 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005180 * @return number of fplmns that is successfully written to the SIM.
5181 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005182 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5183 String callingFeatureId) {
5184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5185 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005186 if (DBG) logv("no permissions for setForbiddenplmns");
5187 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5188 }
5189 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5190 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5191 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5192 }
5193 if (fplmns == null) {
5194 throw new IllegalArgumentException("Fplmn List provided is null");
5195 }
5196 for (String fplmn : fplmns) {
5197 if (!CellIdentity.isValidPlmn(fplmn)) {
5198 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5199 }
5200 }
5201 final long identity = Binder.clearCallingIdentity();
5202 try {
5203 Object response = sendRequest(
5204 CMD_SET_FORBIDDEN_PLMNS,
5205 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5206 subId);
5207 return (int) response;
5208 } finally {
5209 Binder.restoreCallingIdentity(identity);
5210 }
5211 }
5212
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005213 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005214 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005215 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5216 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005217
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005218 final long identity = Binder.clearCallingIdentity();
5219 try {
5220 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5221 if (response.payload == null) {
5222 return "";
5223 }
Evan Charltonc66da362014-05-16 14:06:40 -07005224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 // Append the returned status code to the end of the response payload.
5226 String s = Integer.toHexString(
5227 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5228 s = IccUtils.bytesToHexString(response.payload) + s;
5229 return s;
5230 } finally {
5231 Binder.restoreCallingIdentity(identity);
5232 }
Evan Charltonc66da362014-05-16 14:06:40 -07005233 }
5234
Jake Hambye994d462014-02-03 13:10:13 -08005235 /**
5236 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5237 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5238 *
5239 * @param itemID the ID of the item to read
5240 * @return the NV item as a String, or null on error.
5241 */
5242 @Override
5243 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005244 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005245 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5246 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247
5248 final long identity = Binder.clearCallingIdentity();
5249 try {
5250 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005251 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5253 return value;
5254 } finally {
5255 Binder.restoreCallingIdentity(identity);
5256 }
Jake Hambye994d462014-02-03 13:10:13 -08005257 }
5258
5259 /**
5260 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5261 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5262 *
5263 * @param itemID the ID of the item to read
5264 * @param itemValue the value to write, as a String
5265 * @return true on success; false on any failure
5266 */
5267 @Override
5268 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005269 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005270 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5271 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005272
5273 final long identity = Binder.clearCallingIdentity();
5274 try {
5275 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5276 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005277 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5279 return success;
5280 } finally {
5281 Binder.restoreCallingIdentity(identity);
5282 }
Jake Hambye994d462014-02-03 13:10:13 -08005283 }
5284
5285 /**
5286 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5287 * Used for device configuration by some CDMA operators.
5288 *
5289 * @param preferredRoamingList byte array containing the new PRL
5290 * @return true on success; false on any failure
5291 */
5292 @Override
5293 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005296
5297 final long identity = Binder.clearCallingIdentity();
5298 try {
5299 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5300 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5301 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5302 return success;
5303 } finally {
5304 Binder.restoreCallingIdentity(identity);
5305 }
Jake Hambye994d462014-02-03 13:10:13 -08005306 }
5307
5308 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005309 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005310 * Used for device configuration by some CDMA operators.
5311 *
chen xu6dac5ab2018-10-26 17:39:23 -07005312 * @param slotIndex - device slot.
5313 *
Jake Hambye994d462014-02-03 13:10:13 -08005314 * @return true on success; false on any failure
5315 */
5316 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005317 public boolean resetModemConfig(int slotIndex) {
5318 Phone phone = PhoneFactory.getPhone(slotIndex);
5319 if (phone != null) {
5320 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5321 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005322
chen xu6dac5ab2018-10-26 17:39:23 -07005323 final long identity = Binder.clearCallingIdentity();
5324 try {
5325 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5326 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5327 return success;
5328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005331 }
chen xu6dac5ab2018-10-26 17:39:23 -07005332 return false;
5333 }
5334
5335 /**
5336 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5337 *
5338 * @param slotIndex - device slot.
5339 *
5340 * @return true on success; false on any failure
5341 */
5342 @Override
5343 public boolean rebootModem(int slotIndex) {
5344 Phone phone = PhoneFactory.getPhone(slotIndex);
5345 if (phone != null) {
5346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5347 mApp, phone.getSubId(), "rebootModem");
5348
5349 final long identity = Binder.clearCallingIdentity();
5350 try {
5351 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5352 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5353 return success;
5354 } finally {
5355 Binder.restoreCallingIdentity(identity);
5356 }
5357 }
5358 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005359 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005360
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005361 public String[] getPcscfAddress(String apnType, String callingPackage,
5362 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005363 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5365 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005366 return new String[0];
5367 }
5368
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005369 final long identity = Binder.clearCallingIdentity();
5370 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005371 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005372 } finally {
5373 Binder.restoreCallingIdentity(identity);
5374 }
Wink Saville36469e72014-06-11 15:17:00 -07005375 }
5376
Brad Ebinger51f743a2017-01-23 13:50:20 -08005377 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005378 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5379 * {@link #disableIms(int)}.
5380 * @param slotIndex device slot.
5381 */
5382 public void resetIms(int slotIndex) {
5383 enforceModifyPermission();
5384
5385 final long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (mImsResolver == null) {
5388 // may happen if the does not support IMS.
5389 return;
5390 }
5391 mImsResolver.disableIms(slotIndex);
5392 mImsResolver.enableIms(slotIndex);
5393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
5396 }
5397
5398 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005399 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5400 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005401 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005402 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005403 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005404
5405 final long identity = Binder.clearCallingIdentity();
5406 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005407 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005408 // may happen if the device does not support IMS.
5409 return;
5410 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005411 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005412 } finally {
5413 Binder.restoreCallingIdentity(identity);
5414 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005415 }
5416
5417 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005418 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5419 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005420 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005421 public void disableIms(int slotId) {
5422 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005423
5424 final long identity = Binder.clearCallingIdentity();
5425 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005426 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005427 // may happen if the device does not support IMS.
5428 return;
5429 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005430 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005431 } finally {
5432 Binder.restoreCallingIdentity(identity);
5433 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005434 }
5435
5436 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005437 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5438 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005439 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005440 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005441 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005442 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443
5444 final long identity = Binder.clearCallingIdentity();
5445 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005446 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005447 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5448 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005449 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005450 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005451 } finally {
5452 Binder.restoreCallingIdentity(identity);
5453 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005454 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005455 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005456 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5457 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005458 @Override
5459 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005460 enforceModifyPermission();
5461
5462 final long identity = Binder.clearCallingIdentity();
5463 try {
5464 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005465 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005466 } finally {
5467 Binder.restoreCallingIdentity(identity);
5468 }
5469 }
5470
5471 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005472 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005473 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005474 */
5475 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5476 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005480 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005481 // may happen if the device does not support IMS.
5482 return null;
5483 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005484 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005488 }
5489
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005490 /**
5491 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005492 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005493 */
5494 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5495 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496
5497 final long identity = Binder.clearCallingIdentity();
5498 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005499 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005500 // may happen if the device does not support IMS.
5501 return null;
5502 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005503 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005507 }
5508
Brad Ebinger884c07b2018-02-15 16:17:40 -08005509 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005510 * Sets the ImsService Package Name that Telephony will bind to.
5511 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005512 * @param slotIndex the slot ID that the ImsService should bind for.
5513 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005514 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005515 * @param featureTypes An integer array of feature types associated with a packageName.
5516 * @param packageName The name of the package that the current configuration will be replaced
5517 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005518 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005519 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005520 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5521 int[] featureTypes, String packageName) {
5522 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5523 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5525 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005526 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005527
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005528 final long identity = Binder.clearCallingIdentity();
5529 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005530 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005531 // may happen if the device does not support IMS.
5532 return false;
5533 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005534 Map<Integer, String> featureConfig = new HashMap<>();
5535 for (int featureType : featureTypes) {
5536 featureConfig.put(featureType, packageName);
5537 }
5538 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5539 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005540 } finally {
5541 Binder.restoreCallingIdentity(identity);
5542 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005543 }
5544
5545 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005546 * Clears any carrier ImsService overrides for the slot index specified that were previously
5547 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5548 *
5549 * This should only be used for testing.
5550 *
5551 * @param slotIndex the slot ID that the ImsService should bind for.
5552 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5553 */
5554 @Override
5555 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5556 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5557 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5558 "clearCarrierImsServiceOverride");
5559 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5560 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5561 "clearCarrierImsServiceOverride");
5562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 if (mImsResolver == null) {
5566 // may happen if the device does not support IMS.
5567 return false;
5568 }
5569 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5570 } finally {
5571 Binder.restoreCallingIdentity(identity);
5572 }
5573 }
5574
5575 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005576 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005577 *
5578 * @param slotId The slot that the ImsService is associated with.
5579 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5580 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005581 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005582 * @return the package name of the ImsService configuration.
5583 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005584 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5585 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005586 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005587 TelephonyPermissions
5588 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5589 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5590 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005591
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005592 final long identity = Binder.clearCallingIdentity();
5593 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005594 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005595 // may happen if the device does not support IMS.
5596 return "";
5597 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005598 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005599 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5600 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601 } finally {
5602 Binder.restoreCallingIdentity(identity);
5603 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005604 }
5605
Brad Ebinger77b832e2019-10-17 17:03:22 -07005606 /**
5607 * Get the MmTelFeature state associated with the requested subscription id.
5608 * @param subId The subscription that the MmTelFeature is associated with.
5609 * @param callback A callback with an integer containing the
5610 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5611 */
5612 @Override
5613 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5614 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5615 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5616 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5617 "IMS not available on device.");
5618 }
5619 final long token = Binder.clearCallingIdentity();
5620 try {
5621 int slotId = getSlotIndex(subId);
5622 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5623 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5624 + subId + "'");
5625 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5626 }
5627 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5628 try {
5629 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5630 } catch (RemoteException e) {
5631 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5632 + "Ignore");
5633 }
5634 });
5635 } finally {
5636 Binder.restoreCallingIdentity(token);
5637 }
5638 }
5639
Daniel Brightbb5840b2021-01-12 15:48:18 -08005640 /**
5641 * Sets the ims registration state on all valid {@link Phone}s.
5642 */
5643 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005644 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005645
5646 final long identity = Binder.clearCallingIdentity();
5647 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005648 // NOTE: Before S, this method only set the default phone.
5649 for (final Phone phone : PhoneFactory.getPhones()) {
5650 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5651 phone.setImsRegistrationState(registered);
5652 }
5653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
5656 }
Wink Saville36469e72014-06-11 15:17:00 -07005657 }
5658
5659 /**
Stuart Scott54788802015-03-30 13:18:01 -07005660 * Set the network selection mode to automatic.
5661 *
5662 */
5663 @Override
5664 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5666 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005667
5668 final long identity = Binder.clearCallingIdentity();
5669 try {
shilufc958392020-01-20 11:36:01 -08005670 if (!isActiveSubscription(subId)) {
5671 return;
5672 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005673 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005674 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5675 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 } finally {
5677 Binder.restoreCallingIdentity(identity);
5678 }
Stuart Scott54788802015-03-30 13:18:01 -07005679 }
5680
Jack Yud10cdd42020-09-28 20:28:01 -07005681 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005682 * Ask the radio to connect to the input network and change selection mode to manual.
5683 *
5684 * @param subId the id of the subscription.
5685 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5686 * the operator to attach to.
5687 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5688 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5689 * normal network selection next time.
5690 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005691 */
5692 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005693 public boolean setNetworkSelectionModeManual(
5694 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005697
5698 if (!isActiveSubscription(subId)) {
5699 return false;
5700 }
5701
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005702 final long identity = Binder.clearCallingIdentity();
5703 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005704 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005705 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005706 if (DBG) {
5707 log("setNetworkSelectionModeManual: subId: " + subId
5708 + " operator: " + operatorInfo);
5709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005710 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5711 } finally {
5712 Binder.restoreCallingIdentity(identity);
5713 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005714 }
shilu84f6e8b2019-12-19 13:58:01 -08005715 /**
5716 * Get the manual network selection
5717 *
5718 * @param subId the id of the subscription.
5719 *
5720 * @return the previously saved user selected PLMN
5721 */
5722 @Override
5723 public String getManualNetworkSelectionPlmn(int subId) {
5724 TelephonyPermissions
5725 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5726 mApp, subId, "getManualNetworkSelectionPlmn");
5727
5728 final long identity = Binder.clearCallingIdentity();
5729 try {
5730 if (!isActiveSubscription(subId)) {
5731 return "";
5732 }
5733
5734 final Phone phone = getPhone(subId);
5735 if (phone == null) {
5736 return "";
5737 }
5738 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5739 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5740 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5741 } finally {
5742 Binder.restoreCallingIdentity(identity);
5743 }
5744 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005745
5746 /**
5747 * Scans for available networks.
5748 */
5749 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005750 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5751 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005752 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5753 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005754 LocationAccessPolicy.LocationPermissionResult locationResult =
5755 LocationAccessPolicy.checkLocationPermission(mApp,
5756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5757 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005759 .setCallingPid(Binder.getCallingPid())
5760 .setCallingUid(Binder.getCallingUid())
5761 .setMethod("getCellNetworkScanResults")
5762 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5763 .build());
5764 switch (locationResult) {
5765 case DENIED_HARD:
5766 throw new SecurityException("Not allowed to access scan results -- location");
5767 case DENIED_SOFT:
5768 return null;
5769 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005770
Pengquan Menga1bb6272018-09-06 09:59:22 -07005771 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005772 try {
5773 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005774 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005779 }
5780
5781 /**
sqian80370722020-01-29 15:02:51 -08005782 * Get the call forwarding info, given the call forwarding reason.
5783 */
5784 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005785 public void getCallForwarding(int subId, int callForwardingReason,
5786 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005787 enforceReadPrivilegedPermission("getCallForwarding");
5788 long identity = Binder.clearCallingIdentity();
5789 try {
5790 if (DBG) {
5791 log("getCallForwarding: subId " + subId
5792 + " callForwardingReason" + callForwardingReason);
5793 }
Hall Liua1acea22020-09-18 19:04:59 -07005794
5795 Phone phone = getPhone(subId);
5796 if (phone == null) {
5797 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005798 callback.onError(
5799 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005800 } catch (RemoteException e) {
5801 // ignore
5802 }
5803 return;
5804 }
5805
5806 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5807 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5808 @Override
5809 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5810 try {
5811 callback.onCallForwardingInfoAvailable(info);
5812 } catch (RemoteException e) {
5813 // ignore
5814 }
5815 }
5816
5817 @Override
5818 public void onError(int error) {
5819 try {
5820 callback.onError(error);
5821 } catch (RemoteException e) {
5822 // ignore
5823 }
5824 }
5825 });
5826 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005827 } finally {
5828 Binder.restoreCallingIdentity(identity);
5829 }
5830 }
5831
5832 /**
5833 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5834 * reason, the number to forward, and the timeout before the forwarding is attempted.
5835 */
5836 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005837 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5838 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005839 enforceModifyPermission();
5840 long identity = Binder.clearCallingIdentity();
5841 try {
5842 if (DBG) {
5843 log("setCallForwarding: subId " + subId
5844 + " callForwardingInfo" + callForwardingInfo);
5845 }
Hall Liua1acea22020-09-18 19:04:59 -07005846
5847 Phone phone = getPhone(subId);
5848 if (phone == null) {
5849 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005850 callback.accept(
5851 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005852 } catch (RemoteException e) {
5853 // ignore
5854 }
5855 return;
5856 }
5857
5858 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5859 FunctionalUtils.ignoreRemoteException(callback::accept));
5860
5861 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005862 } finally {
5863 Binder.restoreCallingIdentity(identity);
5864 }
5865 }
5866
5867 /**
Hall Liua1acea22020-09-18 19:04:59 -07005868 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005869 */
5870 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005871 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005872 enforceReadPrivilegedPermission("getCallForwarding");
5873 long identity = Binder.clearCallingIdentity();
5874 try {
Hall Liua1acea22020-09-18 19:04:59 -07005875
5876 Phone phone = getPhone(subId);
5877 if (phone == null) {
5878 try {
5879 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5880 } catch (RemoteException e) {
5881 // ignore
5882 }
5883 return;
5884 }
5885
5886 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5887
sqian80370722020-01-29 15:02:51 -08005888 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005889 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005890 } finally {
5891 Binder.restoreCallingIdentity(identity);
5892 }
5893 }
5894
5895 /**
Hall Liua1acea22020-09-18 19:04:59 -07005896 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005897 */
5898 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005899 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005900 enforceModifyPermission();
5901 long identity = Binder.clearCallingIdentity();
5902 try {
Hall Liua1acea22020-09-18 19:04:59 -07005903 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5904
5905 Phone phone = getPhone(subId);
5906 if (phone == null) {
5907 try {
5908 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5909 } catch (RemoteException e) {
5910 // ignore
5911 }
5912 return;
5913 }
5914
5915 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5916 FunctionalUtils.ignoreRemoteException(callback::accept));
5917
5918 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005919 } finally {
5920 Binder.restoreCallingIdentity(identity);
5921 }
5922 }
5923
5924 /**
yinxub1bed742017-04-17 11:45:04 -07005925 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005926 *
yinxub1bed742017-04-17 11:45:04 -07005927 * @param subId id of the subscription
5928 * @param request contains the radio access networks with bands/channels to scan
5929 * @param messenger callback messenger for scan results or errors
5930 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005931 * @return the id of the requested scan which can be used to stop the scan.
5932 */
5933 @Override
5934 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005935 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5937 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005938 LocationAccessPolicy.LocationPermissionResult locationResult =
5939 LocationAccessPolicy.checkLocationPermission(mApp,
5940 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5941 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005942 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005943 .setCallingPid(Binder.getCallingPid())
5944 .setCallingUid(Binder.getCallingUid())
5945 .setMethod("requestNetworkScan")
5946 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5947 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005948 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005949 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5950 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005951 if (e != null) {
5952 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5953 throw e;
5954 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005955 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005956 return TelephonyScanManager.INVALID_SCAN_ID;
5957 }
5958 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005959 }
Hall Liu912dfd32019-04-25 14:02:26 -07005960 int callingUid = Binder.getCallingUid();
5961 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005962 final long identity = Binder.clearCallingIdentity();
5963 try {
5964 return mNetworkScanRequestTracker.startNetworkScan(
5965 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005966 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005967 } finally {
5968 Binder.restoreCallingIdentity(identity);
5969 }
yinxu504e1392017-04-12 16:03:22 -07005970 }
5971
Hall Liub2ac8ef2019-02-28 15:56:23 -08005972 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005973 NetworkScanRequest request, int subId, String callingPackage) {
5974 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005975 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5976 boolean hasNetworkScanPermission =
5977 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5978 == PERMISSION_GRANTED;
5979
5980 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5981 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5982 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005983 }
5984
5985 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5986 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005987 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5988 return new SecurityException("Specific channels must not be"
5989 + " scanned without location access.");
5990 }
5991 }
5992 }
5993
Hall Liub2ac8ef2019-02-28 15:56:23 -08005994 return null;
5995 }
5996
yinxu504e1392017-04-12 16:03:22 -07005997 /**
5998 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005999 *
6000 * @param subId id of the subscription
6001 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07006002 */
6003 @Override
6004 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006005 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6006 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
Hall Liu912dfd32019-04-25 14:02:26 -07006008 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006009 final long identity = Binder.clearCallingIdentity();
6010 try {
Hall Liu912dfd32019-04-25 14:02:26 -07006011 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006012 } finally {
6013 Binder.restoreCallingIdentity(identity);
6014 }
yinxu504e1392017-04-12 16:03:22 -07006015 }
6016
6017 /**
SongFerngWang9e060372020-12-21 16:41:52 +08006018 * Get the allowed network types bitmask.
Junda Liu84d15a22014-07-02 11:21:04 -07006019 *
SongFerngWang9e060372020-12-21 16:41:52 +08006020 * @return the allowed network types bitmask, defined in RILConstants.java.
Junda Liu84d15a22014-07-02 11:21:04 -07006021 */
6022 @Override
SongFerngWang9e060372020-12-21 16:41:52 +08006023 public int getAllowedNetworkTypesBitmask(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006024 TelephonyPermissions
6025 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
SongFerngWang9e060372020-12-21 16:41:52 +08006026 mApp, subId, "getAllowedNetworkTypesBitmask");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006027
6028 final long identity = Binder.clearCallingIdentity();
6029 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006030 if (DBG) log("getAllowedNetworkTypesBitmask");
6031 int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId);
6032 int networkTypesBitmask = (result != null ? result[0] : -1);
6033 if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask);
6034 return networkTypesBitmask;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006035 } finally {
6036 Binder.restoreCallingIdentity(identity);
6037 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006038 }
6039
6040 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006041 * Get the allowed network types for certain reason.
6042 *
6043 * @param subId the id of the subscription.
6044 * @param reason the reason the allowed network type change is taking place
6045 * @return the allowed network types.
6046 */
6047 @Override
6048 public long getAllowedNetworkTypesForReason(int subId,
6049 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6050 TelephonyPermissions
6051 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6052 mApp, subId, "getAllowedNetworkTypesForReason");
6053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6056 } finally {
6057 Binder.restoreCallingIdentity(identity);
6058 }
6059 }
6060
6061 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006062 * Enable/Disable E-UTRA-NR Dual Connectivity
6063 * @param subId subscription id of the sim card
6064 * @param nrDualConnectivityState expected NR dual connectivity state
6065 * This can be passed following states
6066 * <ol>
6067 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6068 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6069 * <li>Disable NR dual connectivity and force secondary cell to be released
6070 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6071 * </ol>
6072 * @return operation result.
6073 */
6074 @Override
6075 public int setNrDualConnectivityState(int subId,
6076 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6078 mApp, subId, "enableNRDualConnectivity");
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006079 if (isRadioInterfaceCapabilitySupported(
6080 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6081 return TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_NOT_SUPPORTED;
6082 }
6083
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006084 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6085 final long identity = Binder.clearCallingIdentity();
6086 try {
6087 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6088 nrDualConnectivityState, subId,
6089 workSource);
6090 if (DBG) log("enableNRDualConnectivity result: " + result);
6091 return result;
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
6095 }
6096
6097 /**
6098 * Is E-UTRA-NR Dual Connectivity enabled
6099 * @return true if dual connectivity is enabled else false
6100 */
6101 @Override
6102 public boolean isNrDualConnectivityEnabled(int subId) {
6103 TelephonyPermissions
6104 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6105 mApp, subId, "isNRDualConnectivityEnabled");
Sooraj Sasindrandfd595b2021-03-11 17:38:13 -08006106 if (isRadioInterfaceCapabilitySupported(
6107 TelephonyManager.CAPABILITY_NR_DUAL_CONNECTIVITY_CONFIGURATION_AVAILABLE)) {
6108 return false;
6109 }
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006110 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6114 null, subId, workSource);
6115 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6116 return isEnabled;
6117 } finally {
6118 Binder.restoreCallingIdentity(identity);
6119 }
6120 }
6121
6122 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006123 * get carrier bandwidth per primary and secondary carrier
6124 * @param subId subscription id of the sim card
6125 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6126 */
6127 @Override
6128 public CarrierBandwidth getCarrierBandwidth(int subId) {
6129 TelephonyPermissions
6130 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6131 mApp, subId, "isNRDualConnectivityEnabled");
6132 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 CarrierBandwidth carrierBandwidth =
6136 getPhoneFromSubId(subId).getCarrierBandwidth();
6137 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6138 return carrierBandwidth;
6139 } finally {
6140 Binder.restoreCallingIdentity(identity);
6141 }
6142 }
6143
6144 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006145 * Set the allowed network types of the device and
6146 * provide the reason triggering the allowed network change.
6147 *
6148 * @param subId the id of the subscription.
6149 * @param reason the reason the allowed network type change is taking place
6150 * @param allowedNetworkTypes the allowed network types.
6151 * @return true on success; false on any failure.
6152 */
6153 @Override
6154 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006155 @TelephonyManager.AllowedNetworkTypesReason int reason,
6156 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006157 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6158 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006159 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6160 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6161 return false;
6162 }
6163
6164 if (DBG) {
6165 log("setAllowedNetworkTypesForReason: " + reason
6166 + " value: " + allowedNetworkTypes);
6167 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006168 final long identity = Binder.clearCallingIdentity();
6169 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006170 Boolean success = (Boolean) sendRequest(
6171 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6172 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6173
6174 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6175 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006176 } finally {
6177 Binder.restoreCallingIdentity(identity);
6178 }
6179 }
6180
6181 /**
Miaoa84611c2019-03-15 09:21:10 +08006182 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006183 *
Miaoa84611c2019-03-15 09:21:10 +08006184 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006185 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006186 * @hide
6187 */
6188 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006189 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006191 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006192 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006193 try {
Miaoa84611c2019-03-15 09:21:10 +08006194 if (phone != null) {
6195 return phone.hasMatchedTetherApnSetting();
6196 } else {
6197 return false;
6198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006199 } finally {
6200 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006201 }
Junda Liu475951f2014-11-07 16:45:03 -08006202 }
6203
6204 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006205 * Enable or disable always reporting signal strength changes from radio.
6206 *
6207 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6208 */
6209 @Override
6210 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6211 enforceModifyPermission();
6212 enforceSystemCaller();
6213
6214 final long identity = Binder.clearCallingIdentity();
6215 final Phone phone = getPhone(subId);
6216 try {
6217 if (phone != null) {
6218 if (DBG) {
6219 log("setAlwaysReportSignalStrength: subId=" + subId
6220 + " isEnable=" + isEnable);
6221 }
6222 phone.setAlwaysReportSignalStrength(isEnable);
6223 } else {
6224 loge("setAlwaysReportSignalStrength: no phone found for subId="
6225 + subId);
6226 }
6227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006233 * Get the user enabled state of Mobile Data.
6234 *
6235 * TODO: remove and use isUserDataEnabled.
6236 * This can't be removed now because some vendor codes
6237 * calls through ITelephony directly while they should
6238 * use TelephonyManager.
6239 *
6240 * @return true on enabled
6241 */
6242 @Override
6243 public boolean getDataEnabled(int subId) {
6244 return isUserDataEnabled(subId);
6245 }
6246
6247 /**
6248 * Get whether mobile data is enabled per user setting.
6249 *
6250 * There are other factors deciding whether mobile data is actually enabled, but they are
6251 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006252 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006253 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006254 *
6255 * @return {@code true} if data is enabled else {@code false}
6256 */
6257 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006258 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006259 try {
6260 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6261 null);
6262 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6264 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006265 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006266
6267 final long identity = Binder.clearCallingIdentity();
6268 try {
6269 int phoneId = mSubscriptionController.getPhoneId(subId);
6270 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6271 Phone phone = PhoneFactory.getPhone(phoneId);
6272 if (phone != null) {
6273 boolean retVal = phone.isUserDataEnabled();
6274 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6275 return retVal;
6276 } else {
6277 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6278 return false;
6279 }
6280 } finally {
6281 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006282 }
6283 }
6284
6285 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006286 * Checks if the device is capable of mobile data by considering whether whether the
6287 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6288 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006289 *
Shuo Qian985d1232020-01-08 14:30:06 -08006290 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006291 */
6292 @Override
6293 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006294 try {
6295 try {
6296 mApp.enforceCallingOrSelfPermission(
6297 android.Manifest.permission.ACCESS_NETWORK_STATE,
6298 null);
6299 } catch (Exception e) {
6300 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6301 "isDataEnabled");
6302 }
6303 } catch (Exception e) {
6304 enforceReadPrivilegedPermission("isDataEnabled");
6305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006306
6307 final long identity = Binder.clearCallingIdentity();
6308 try {
6309 int phoneId = mSubscriptionController.getPhoneId(subId);
6310 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6311 Phone phone = PhoneFactory.getPhone(phoneId);
6312 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006313 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006314 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6315 return retVal;
6316 } else {
6317 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6318 return false;
6319 }
6320 } finally {
6321 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006322 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006323 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006324
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006325 /**
6326 * Check if data is enabled for a specific reason
6327 * @param subId Subscription index
6328 * @param reason the reason the data enable change is taking place
6329 * @return {@code true} if the overall data is enabled; {@code false} if not.
6330 */
6331 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006332 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006333 @TelephonyManager.DataEnabledReason int reason) {
6334 try {
6335 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6336 null);
6337 } catch (Exception e) {
6338 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006339 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006340 }
6341
6342
6343 final long identity = Binder.clearCallingIdentity();
6344 try {
6345 int phoneId = mSubscriptionController.getPhoneId(subId);
6346 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006347 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006348 + " reason=" + reason);
6349 }
6350 Phone phone = PhoneFactory.getPhone(phoneId);
6351 if (phone != null) {
6352 boolean retVal;
6353 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6354 retVal = phone.isUserDataEnabled();
6355 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006356 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006357 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006358 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006359 return retVal;
6360 } else {
6361 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006362 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006363 + subId + " retVal=false");
6364 }
6365 return false;
6366 }
6367 } finally {
6368 Binder.restoreCallingIdentity(identity);
6369 }
6370 }
6371
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006372 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006373 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006374 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6375 // Skip the check if it's one of these special uids
6376 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6377 }
6378
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006379 //load access rules from carrier configs, and check those as well: b/139133814
6380 SubscriptionController subController = SubscriptionController.getInstance();
6381 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6382 || subController == null) return privilegeFromSim;
6383
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006384 PackageManager pkgMgr = phone.getContext().getPackageManager();
6385 String[] packages = pkgMgr.getPackagesForUid(uid);
6386
6387 final long identity = Binder.clearCallingIdentity();
6388 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006389 int subId = phone.getSubId();
6390 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6391 // A test override is in place for the privileges for this subId, so don't try to
6392 // read the subscription privileges.
6393 return privilegeFromSim;
6394 }
6395 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006396 SubscriptionManager subManager = (SubscriptionManager)
6397 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6398 for (String pkg : packages) {
6399 if (subManager.canManageSubscription(subInfo, pkg)) {
6400 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6401 }
6402 }
6403 return privilegeFromSim;
6404 } finally {
6405 Binder.restoreCallingIdentity(identity);
6406 }
6407 }
6408
6409 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6410 String pkgName) {
6411 //load access rules from carrier configs, and check those as well: b/139133814
6412 SubscriptionController subController = SubscriptionController.getInstance();
6413 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6414 || subController == null) return privilegeFromSim;
6415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006418 int subId = phone.getSubId();
6419 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6420 // A test override is in place for the privileges for this subId, so don't try to
6421 // read the subscription privileges.
6422 return privilegeFromSim;
6423 }
6424 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006425 SubscriptionManager subManager = (SubscriptionManager)
6426 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6427 return subManager.canManageSubscription(subInfo, pkgName)
6428 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6429 } finally {
6430 Binder.restoreCallingIdentity(identity);
6431 }
6432 }
6433
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006434 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006435 public int getCarrierPrivilegeStatus(int subId) {
6436 final Phone phone = getPhone(subId);
6437 if (phone == null) {
6438 loge("getCarrierPrivilegeStatus: Invalid subId");
6439 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6440 }
6441 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006442 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006443 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006444 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6445 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006446
6447 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6448 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006449 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006450 }
Junda Liu29340342014-07-10 15:23:27 -07006451
6452 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006453 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006454 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006455 final Phone phone = getPhone(subId);
6456 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006457 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006458 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6459 }
6460 UiccProfile profile =
6461 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6462 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006463 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006464 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6465 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006466 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006467 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006468 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006469 }
6470
6471 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006472 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6473 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006474 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006475 }
6476
6477 int phoneId = SubscriptionManager.getPhoneId(subId);
6478 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006479 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006480 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006481 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6482 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006483 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6484 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6485 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006486 }
6487
6488 @Override
6489 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006490 if (TextUtils.isEmpty(pkgName))
6491 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006492 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6493 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6494 UiccCard card = UiccController.getInstance().getUiccCard(i);
6495 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006496 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006497 continue;
6498 }
6499
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006500 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6501 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6502 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006503 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6504 break;
6505 }
6506 }
6507
6508 return result;
Junda Liu29340342014-07-10 15:23:27 -07006509 }
Derek Tan89e89d42014-07-08 17:00:10 -07006510
6511 @Override
Junda Liue64de782015-04-16 17:19:16 -07006512 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6513 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6514 loge("phoneId " + phoneId + " is not valid.");
6515 return null;
6516 }
6517 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006518 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006519 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006520 return null ;
6521 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006522 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006523 }
6524
Amith Yamasani6e118872016-02-19 12:53:51 -08006525 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006526 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006527 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006528 List<String> privilegedPackages = new ArrayList<>();
6529 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006530 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6531 // has UICC in that slot.
6532 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006533 if (card.hasCarrierPrivilegeRules()) {
6534 if (packages == null) {
6535 // Only check packages in user 0 for now
6536 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006537 PackageManager.MATCH_DISABLED_COMPONENTS
6538 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006539 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006540 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006541 }
6542 for (int p = packages.size() - 1; p >= 0; p--) {
6543 PackageInfo pkgInfo = packages.get(p);
6544 if (pkgInfo != null && pkgInfo.packageName != null
6545 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006546 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006547 privilegedPackages.add(pkgInfo.packageName);
6548 }
6549 }
6550 }
6551 }
6552 return privilegedPackages;
6553 }
6554
chen xuf7e9fe82019-05-09 19:31:02 -07006555 @Override
6556 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006557 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6558
6559 final long identity = Binder.clearCallingIdentity();
6560
chen xuf7e9fe82019-05-09 19:31:02 -07006561 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006562 try {
6563 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6564 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6565 }
6566 } finally {
6567 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006568 }
6569 return privilegedPackages;
6570 }
6571
Wink Savilleb564aae2014-10-23 10:18:09 -07006572 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006573 final Phone phone = getPhone(subId);
6574 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006575 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006576 return null;
6577 }
6578 String iccId = card.getIccId();
6579 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006580 return null;
6581 }
6582 return iccId;
6583 }
6584
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006585 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006586 public void setCallComposerStatus(int subId, int status) {
6587 enforceModifyPermission();
6588
6589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 Phone phone = getPhone(subId);
6592 if (phone != null) {
6593 Phone defaultPhone = phone.getImsPhone();
6594 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6595 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6596 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006597 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6598 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006599 }
6600 }
Shuo Qiand8782462020-12-22 19:10:14 -08006601 } catch (ImsException e) {
6602 throw new ServiceSpecificException(e.getCode());
6603 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006604 Binder.restoreCallingIdentity(identity);
6605 }
6606 }
6607
6608 @Override
6609 public int getCallComposerStatus(int subId) {
6610 enforceReadPrivilegedPermission("getCallComposerStatus");
6611
6612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 Phone phone = getPhone(subId);
6615 if (phone != null) {
6616 Phone defaultPhone = phone.getImsPhone();
6617 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6618 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6619 return imsPhone.getCallComposerStatus();
6620 }
6621 }
6622 } finally {
6623 Binder.restoreCallingIdentity(identity);
6624 }
6625 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6626 }
6627
6628 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006629 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6630 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006631 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006632 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006633
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006634 final long identity = Binder.clearCallingIdentity();
6635 try {
6636 final String iccId = getIccId(subId);
6637 final Phone phone = getPhone(subId);
6638 if (phone == null) {
6639 return false;
6640 }
6641 final String subscriberId = phone.getSubscriberId();
6642
6643 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006644 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 + subscriberId + " to " + number);
6646 }
6647
6648 if (TextUtils.isEmpty(iccId)) {
6649 return false;
6650 }
6651
6652 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6653
6654 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6655 if (alphaTag == null) {
6656 editor.remove(alphaTagPrefKey);
6657 } else {
6658 editor.putString(alphaTagPrefKey, alphaTag);
6659 }
6660
6661 // Record both the line number and IMSI for this ICCID, since we need to
6662 // track all merged IMSIs based on line number
6663 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6664 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6665 if (number == null) {
6666 editor.remove(numberPrefKey);
6667 editor.remove(subscriberPrefKey);
6668 } else {
6669 editor.putString(numberPrefKey, number);
6670 editor.putString(subscriberPrefKey, subscriberId);
6671 }
6672
6673 editor.commit();
6674 return true;
6675 } finally {
6676 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006677 }
Derek Tan7226c842014-07-02 17:42:23 -07006678 }
6679
6680 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006681 public String getLine1NumberForDisplay(int subId, String callingPackage,
6682 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006683 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006685 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006686 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006687 return null;
6688 }
Derek Tan97ebb422014-09-05 16:55:38 -07006689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 final long identity = Binder.clearCallingIdentity();
6691 try {
6692 String iccId = getIccId(subId);
6693 if (iccId != null) {
6694 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6695 if (DBG_MERGE) {
6696 log("getLine1NumberForDisplay returning "
6697 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6698 }
6699 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006700 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006701 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6702 return null;
6703 } finally {
6704 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006705 }
Derek Tan7226c842014-07-02 17:42:23 -07006706 }
6707
6708 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006709 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6710 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006711 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006712 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006713 return null;
6714 }
Derek Tan97ebb422014-09-05 16:55:38 -07006715
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 String iccId = getIccId(subId);
6719 if (iccId != null) {
6720 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6721 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6722 }
6723 return null;
6724 } finally {
6725 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006726 }
Derek Tan7226c842014-07-02 17:42:23 -07006727 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006728
6729 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006730 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6731 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006732 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6733 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006734 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006735 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006736 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006737 return null;
6738 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006739
Jordan Liub49b04b2019-05-06 14:45:15 -07006740 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6741 // the process, where TelephonyManager was instantiated.
6742 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006743 final long identity = Binder.clearCallingIdentity();
6744 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006745 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006746 final TelephonyManager tele = TelephonyManager.from(context);
6747 final SubscriptionManager sub = SubscriptionManager.from(context);
6748
6749 // Figure out what subscribers are currently active
6750 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006751
Jordan Liub49b04b2019-05-06 14:45:15 -07006752 // Only consider subs which match the current subId
6753 // This logic can be simplified. See b/131189269 for progress.
6754 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006755 activeSubscriberIds.add(tele.getSubscriberId(subId));
6756 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006757
6758 // First pass, find a number override for an active subscriber
6759 String mergeNumber = null;
6760 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6761 for (String key : prefs.keySet()) {
6762 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6763 final String subscriberId = (String) prefs.get(key);
6764 if (activeSubscriberIds.contains(subscriberId)) {
6765 final String iccId = key.substring(
6766 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6767 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6768 mergeNumber = (String) prefs.get(numberKey);
6769 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006770 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006771 + " for active subscriber " + subscriberId);
6772 }
6773 if (!TextUtils.isEmpty(mergeNumber)) {
6774 break;
6775 }
6776 }
6777 }
6778 }
6779
6780 // Shortcut when no active merged subscribers
6781 if (TextUtils.isEmpty(mergeNumber)) {
6782 return null;
6783 }
6784
6785 // Second pass, find all subscribers under that line override
6786 final ArraySet<String> result = new ArraySet<>();
6787 for (String key : prefs.keySet()) {
6788 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6789 final String number = (String) prefs.get(key);
6790 if (mergeNumber.equals(number)) {
6791 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6792 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6793 final String subscriberId = (String) prefs.get(subscriberKey);
6794 if (!TextUtils.isEmpty(subscriberId)) {
6795 result.add(subscriberId);
6796 }
6797 }
6798 }
6799 }
6800
6801 final String[] resultArray = result.toArray(new String[result.size()]);
6802 Arrays.sort(resultArray);
6803 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006804 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006805 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6806 }
6807 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006808 } finally {
6809 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006810 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006811 }
6812
6813 @Override
zoey chen38003472019-12-13 17:16:31 +08006814 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6815 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006816
6817 final long identity = Binder.clearCallingIdentity();
6818 try {
6819 final TelephonyManager telephonyManager = mApp.getSystemService(
6820 TelephonyManager.class);
6821 String subscriberId = telephonyManager.getSubscriberId(subId);
6822 if (subscriberId == null) {
6823 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006824 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006825 + subId);
6826 }
6827 return null;
6828 }
6829
6830 final SubscriptionInfo info = SubscriptionController.getInstance()
6831 .getSubscriptionInfo(subId);
6832 final ParcelUuid groupUuid = info.getGroupUuid();
6833 // If it doesn't belong to any group, return just subscriberId of itself.
6834 if (groupUuid == null) {
6835 return new String[]{subscriberId};
6836 }
6837
6838 // Get all subscriberIds from the group.
6839 final List<String> mergedSubscriberIds = new ArrayList<>();
6840 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006841 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006842 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006843 for (SubscriptionInfo subInfo : groupInfos) {
6844 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6845 if (subscriberId != null) {
6846 mergedSubscriberIds.add(subscriberId);
6847 }
6848 }
6849
6850 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6851 } finally {
6852 Binder.restoreCallingIdentity(identity);
6853
6854 }
6855 }
6856
6857 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006858 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006859 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006860 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006861
6862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 final Phone phone = getPhone(subId);
6865 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6866 } finally {
6867 Binder.restoreCallingIdentity(identity);
6868 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006869 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006870
6871 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006872 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006873 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6874 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006875 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6876 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006877
6878 final long identity = Binder.clearCallingIdentity();
6879 try {
6880 final Phone phone = getPhone(subId);
6881 if (phone == null) {
6882 return false;
6883 }
6884 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6885 cdmaNonRoamingList);
6886 } finally {
6887 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006888 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006889 }
6890
6891 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006892 @Deprecated
6893 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6894 enforceModifyPermission();
6895
6896 int returnValue = 0;
6897 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006898 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006899 if(result.exception == null) {
6900 if (result.result != null) {
6901 byte[] responseData = (byte[])(result.result);
6902 if(responseData.length > oemResp.length) {
6903 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6904 responseData.length + "bytes. Buffer Size is " +
6905 oemResp.length + "bytes.");
6906 }
6907 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6908 returnValue = responseData.length;
6909 }
6910 } else {
6911 CommandException ex = (CommandException) result.exception;
6912 returnValue = ex.getCommandError().ordinal();
6913 if(returnValue > 0) returnValue *= -1;
6914 }
6915 } catch (RuntimeException e) {
6916 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6917 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6918 if(returnValue > 0) returnValue *= -1;
6919 }
6920
6921 return returnValue;
6922 }
6923
6924 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006925 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006926 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006927 try {
6928 TelephonyPermissions
6929 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6930 mApp, phone.getSubId(), "getRadioAccessFamily");
6931 } catch (SecurityException e) {
6932 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6933 throw e;
6934 }
chen xub97461a2018-10-26 14:17:57 -07006935 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006936 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006937 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006938 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006939 final long identity = Binder.clearCallingIdentity();
6940 try {
chen xub97461a2018-10-26 14:17:57 -07006941 TelephonyPermissions
6942 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6943 mApp, phone.getSubId(), "getRadioAccessFamily");
6944 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 } finally {
6946 Binder.restoreCallingIdentity(identity);
6947 }
chen xub97461a2018-10-26 14:17:57 -07006948 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006949 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006950
6951 @Override
6952 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006953 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006954 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955
6956 final long identity = Binder.clearCallingIdentity();
6957 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006958 ImsManager.getInstance(defaultPhone.getContext(),
6959 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 } finally {
6961 Binder.restoreCallingIdentity(identity);
6962 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006963 }
6964
6965 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006966 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006967 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006968 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6969 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006970 return false;
6971 }
Svet Ganovb320e182015-04-16 12:30:10 -07006972
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006973 final long identity = Binder.clearCallingIdentity();
6974 try {
6975 // Check the user preference and the system-level IMS setting. Even if the user has
6976 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6977 // In the long run, we may instead need to check if there exists a connection service
6978 // which can support video calling.
6979 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006980 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981 return imsManager.isVtEnabledByPlatform()
6982 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6983 && imsManager.isVtEnabledByUser();
6984 } finally {
6985 Binder.restoreCallingIdentity(identity);
6986 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006987 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006988
Andrew Leea1239f22015-03-02 17:44:07 -08006989 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006990 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6991 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006993 mApp, subId, callingPackage, callingFeatureId,
6994 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006995 return false;
6996 }
6997
6998 final long identity = Binder.clearCallingIdentity();
6999 try {
7000 CarrierConfigManager configManager =
7001 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007002 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7004 } finally {
7005 Binder.restoreCallingIdentity(identity);
7006 }
Andrew Leea1239f22015-03-02 17:44:07 -08007007 }
7008
7009 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007010 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007011 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007012 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 return false;
7014 }
7015
7016 final long identity = Binder.clearCallingIdentity();
7017 try {
7018 CarrierConfigManager configManager =
7019 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007020 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7022 } finally {
7023 Binder.restoreCallingIdentity(identity);
7024 }
Andrew Leea1239f22015-03-02 17:44:07 -08007025 }
7026
Andrew Lee9431b832015-03-09 18:46:45 -07007027 @Override
7028 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007029 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007030 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007031 }
7032
7033 @Override
7034 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007035 final long identity = Binder.clearCallingIdentity();
7036 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007037 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038 } finally {
7039 Binder.restoreCallingIdentity(identity);
7040 }
Andrew Lee9431b832015-03-09 18:46:45 -07007041 }
7042
Hall Liuf6668912018-10-31 17:05:23 -07007043 /**
7044 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7045 * support for the feature and device firmware support.
7046 *
7047 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7048 */
7049 @Override
7050 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 final Phone phone = getPhone(subscriptionId);
7053 if (phone == null) {
7054 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7055 return false;
7056 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007057 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007058 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7060 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007061 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007062 return isCarrierSupported && isDeviceSupported;
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
Hall Liu98187582018-01-22 19:15:32 -08007066 }
7067
Hall Liuf6668912018-10-31 17:05:23 -07007068 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007069 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7070 * RTT setting, will return true if the device and carrier both support RTT.
7071 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007072 */
7073 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007074 final long identity = Binder.clearCallingIdentity();
7075 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007076 boolean isRttSupported = isRttSupported(subscriptionId);
7077 boolean isUserRttSettingOn = Settings.Secure.getInt(
7078 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7079 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7080 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7081 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007085 }
7086
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007087 @Deprecated
7088 @Override
7089 public String getDeviceId(String callingPackage) {
7090 return getDeviceIdWithFeature(callingPackage, null);
7091 }
7092
Sanket Padawe7310cc72015-01-14 09:53:20 -08007093 /**
7094 * Returns the unique device ID of phone, for example, the IMEI for
7095 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7096 *
7097 * <p>Requires Permission:
7098 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7099 */
7100 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007101 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007102 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007103 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007104 return null;
7105 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007106 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007107 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007108 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007109 return null;
7110 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111
7112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 return phone.getDeviceId();
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007118 }
7119
Ping Sunc67b7c22016-03-02 19:16:45 +08007120 /**
7121 * {@hide}
7122 * Returns the IMS Registration Status on a particular subid
7123 *
7124 * @param subId
7125 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007126 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007127 Phone phone = getPhone(subId);
7128 if (phone != null) {
7129 return phone.isImsRegistered();
7130 } else {
7131 return false;
7132 }
7133 }
7134
Santos Cordon7a1885b2015-02-03 11:15:19 -08007135 @Override
7136 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 final long identity = Binder.clearCallingIdentity();
7138 try {
7139 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7140 } finally {
7141 Binder.restoreCallingIdentity(identity);
7142 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007143 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007144
Tyler Gunnf70ed162019-04-03 15:28:53 -07007145 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007146 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007147 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007148 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007149 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007150 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7151 }
7152 final long identity = Binder.clearCallingIdentity();
7153 try {
7154 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7155 } finally {
7156 Binder.restoreCallingIdentity(identity);
7157 }
7158 }
7159
7160 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007161 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007162 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7163 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007164 final long identity = Binder.clearCallingIdentity();
7165 try {
7166 Phone phone = getPhone(subscriptionId);
7167 if (phone == null) {
7168 return null;
7169 }
7170 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7171 } finally {
7172 Binder.restoreCallingIdentity(identity);
7173 }
7174 }
7175
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007176 /**
7177 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007178 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007179 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007180 final long identity = Binder.clearCallingIdentity();
7181 try {
7182 Phone phone = getPhone(subId);
7183 if (phone != null) {
7184 return phone.isWifiCallingEnabled();
7185 } else {
7186 return false;
7187 }
7188 } finally {
7189 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007190 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007191 }
7192
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007193 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007194 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007195 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007196 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 Phone phone = getPhone(subId);
7200 if (phone != null) {
7201 return phone.isVideoEnabled();
7202 } else {
7203 return false;
7204 }
7205 } finally {
7206 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007207 }
7208 }
7209
7210 /**
7211 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7212 * defined in {@link ImsRegistrationImplBase}.
7213 */
7214 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007215 final long identity = Binder.clearCallingIdentity();
7216 try {
7217 Phone phone = getPhone(subId);
7218 if (phone != null) {
7219 return phone.getImsRegistrationTech();
7220 } else {
7221 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7222 }
7223 } finally {
7224 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007225 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007226 }
7227
Stuart Scott8eef64f2015-04-08 15:13:54 -07007228 @Override
7229 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007230 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007231 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7232 return;
7233 }
7234
Svet Ganovcc087f82015-05-12 20:35:54 -07007235 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007236
Svet Ganovcc087f82015-05-12 20:35:54 -07007237 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007238 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7239 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007240 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007241 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007242 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007243 setAllowedNetworkTypesForReason(subId,
7244 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7245 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7246 setAllowedNetworkTypesForReason(subId,
7247 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7248 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7249 setAllowedNetworkTypesForReason(subId,
7250 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7251 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007252 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7253 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007254 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007255 // There has been issues when Sms raw table somehow stores orphan
7256 // fragments. They lead to garbled message when new fragments come
7257 // in and combined with those stale ones. In case this happens again,
7258 // user can reset all network settings which will clean up this table.
7259 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007260 // Clean up IMS settings as well here.
7261 int slotId = getSlotIndex(subId);
7262 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7263 ImsManager.getInstance(mApp, slotId).factoryReset();
7264 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007265
7266 // Erase modem config if erase modem on network setting is enabled.
7267 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7268 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7269 if (configValue != null && Boolean.parseBoolean(configValue)) {
7270 sendEraseModemConfig(getDefaultPhone());
7271 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007272 } finally {
7273 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007274 }
7275 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007276
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007277 private void cleanUpSmsRawTable(Context context) {
7278 ContentResolver resolver = context.getContentResolver();
7279 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7280 resolver.delete(uri, null, null);
7281 }
7282
Narayan Kamath1c496c22015-04-16 14:40:19 +01007283 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007284 public String getSimLocaleForSubscriber(int subId) {
7285 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7286 final Phone phone = getPhone(subId);
7287 if (phone == null) {
7288 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007289 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291 final long identity = Binder.clearCallingIdentity();
7292 try {
chen xu5d3637b2019-01-21 23:31:38 -08007293 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007294 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007295 if (info == null) {
7296 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7297 return null;
7298 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007299 // Try and fetch the locale from the carrier properties or from the SIM language
7300 // preferences (EF-PL and EF-LI)...
7301 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007303 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7304 if (localeFromDefaultSim != null) {
7305 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7306 if (DBG) log("Using locale from subId: " + subId + " locale: "
7307 + localeFromDefaultSim);
7308 return localeFromDefaultSim.toLanguageTag();
7309 } else {
7310 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 }
7312 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 // The SIM language preferences only store a language (e.g. fr = French), not an
7315 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7316 // the SIM and carrier preferences does not include a country we add the country
7317 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007318 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007319 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007320 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007321 return mccLocale.toLanguageTag();
7322 }
7323
7324 if (DBG) log("No locale found - returning null");
7325 return null;
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
7328 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007329 }
7330
7331 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007332 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007333 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007334 }
7335
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007336 /**
7337 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7338 */
7339 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007340 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007341 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007342 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007343
Chenjie Yu1ba97252018-01-11 18:16:20 -08007344 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007345 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007346
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007347 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007348 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7349 * representing the state of the modem.
7350 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007351 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7352 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007353 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007354 */
7355 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007356 public void requestModemActivityInfo(ResultReceiver result) {
7357 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007358 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007359
7360 final long identity = Binder.clearCallingIdentity();
7361 try {
sqian1a1be542020-03-05 11:37:28 -08007362 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 } finally {
7364 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007365 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007366 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007367
Siddharth Rayb8114062018-06-17 15:02:38 -07007368 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7369 // less than total activity duration.
7370 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7371 if (info == null) {
7372 return false;
7373 }
7374 int activityDurationMs =
7375 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7376 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007377 int[] txTimeMs = info.getTransmitTimeMillis();
7378 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7379 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007380 }
7381 return (info.isValid()
7382 && (info.getSleepTimeMillis() <= activityDurationMs)
7383 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007384 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007385 && (totalTxTimeMs <= activityDurationMs));
7386 }
7387
Jack Yu85bd38a2015-11-09 11:34:32 -08007388 /**
7389 * {@hide}
7390 * Returns the service state information on specified subscription.
7391 */
7392 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7394 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007395 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007396 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007397 return null;
7398 }
7399
Hall Liuf19c44f2018-11-27 14:38:17 -08007400 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7401 LocationAccessPolicy.checkLocationPermission(mApp,
7402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7403 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007404 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007405 .setCallingPid(Binder.getCallingPid())
7406 .setCallingUid(Binder.getCallingUid())
7407 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007408 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007409 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7410 .build());
7411
7412 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7413 LocationAccessPolicy.checkLocationPermission(mApp,
7414 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7415 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007416 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007417 .setCallingPid(Binder.getCallingPid())
7418 .setCallingUid(Binder.getCallingUid())
7419 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007420 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007421 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7422 .build());
7423 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7424 boolean hasFinePermission =
7425 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7426 boolean hasCoarsePermission =
7427 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 final long identity = Binder.clearCallingIdentity();
7430 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007431 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7432 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7433 Rlog.d(LOG_TAG,
7434 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7435 return null;
7436 }
7437
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007438 final Phone phone = getPhone(subId);
7439 if (phone == null) {
7440 return null;
7441 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007442
Hall Liuf19c44f2018-11-27 14:38:17 -08007443 ServiceState ss = phone.getServiceState();
7444
7445 // Scrub out the location info in ServiceState depending on what level of access
7446 // the caller has.
7447 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007448 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7449 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007450 } finally {
7451 Binder.restoreCallingIdentity(identity);
7452 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007453 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007454
7455 /**
7456 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7457 *
7458 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7459 * voicemail ringtone.
7460 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7461 * PhoneAccount.
7462 */
7463 @Override
7464 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7468 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007469 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007470 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007471
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007472 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
7475 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007476 }
7477
7478 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007479 * Sets the per-account voicemail ringtone.
7480 *
7481 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7482 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7483 *
7484 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7485 * voicemail ringtone.
7486 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7487 * PhoneAccount.
7488 */
7489 @Override
7490 public void setVoicemailRingtoneUri(String callingPackage,
7491 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007492 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007493 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007494 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7495 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7497 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7498 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007499 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
7503 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7504 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007505 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007506 }
7507 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7508 } finally {
7509 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007510 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007511 }
7512
7513 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007514 * Returns whether vibration is set for voicemail notification in Phone settings.
7515 *
7516 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7517 * voicemail vibration setting.
7518 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7519 */
7520 @Override
7521 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 final long identity = Binder.clearCallingIdentity();
7523 try {
7524 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7525 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007526 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007527 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007528
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007529 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7530 } finally {
7531 Binder.restoreCallingIdentity(identity);
7532 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007533 }
7534
Youhan Wange64578a2016-05-02 15:32:42 -07007535 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007536 * Sets the per-account voicemail vibration.
7537 *
7538 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7539 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7540 *
7541 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7542 * voicemail vibration setting.
7543 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7544 * specific PhoneAccount.
7545 */
7546 @Override
7547 public void setVoicemailVibrationEnabled(String callingPackage,
7548 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007549 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007550 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007551 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7552 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007553 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7554 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7555 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007556 }
7557
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 final long identity = Binder.clearCallingIdentity();
7559 try {
7560 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7561 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007562 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007563 }
7564 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7565 } finally {
7566 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007567 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007568 }
7569
7570 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007571 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7572 *
7573 * @throws SecurityException if the caller does not have the required permission
7574 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007575 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007576 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007577 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007578 }
7579
7580 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007581 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7582 * permission.
7583 *
7584 * @throws SecurityException if the caller does not have the required permission
7585 */
7586 private void enforceSendSmsPermission() {
7587 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7588 }
7589
7590 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007591 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007592 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007593 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007594 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007595 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 final long identity = Binder.clearCallingIdentity();
7597 try {
7598 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007599 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 if (componentName == null) {
7601 throw new SecurityException(
7602 "Caller not current active visual voicemail package[null]");
7603 }
7604 String vvmPackage = componentName.getPackageName();
7605 if (!callingPackage.equals(vvmPackage)) {
7606 throw new SecurityException("Caller not current active visual voicemail package["
7607 + vvmPackage + "]");
7608 }
7609 } finally {
7610 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007611 }
7612 }
7613
7614 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007615 * Return the application ID for the app type.
7616 *
7617 * @param subId the subscription ID that this request applies to.
7618 * @param appType the uicc app type.
7619 * @return Application ID for specificied app type, or null if no uicc.
7620 */
7621 @Override
7622 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007623 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007624 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625
7626 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007627 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007628 if (phone == null) {
7629 return null;
7630 }
7631 String aid = null;
7632 try {
7633 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7634 .getApplicationByType(appType).getAid();
7635 } catch (Exception e) {
7636 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7637 }
7638 return aid;
7639 } finally {
7640 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007641 }
Youhan Wange64578a2016-05-02 15:32:42 -07007642 }
7643
Youhan Wang4001d252016-05-11 10:29:41 -07007644 /**
7645 * Return the Electronic Serial Number.
7646 *
7647 * @param subId the subscription ID that this request applies to.
7648 * @return ESN or null if error.
7649 */
7650 @Override
7651 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007652 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007653 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007654
7655 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007656 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657 if (phone == null) {
7658 return null;
7659 }
7660 String esn = null;
7661 try {
7662 esn = phone.getEsn();
7663 } catch (Exception e) {
7664 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7665 }
7666 return esn;
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007669 }
Youhan Wang4001d252016-05-11 10:29:41 -07007670 }
7671
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007672 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007673 * Return the Preferred Roaming List Version.
7674 *
7675 * @param subId the subscription ID that this request applies to.
7676 * @return PRLVersion or null if error.
7677 */
7678 @Override
7679 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007680 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007681 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007682
7683 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007684 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685 if (phone == null) {
7686 return null;
7687 }
7688 String cdmaPrlVersion = null;
7689 try {
7690 cdmaPrlVersion = phone.getCdmaPrlVersion();
7691 } catch (Exception e) {
7692 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7693 }
7694 return cdmaPrlVersion;
7695 } finally {
7696 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007697 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007698 }
7699
7700 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007701 * Get snapshot of Telephony histograms
7702 * @return List of Telephony histograms
7703 * @hide
7704 */
7705 @Override
7706 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007707 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7708 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709
7710 final long identity = Binder.clearCallingIdentity();
7711 try {
7712 return RIL.getTelephonyRILTimingHistograms();
7713 } finally {
7714 Binder.restoreCallingIdentity(identity);
7715 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007716 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007717
7718 /**
7719 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007720 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7721 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007722 * Require system privileges. In the future we may add this to carrier APIs.
7723 *
Michele Berionne482f8202018-11-27 18:57:59 -08007724 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007725 */
7726 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007727 @TelephonyManager.SetCarrierRestrictionResult
7728 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007729 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007730 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007731
Michele Berionne482f8202018-11-27 18:57:59 -08007732 if (carrierRestrictionRules == null) {
7733 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007734 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007736 final long identity = Binder.clearCallingIdentity();
7737 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007738 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007739 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007740 } finally {
7741 Binder.restoreCallingIdentity(identity);
7742 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007743 }
7744
7745 /**
7746 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007747 * Get the allowed carrier list and the excluded carrier list, including the priority between
7748 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007749 * Require system privileges. In the future we may add this to carrier APIs.
7750 *
Michele Berionne482f8202018-11-27 18:57:59 -08007751 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007752 */
7753 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007754 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007755 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007756 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007760 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7761 if (response instanceof CarrierRestrictionRules) {
7762 return (CarrierRestrictionRules) response;
7763 }
7764 // Response is an Exception of some kind,
7765 // which is signalled to the user as a NULL retval
7766 return null;
7767 } catch (Exception e) {
7768 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7769 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007770 } finally {
7771 Binder.restoreCallingIdentity(identity);
7772 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007773 }
7774
fionaxu59545b42016-05-25 15:53:37 -07007775 /**
fionaxu59545b42016-05-25 15:53:37 -07007776 * Action set from carrier signalling broadcast receivers to enable/disable radio
7777 * @param subId the subscription ID that this action applies to.
7778 * @param enabled control enable or disable radio.
7779 * {@hide}
7780 */
7781 @Override
7782 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7783 enforceModifyPermission();
7784 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007785
7786 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007787 if (phone == null) {
7788 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7789 return;
7790 }
7791 try {
7792 phone.carrierActionSetRadioEnabled(enabled);
7793 } catch (Exception e) {
7794 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007795 } finally {
7796 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007797 }
7798 }
7799
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007800 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007801 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7802 * network status based on which carrier apps could apply actions accordingly,
7803 * enable/disable default url handler for example.
7804 *
7805 * @param subId the subscription ID that this action applies to.
7806 * @param report control start/stop reporting the default network status.
7807 * {@hide}
7808 */
7809 @Override
7810 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7811 enforceModifyPermission();
7812 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007813
7814 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007815 if (phone == null) {
7816 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7817 return;
7818 }
7819 try {
7820 phone.carrierActionReportDefaultNetworkStatus(report);
7821 } catch (Exception e) {
7822 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007823 } finally {
7824 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007825 }
7826 }
7827
7828 /**
fionaxud9622282017-07-17 17:51:30 -07007829 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7830 * @param subId the subscription ID that this action applies to.
7831 * {@hide}
7832 */
7833 @Override
7834 public void carrierActionResetAll(int subId) {
7835 enforceModifyPermission();
7836 final Phone phone = getPhone(subId);
7837 if (phone == null) {
7838 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7839 return;
7840 }
7841 try {
7842 phone.carrierActionResetAll();
7843 } catch (Exception e) {
7844 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7845 }
7846 }
7847
7848 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007849 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7850 * bug report is being generated.
7851 */
7852 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007853 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007854 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7855 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007856 writer.println("Permission Denial: can't dump Phone from pid="
7857 + Binder.getCallingPid()
7858 + ", uid=" + Binder.getCallingUid()
7859 + "without permission "
7860 + android.Manifest.permission.DUMP);
7861 return;
7862 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007863 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007864 }
Jack Yueb89b242016-06-22 13:27:47 -07007865
Brad Ebingerdac2f002018-04-03 15:17:52 -07007866 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007867 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7868 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7869 @NonNull String[] args) {
7870 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7871 this, in.getFileDescriptor(), out.getFileDescriptor(),
7872 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007873 }
7874
Jack Yueb89b242016-06-22 13:27:47 -07007875 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007876 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007877 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007878 * @param reason the reason the data enable change is taking place
7879 * @param enabled True if enabling the data, otherwise disabling.
7880 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007881 */
7882 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007883 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007884 boolean enabled) {
7885 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7886 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7887 try {
7888 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007889 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007890 } catch (SecurityException se) {
7891 enforceModifyPermission();
7892 }
7893 } else {
7894 enforceModifyPermission();
7895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007896
7897 final long identity = Binder.clearCallingIdentity();
7898 try {
7899 Phone phone = getPhone(subId);
7900 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007901 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7902 phone.carrierActionSetMeteredApnsEnabled(enabled);
7903 } else {
7904 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7905 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007906 }
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007909 }
7910 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007911
7912 /**
7913 * Get Client request stats
7914 * @return List of Client Request Stats
7915 * @hide
7916 */
7917 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007918 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7919 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007920 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007921 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007922 return null;
7923 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007924 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 if (phone != null) {
7929 return phone.getClientRequestStats();
7930 }
7931
7932 return null;
7933 } finally {
7934 Binder.restoreCallingIdentity(identity);
7935 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007936 }
7937
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007938 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007939 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007940 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007941 }
Jack Yueb4124c2017-02-16 15:32:43 -08007942
7943 /**
Grace Chen70990072017-03-24 17:21:30 -07007944 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007945 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007946 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007947 * @param state State of SIM (power down, power up, pass through)
7948 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7949 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7950 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007951 *
7952 **/
7953 @Override
Grace Chen70990072017-03-24 17:21:30 -07007954 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007955 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007956 Phone phone = PhoneFactory.getPhone(slotIndex);
7957
vagdeviaf9a5b92018-08-15 16:01:53 -07007958 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007963 phone.setSimPowerState(state, null, workSource);
7964 }
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 }
7969
7970 /**
7971 * Set SIM card power state.
7972 *
7973 * @param slotIndex SIM slot id.
7974 * @param state State of SIM (power down, power up, pass through)
7975 * @param callback callback to trigger after success or failure
7976 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7977 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7978 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7979 *
7980 **/
7981 @Override
7982 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7983 IIntegerConsumer callback) {
7984 enforceModifyPermission();
7985 Phone phone = PhoneFactory.getPhone(slotIndex);
7986
7987 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7988
7989 final long identity = Binder.clearCallingIdentity();
7990 try {
7991 if (phone != null) {
7992 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7993 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007994 }
7995 } finally {
7996 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007997 }
7998 }
Shuo Qiandd210312017-04-12 22:11:33 +00007999
Tyler Gunn65d45c22017-06-05 11:22:26 -07008000 private boolean isUssdApiAllowed(int subId) {
8001 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008002 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008003 if (configManager == null) {
8004 return false;
8005 }
8006 PersistableBundle pb = configManager.getConfigForSubId(subId);
8007 if (pb == null) {
8008 return false;
8009 }
8010 return pb.getBoolean(
8011 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8012 }
8013
Shuo Qiandd210312017-04-12 22:11:33 +00008014 /**
8015 * Check if phone is in emergency callback mode
8016 * @return true if phone is in emergency callback mode
8017 * @param subId sub id
8018 */
goneil9c5f4872017-12-05 14:07:56 -08008019 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008020 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008021 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008022 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008023
8024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 if (phone != null) {
8027 return phone.isInEcm();
8028 } else {
8029 return false;
8030 }
8031 } finally {
8032 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008033 }
8034 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008035
8036 /**
8037 * Get the current signal strength information for the given subscription.
8038 * Because this information is not updated when the device is in a low power state
8039 * it should not be relied-upon to be current.
8040 * @param subId Subscription index
8041 * @return the most recent cached signal strength info from the modem
8042 */
8043 @Override
8044 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008045 final long identity = Binder.clearCallingIdentity();
8046 try {
8047 Phone p = getPhone(subId);
8048 if (p == null) {
8049 return null;
8050 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008051
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008052 return p.getSignalStrength();
8053 } finally {
8054 Binder.restoreCallingIdentity(identity);
8055 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008056 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008057
Pengquan Meng77b7f132018-08-22 14:49:57 -07008058 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008059 * Get the current modem radio state for the given slot.
8060 * @param slotIndex slot index.
8061 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008062 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008063 * @return the current radio power state from the modem
8064 */
8065 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008066 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008067 Phone phone = PhoneFactory.getPhone(slotIndex);
8068 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008069 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8070 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008071 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8072 }
8073
8074 final long identity = Binder.clearCallingIdentity();
8075 try {
8076 return phone.getRadioPowerState();
8077 } finally {
8078 Binder.restoreCallingIdentity(identity);
8079 }
8080 }
8081 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8082 }
8083
8084 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008085 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8086 *
8087 * <p>Requires one of the following permissions:
8088 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8089 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8090 * privileges.
8091 *
8092 * @param subId subscription id
8093 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8094 * {@code false}.
8095 */
8096 @Override
8097 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008098 try {
8099 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8100 null);
8101 } catch (Exception e) {
8102 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8103 mApp, subId, "isDataRoamingEnabled");
8104 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008105
Pengquan Menga1bb6272018-09-06 09:59:22 -07008106 boolean isEnabled = false;
8107 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008108 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008109 Phone phone = getPhone(subId);
8110 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008111 } finally {
8112 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008113 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008114 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008115 }
8116
8117
8118 /**
8119 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8120 *
8121 * <p> Requires permission:
8122 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8123 * privileges.
8124 *
8125 * @param subId subscription id
8126 * @param isEnabled {@code true} means enable, {@code false} means disable.
8127 */
8128 @Override
8129 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008130 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8131 mApp, subId, "setDataRoamingEnabled");
8132
Pengquan Menga1bb6272018-09-06 09:59:22 -07008133 final long identity = Binder.clearCallingIdentity();
8134 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008135 Phone phone = getPhone(subId);
8136 if (phone != null) {
8137 phone.setDataRoamingEnabled(isEnabled);
8138 }
8139 } finally {
8140 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008141 }
8142 }
8143
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008144 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008145 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008146 TelephonyPermissions
8147 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008148 mApp, subId, "isManualNetworkSelectionAllowed");
8149
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008150 boolean isAllowed = true;
8151 final long identity = Binder.clearCallingIdentity();
8152 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008153 Phone phone = getPhone(subId);
8154 if (phone != null) {
8155 isAllowed = phone.isCspPlmnEnabled();
8156 }
8157 } finally {
8158 Binder.restoreCallingIdentity(identity);
8159 }
8160 return isAllowed;
8161 }
8162
8163 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008164 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008165 // Verify that tha callingPackage belongs to the calling UID
8166 mApp.getSystemService(AppOpsManager.class)
8167 .checkPackage(Binder.getCallingUid(), callingPackage);
8168
Jordan Liu1e142fc2019-04-22 15:10:43 -07008169 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008170 try {
8171 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008172 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008173 } catch (SecurityException e) {
8174 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8175 // has carrier privileges on an active UICC
8176 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8177 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008178 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008179 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008180 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008181
8182 final long identity = Binder.clearCallingIdentity();
8183 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008184 UiccController uiccController = UiccController.getInstance();
8185 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008186 if (hasReadPermission) {
8187 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008188 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008189
8190 // Remove private info if the caller doesn't have access
8191 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8192 for (UiccCardInfo cardInfo : cardInfos) {
8193 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8194 // is available
8195 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8196 if (card == null || card.getUiccProfile() == null) {
8197 // assume no access if the card or profile is unavailable
8198 filteredInfos.add(cardInfo.getUnprivileged());
8199 continue;
8200 }
8201 UiccProfile profile = card.getUiccProfile();
8202 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8203 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8204 filteredInfos.add(cardInfo);
8205 } else {
8206 filteredInfos.add(cardInfo.getUnprivileged());
8207 }
8208 }
8209 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008210 } finally {
8211 Binder.restoreCallingIdentity(identity);
8212 }
8213 }
8214
8215 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008216 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008217 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008218
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008219 final long identity = Binder.clearCallingIdentity();
8220 try {
8221 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8222 if (slots == null) {
8223 Rlog.i(LOG_TAG, "slots is null.");
8224 return null;
8225 }
8226
8227 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8228 for (int i = 0; i < slots.length; i++) {
8229 UiccSlot slot = slots[i];
8230 if (slot == null) {
8231 continue;
8232 }
8233
Jordan Liu7be7e652019-05-06 18:55:02 +00008234 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008235 UiccCard card = slot.getUiccCard();
8236 if (card != null) {
8237 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008238 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008239 cardId = slot.getEid();
8240 if (TextUtils.isEmpty(cardId)) {
8241 cardId = slot.getIccId();
8242 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008243 }
8244
Jordan Liu857451f2019-05-09 16:35:35 -07008245 if (cardId != null) {
8246 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8247 // if cardId is an EID, it's all digits so this is fine
8248 cardId = IccUtils.stripTrailingFs(cardId);
8249 }
8250
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008251 int cardState = 0;
8252 switch (slot.getCardState()) {
8253 case CARDSTATE_ABSENT:
8254 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8255 break;
8256 case CARDSTATE_PRESENT:
8257 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8258 break;
8259 case CARDSTATE_ERROR:
8260 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8261 break;
8262 case CARDSTATE_RESTRICTED:
8263 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8264 break;
8265 default:
8266 break;
8267
8268 }
8269
8270 infos[i] = new UiccSlotInfo(
8271 slot.isActive(),
8272 slot.isEuicc(),
8273 cardId,
8274 cardState,
8275 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008276 slot.isExtendedApduSupported(),
8277 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008278 }
8279 return infos;
8280 } finally {
8281 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008282 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008283 }
8284
8285 @Override
8286 public boolean switchSlots(int[] physicalSlots) {
8287 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008288
8289 final long identity = Binder.clearCallingIdentity();
8290 try {
8291 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8292 } finally {
8293 Binder.restoreCallingIdentity(identity);
8294 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008295 }
Jack Yu4c988042018-02-27 15:30:01 -08008296
8297 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008298 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008299 final long identity = Binder.clearCallingIdentity();
8300 try {
8301 return UiccController.getInstance().getCardIdForDefaultEuicc();
8302 } finally {
8303 Binder.restoreCallingIdentity(identity);
8304 }
8305 }
8306
Pengquan Meng85728fb2018-03-12 16:31:21 -07008307 /**
goneil47ffb6e2018-04-06 15:40:58 -07008308 * A test API to reload the UICC profile.
8309 *
8310 * <p>Requires that the calling app has permission
8311 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8312 * @hide
8313 */
8314 @Override
8315 public void refreshUiccProfile(int subId) {
8316 enforceModifyPermission();
8317
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
8320 Phone phone = getPhone(subId);
8321 if (phone == null) {
8322 return;
8323 }
8324 UiccCard uiccCard = phone.getUiccCard();
8325 if (uiccCard == null) {
8326 return;
8327 }
8328 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8329 if (uiccProfile == null) {
8330 return;
8331 }
8332 uiccProfile.refresh();
8333 } finally {
8334 Binder.restoreCallingIdentity(identity);
8335 }
8336 }
8337
8338 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008339 * Returns false if the mobile data is disabled by default, otherwise return true.
8340 */
8341 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008342 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008343 }
8344
8345 /**
8346 * Returns true if the data roaming is enabled by default, i.e the system property
8347 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8348 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8349 */
8350 private boolean getDefaultDataRoamingEnabled(int subId) {
8351 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008352 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008353 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008354 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8355 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8356 return isDataRoamingEnabled;
8357 }
8358
8359 /**
8360 * Returns the default network type for the given {@code subId}, if the default network type is
8361 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8362 */
8363 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008364 List<Integer> list = TelephonyProperties.default_network();
8365 int phoneId = mSubscriptionController.getPhoneId(subId);
8366 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8367 return list.get(phoneId);
8368 }
8369 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008370 }
fionaxua13278b2018-03-21 00:08:13 -07008371
8372 @Override
8373 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008374 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008375 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008376
8377 final long identity = Binder.clearCallingIdentity();
8378 try {
8379 final Phone phone = getPhone(subId);
8380 if (phone == null) {
8381 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8382 return;
8383 }
chen xueaba88a2019-03-15 13:15:10 -07008384 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8385 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008386 if (carrierPrivilegeRules == null) {
8387 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8388 } else {
8389 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8390 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008391 } finally {
8392 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008393 }
fionaxua13278b2018-03-21 00:08:13 -07008394 }
8395
8396 @Override
8397 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008398 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008399
8400 final long identity = Binder.clearCallingIdentity();
8401 try {
8402 final Phone phone = getPhone(subId);
8403 if (phone == null) {
8404 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8405 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8406 }
8407 return phone.getCarrierIdListVersion();
8408 } finally {
8409 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008410 }
fionaxua13278b2018-03-21 00:08:13 -07008411 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008412
8413 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008414 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8415 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008416 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008417 mApp, subId, callingPackage, callingFeatureId,
8418 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008419 return -1;
8420 }
8421
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8425 } finally {
8426 Binder.restoreCallingIdentity(identity);
8427 }
8428 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008429
8430 @Override
8431 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008432 TelephonyPermissions
8433 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008434 mApp, subId, "getCdmaRoamingMode");
8435
8436 final long identity = Binder.clearCallingIdentity();
8437 try {
8438 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
8443
8444 @Override
8445 public boolean setCdmaRoamingMode(int subId, int mode) {
8446 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8447 mApp, subId, "setCdmaRoamingMode");
8448
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
8457 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008458 public int getCdmaSubscriptionMode(int subId) {
8459 TelephonyPermissions
8460 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8461 mApp, subId, "getCdmaSubscriptionMode");
8462
8463 final long identity = Binder.clearCallingIdentity();
8464 try {
8465 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8466 } finally {
8467 Binder.restoreCallingIdentity(identity);
8468 }
8469 }
8470
8471 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008472 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8474 mApp, subId, "setCdmaSubscriptionMode");
8475
8476 final long identity = Binder.clearCallingIdentity();
8477 try {
8478 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8479 } finally {
8480 Binder.restoreCallingIdentity(identity);
8481 }
8482 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008483
sqianc5eccab2018-10-19 18:46:41 -07008484 @Override
sqian8c685422019-02-22 15:55:18 -08008485 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008486 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008487 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008488 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8489 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008490 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8491 }
8492 final long identity = Binder.clearCallingIdentity();
8493 try {
sqian854d44b2018-12-12 16:48:18 -08008494 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8495 for (Phone phone: PhoneFactory.getPhones()) {
8496 if (phone.getEmergencyNumberTracker() != null
8497 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8498 emergencyNumberListInternal.put(
8499 phone.getSubId(),
8500 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8501 }
sqian11b7a0e2018-12-05 18:48:28 -08008502 }
sqian854d44b2018-12-12 16:48:18 -08008503 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
sqianc5eccab2018-10-19 18:46:41 -07008507 }
8508
8509 @Override
sqian8c685422019-02-22 15:55:18 -08008510 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008511 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008512 if (!exactMatch) {
8513 TelephonyPermissions
8514 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008515 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008516 }
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
sqian854d44b2018-12-12 16:48:18 -08008519 for (Phone phone: PhoneFactory.getPhones()) {
8520 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008521 && phone.getEmergencyNumberTracker()
8522 .isEmergencyNumber(number, exactMatch)) {
8523 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008524 }
sqian11b7a0e2018-12-05 18:48:28 -08008525 }
8526 return false;
8527 } finally {
8528 Binder.restoreCallingIdentity(identity);
8529 }
8530 }
8531
sqianf4ca7ed2019-01-15 18:32:07 -08008532 /**
8533 * Update emergency number list for test mode.
8534 */
8535 @Override
8536 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8537 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8538 "updateEmergencyNumberListTestMode");
8539
8540 final long identity = Binder.clearCallingIdentity();
8541 try {
8542 for (Phone phone: PhoneFactory.getPhones()) {
8543 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8544 if (tracker != null) {
8545 tracker.executeEmergencyNumberTestModeCommand(action, num);
8546 }
8547 }
8548 } finally {
8549 Binder.restoreCallingIdentity(identity);
8550 }
8551 }
8552
8553 /**
8554 * Get the full emergency number list for test mode.
8555 */
8556 @Override
8557 public List<String> getEmergencyNumberListTestMode() {
8558 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8559 "getEmergencyNumberListTestMode");
8560
8561 final long identity = Binder.clearCallingIdentity();
8562 try {
8563 Set<String> emergencyNumbers = new HashSet<>();
8564 for (Phone phone: PhoneFactory.getPhones()) {
8565 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8566 if (tracker != null) {
8567 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8568 emergencyNumbers.add(num.getNumber());
8569 }
8570 }
8571 }
8572 return new ArrayList<>(emergencyNumbers);
8573 } finally {
8574 Binder.restoreCallingIdentity(identity);
8575 }
8576 }
8577
chen xud6b45bd2018-10-30 22:27:10 -07008578 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008579 public int getEmergencyNumberDbVersion(int subId) {
8580 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8581
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 final Phone phone = getPhone(subId);
8585 if (phone == null) {
8586 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8587 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8588 }
8589 return phone.getEmergencyNumberDbVersion();
8590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
8593 }
8594
8595 @Override
8596 public void notifyOtaEmergencyNumberDbInstalled() {
8597 enforceModifyPermission();
8598
8599 final long identity = Binder.clearCallingIdentity();
8600 try {
8601 for (Phone phone: PhoneFactory.getPhones()) {
8602 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8603 if (tracker != null) {
8604 tracker.updateOtaEmergencyNumberDatabase();
8605 }
8606 }
8607 } finally {
8608 Binder.restoreCallingIdentity(identity);
8609 }
8610 }
8611
8612 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008613 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008614 enforceActiveEmergencySessionPermission();
8615
8616 final long identity = Binder.clearCallingIdentity();
8617 try {
8618 for (Phone phone: PhoneFactory.getPhones()) {
8619 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8620 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008621 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8622 }
8623 }
8624 } finally {
8625 Binder.restoreCallingIdentity(identity);
8626 }
8627 }
8628
8629 @Override
8630 public void resetOtaEmergencyNumberDbFilePath() {
8631 enforceActiveEmergencySessionPermission();
8632
8633 final long identity = Binder.clearCallingIdentity();
8634 try {
8635 for (Phone phone: PhoneFactory.getPhones()) {
8636 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8637 if (tracker != null) {
8638 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008639 }
8640 }
8641 } finally {
8642 Binder.restoreCallingIdentity(identity);
8643 }
8644 }
8645
8646 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008647 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8648 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8649 Phone phone = getPhone(subId);
8650 if (phone == null) {
8651 return null;
8652 }
8653 final long identity = Binder.clearCallingIdentity();
8654 try {
8655 UiccProfile profile = UiccController.getInstance()
8656 .getUiccProfileForPhone(phone.getPhoneId());
8657 if (profile != null) {
8658 return profile.getCertsFromCarrierPrivilegeAccessRules();
8659 }
8660 } finally {
8661 Binder.restoreCallingIdentity(identity);
8662 }
8663 return null;
8664 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008665
8666 /**
8667 * Enable or disable a modem stack.
8668 */
8669 @Override
8670 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8671 enforceModifyPermission();
8672
8673 final long identity = Binder.clearCallingIdentity();
8674 try {
8675 Phone phone = PhoneFactory.getPhone(slotIndex);
8676 if (phone == null) {
8677 return false;
8678 } else {
8679 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8680 }
8681 } finally {
8682 Binder.restoreCallingIdentity(identity);
8683 }
8684 }
Michelecea4cf22018-12-21 15:00:11 -08008685
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008686 /**
8687 * Whether a modem stack is enabled or not.
8688 */
8689 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008690 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8691 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008692 Phone phone = PhoneFactory.getPhone(slotIndex);
8693 if (phone == null) return false;
8694
8695 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008696 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8697 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008698 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8699 }
8700
8701 final long identity = Binder.clearCallingIdentity();
8702 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008703 try {
8704 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8705 } catch (NoSuchElementException ex) {
8706 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8707 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008708 } finally {
8709 Binder.restoreCallingIdentity(identity);
8710 }
8711 }
8712
Michelecea4cf22018-12-21 15:00:11 -08008713 @Override
Michele0ea7d782019-03-19 14:58:42 -07008714 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008715 enforceModifyPermission();
8716
8717 final long identity = Binder.clearCallingIdentity();
8718 try {
8719 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008720 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008721 .commit();
8722 } finally {
8723 Binder.restoreCallingIdentity(identity);
8724 }
8725 }
8726
8727 @Override
Michele0ea7d782019-03-19 14:58:42 -07008728 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008729 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008730 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008731 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8732 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008733 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008734 }
Michelecea4cf22018-12-21 15:00:11 -08008735
8736 final long identity = Binder.clearCallingIdentity();
8737 try {
Michele0ea7d782019-03-19 14:58:42 -07008738 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008739 } finally {
8740 Binder.restoreCallingIdentity(identity);
8741 }
8742 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008743
Michele0ea7d782019-03-19 14:58:42 -07008744 @TelephonyManager.IsMultiSimSupportedResult
8745 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008746 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8747 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8748 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008749 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8750 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008751 }
8752 // Check if the hardware supports multisim functionality. If usage of multisim is not
8753 // supported by the modem, indicate that it is restricted.
8754 PhoneCapability staticCapability =
8755 mPhoneConfigurationManager.getStaticPhoneCapability();
8756 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008757 loge("isMultiSimSupportedInternal: no static configuration available");
8758 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008759 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008760 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008761 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8762 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008763 }
8764 // Check if support of multiple SIMs is restricted by carrier
8765 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008766 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008767 }
8768
Michele0ea7d782019-03-19 14:58:42 -07008769 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008770 }
8771
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008772 /**
8773 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008774 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8775 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8776 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008777 * @param numOfSims number of active sims we want to switch to
8778 */
8779 @Override
8780 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008781 if (numOfSims == 1) {
8782 enforceModifyPermission();
8783 } else {
8784 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8785 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8786 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008787 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008788
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008789 try {
Michele30b57b22019-03-01 12:01:14 -08008790 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008791 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008792 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8793 return;
8794 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008795 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8796 } finally {
8797 Binder.restoreCallingIdentity(identity);
8798 }
8799 }
8800
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008801 @Override
8802 public boolean isApplicationOnUicc(int subId, int appType) {
8803 enforceReadPrivilegedPermission("isApplicationOnUicc");
8804 Phone phone = getPhone(subId);
8805 if (phone == null) {
8806 return false;
8807 }
8808 final long identity = Binder.clearCallingIdentity();
8809 try {
8810 UiccCard uiccCard = phone.getUiccCard();
8811 if (uiccCard == null) {
8812 return false;
8813 }
8814 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8815 if (uiccProfile == null) {
8816 return false;
8817 }
8818 if (TelephonyManager.APPTYPE_SIM <= appType
8819 && appType <= TelephonyManager.APPTYPE_ISIM) {
8820 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8821 }
8822 return false;
8823 } finally {
8824 Binder.restoreCallingIdentity(identity);
8825 }
8826 }
8827
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008828 /**
chen xub4baa772019-04-03 10:23:41 -07008829 * Get whether making changes to modem configurations will trigger reboot.
8830 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008831 */
8832 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008833 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8834 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008835 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008836 mApp, subId, callingPackage, callingFeatureId,
8837 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008838 return false;
8839 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008840 final long identity = Binder.clearCallingIdentity();
8841 try {
8842 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8843 } finally {
8844 Binder.restoreCallingIdentity(identity);
8845 }
8846 }
8847
Nathan Harold29f5f052019-02-15 13:41:57 -08008848 private void updateModemStateMetrics() {
8849 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8850 // TODO: check the state for each modem if the api is ready.
8851 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8852 }
8853
Pengquan Meng3889a572019-01-23 11:16:29 -08008854 @Override
8855 public int[] getSlotsMapping() {
8856 enforceReadPrivilegedPermission("getSlotsMapping");
8857
8858 final long identity = Binder.clearCallingIdentity();
8859 try {
8860 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8861 // All logical slots should have a mapping to a physical slot.
8862 int[] logicalSlotsMapping = new int[phoneCount];
8863 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8864 for (int i = 0; i < slotInfos.length; i++) {
8865 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8866 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8867 }
8868 }
8869 return logicalSlotsMapping;
8870 } finally {
8871 Binder.restoreCallingIdentity(identity);
8872 }
8873 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008874
8875 /**
8876 * Get the IRadio HAL Version
8877 */
8878 @Override
8879 public int getRadioHalVersion() {
8880 Phone phone = getDefaultPhone();
8881 if (phone == null) return -1;
8882 HalVersion hv = phone.getHalVersion();
8883 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8884 return hv.major * 100 + hv.minor;
8885 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008886
8887 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008888 * Get the current calling package name.
8889 * @return the current calling package name
8890 */
8891 @Override
8892 public String getCurrentPackageName() {
8893 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8894 }
8895
8896 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008897 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8898 * corresponding network requests on a subId.
8899 *
8900 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008901 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008902 * 2) APN is un-metered for this subscription, or
8903 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008904 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008905 *
8906 * @return whether data is allowed for a apn type.
8907 *
8908 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008909 */
8910 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008911 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008912 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8913 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008914
8915 // Now that all security checks passes, perform the operation as ourselves.
8916 final long identity = Binder.clearCallingIdentity();
8917 try {
8918 Phone phone = getPhone(subId);
8919 if (phone == null) return false;
8920
Jack Yu41407ee2019-05-13 16:54:09 -07008921 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008922 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8923 } finally {
8924 Binder.restoreCallingIdentity(identity);
8925 }
8926 }
8927
8928 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008929 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008930 enforceReadPrivilegedPermission("isApnMetered");
8931
8932 // Now that all security checks passes, perform the operation as ourselves.
8933 final long identity = Binder.clearCallingIdentity();
8934 try {
8935 Phone phone = getPhone(subId);
8936 if (phone == null) return true; // By default return true.
8937
Jack Yu41407ee2019-05-13 16:54:09 -07008938 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008939 } finally {
8940 Binder.restoreCallingIdentity(identity);
8941 }
8942 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008943
8944 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008945 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8946 int subscriptionId, IBooleanConsumer resultCallback) {
8947 enforceModifyPermission();
8948 long token = Binder.clearCallingIdentity();
8949 try {
8950 Phone phone = getPhone(subscriptionId);
8951 if (phone == null) {
8952 try {
8953 if (resultCallback != null) {
8954 resultCallback.accept(false);
8955 }
8956 } catch (RemoteException e) {
8957 // ignore
8958 }
8959 return;
8960 }
8961 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8962 Pair.create(specifiers, (x) -> {
8963 try {
8964 if (resultCallback != null) {
8965 resultCallback.accept(x);
8966 }
8967 } catch (RemoteException e) {
8968 // ignore
8969 }
8970 });
8971 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8972 } finally {
8973 Binder.restoreCallingIdentity(token);
8974 }
8975 }
8976
8977 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008978 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8979 TelephonyPermissions
8980 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8981 mApp, subId, "getSystemSelectionChannels");
8982 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8983 final long identity = Binder.clearCallingIdentity();
8984 try {
8985 List<RadioAccessSpecifier> specifiers =
8986 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8987 null, subId, workSource);
8988 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8989 return specifiers;
8990 } finally {
8991 Binder.restoreCallingIdentity(identity);
8992 }
8993 }
8994
8995 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008996 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008997 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008998 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8999 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9000 if (iccRecords == null) {
9001 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9002 return false;
9003 }
9004 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9005 }
9006
9007 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009008 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9009 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009010 if (callingPackage == null) {
9011 callingPackage = getCurrentPackageName();
9012 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009013 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9014 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009015 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9016 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009017 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9018 }
9019 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9020 Intent intent = new Intent();
9021 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9022 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9023 // Bring up choose default SMS subscription dialog right now
9024 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9025 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9026 mApp.startActivity(intent);
9027 }
chen xud5ca2d52019-05-28 15:20:57 -07009028
9029 @Override
9030 public String getMmsUAProfUrl(int subId) {
9031 //TODO investigate if this API should require proper permission check in R b/133791609
9032 final long identity = Binder.clearCallingIdentity();
9033 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009034 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9035 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9036 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9037 return carrierUAProfUrl;
9038 }
chen xud5ca2d52019-05-28 15:20:57 -07009039 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9040 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9041 } finally {
9042 Binder.restoreCallingIdentity(identity);
9043 }
9044 }
9045
9046 @Override
9047 public String getMmsUserAgent(int subId) {
9048 //TODO investigate if this API should require proper permission check in R b/133791609
9049 final long identity = Binder.clearCallingIdentity();
9050 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009051 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9052 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9053 if (!TextUtils.isEmpty(carrierUserAgent)) {
9054 return carrierUserAgent;
9055 }
chen xud5ca2d52019-05-28 15:20:57 -07009056 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9057 .getString(com.android.internal.R.string.config_mms_user_agent);
9058 } finally {
9059 Binder.restoreCallingIdentity(identity);
9060 }
9061 }
Jack Yub07d4972019-05-28 16:12:25 -07009062
9063 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009064 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9065 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9066
9067 final long identity = Binder.clearCallingIdentity();
9068 try {
9069 Phone phone = getPhone(subscriptionId);
9070 if (phone == null) return false;
9071
9072 switch (policy) {
9073 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9074 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9075 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9076 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9077 default:
9078 throw new IllegalArgumentException(policy + " is not a valid policy");
9079 }
9080 } finally {
9081 Binder.restoreCallingIdentity(identity);
9082 }
9083 }
9084
9085 @Override
9086 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9087 boolean enabled) {
9088 enforceModifyPermission();
9089
9090 final long identity = Binder.clearCallingIdentity();
9091 try {
9092 Phone phone = getPhone(subscriptionId);
9093 if (phone == null) return;
9094
9095 switch (policy) {
9096 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9097 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9098 break;
9099 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9100 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9101 break;
9102 default:
9103 throw new IllegalArgumentException(policy + " is not a valid policy");
9104 }
9105 } finally {
9106 Binder.restoreCallingIdentity(identity);
9107 }
9108 }
9109
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009110 /**
Hall Liub48cf452020-09-25 11:13:49 -07009111 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009112 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9113 * otherwise.
9114 */
9115 @Override
9116 public void setCepEnabled(boolean isCepEnabled) {
9117 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9118
9119 final long identity = Binder.clearCallingIdentity();
9120 try {
9121 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9122 for (Phone phone : PhoneFactory.getPhones()) {
9123 Phone defaultPhone = phone.getImsPhone();
9124 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9125 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9126 ImsPhoneCallTracker imsPhoneCallTracker =
9127 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9128 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9129 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9130 + imsPhone.getMsisdn());
9131 }
9132 }
9133 } finally {
9134 Binder.restoreCallingIdentity(identity);
9135 }
9136 }
allenwtsu46dcc572020-01-08 18:24:03 +08009137
9138 /**
9139 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9140 *
9141 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9142 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9143 * before being read.
9144 */
9145 @Override
9146 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9147 isCompressed) {
9148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9149 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009150 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9151 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9152 }
9153 if (!isImsAvailableOnDevice()) {
9154 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9155 "IMS not available on device.");
9156 }
9157
9158 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009159 try {
Hui Wang068ab862020-10-31 05:12:53 +00009160 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9161 } finally {
9162 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009163 }
9164 }
zoey chenf95ca592019-12-30 16:11:23 +08009165
9166 @Override
9167 public boolean isIccLockEnabled(int subId) {
9168 enforceReadPrivilegedPermission("isIccLockEnabled");
9169
9170 // Now that all security checks passes, perform the operation as ourselves.
9171 final long identity = Binder.clearCallingIdentity();
9172 try {
9173 Phone phone = getPhone(subId);
9174 if (phone != null && phone.getIccCard() != null) {
9175 return phone.getIccCard().getIccLockEnabled();
9176 } else {
9177 return false;
9178 }
9179 } finally {
9180 Binder.restoreCallingIdentity(identity);
9181 }
9182 }
9183
9184 /**
zoey chene02881a2019-12-30 16:11:23 +08009185 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009186 *
zoey chene02881a2019-12-30 16:11:23 +08009187 * @return an integer representing the status of IccLock enabled or disabled in the following
9188 * three cases:
9189 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9190 * successfully.
9191 * - Positive number and zero for remaining password attempts.
9192 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009193 *
9194 */
9195 @Override
9196 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9197 enforceModifyPermission();
9198
9199 Phone phone = getPhone(subId);
9200 if (phone == null) {
9201 return 0;
9202 }
9203 // Now that all security checks passes, perform the operation as ourselves.
9204 final long identity = Binder.clearCallingIdentity();
9205 try {
9206 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9207 new Pair<Boolean, String>(enabled, password), phone, null);
9208 return attemptsRemaining;
9209
9210 } catch (Exception e) {
9211 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9212 } finally {
9213 Binder.restoreCallingIdentity(identity);
9214 }
9215 return 0;
9216 }
9217
9218 /**
9219 * Change the ICC password used in ICC pin lock.
9220 *
zoey chene02881a2019-12-30 16:11:23 +08009221 * @return an integer representing the status of IccLock changed in the following three cases:
9222 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9223 * - Positive number and zero for remaining password attempts.
9224 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009225 *
9226 */
9227 @Override
9228 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9229 enforceModifyPermission();
9230
9231 Phone phone = getPhone(subId);
9232 if (phone == null) {
9233 return 0;
9234 }
9235 // Now that all security checks passes, perform the operation as ourselves.
9236 final long identity = Binder.clearCallingIdentity();
9237 try {
9238 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9239 new Pair<String, String>(oldPassword, newPassword), phone, null);
9240 return attemptsRemaining;
9241
9242 } catch (Exception e) {
9243 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9244 } finally {
9245 Binder.restoreCallingIdentity(identity);
9246 }
9247 return 0;
9248 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009249
Peter Wangdafb9ac2020-01-15 14:13:38 -08009250 /**
9251 * Request for receiving user activity notification
9252 */
9253 @Override
9254 public void requestUserActivityNotification() {
9255 if (!mNotifyUserActivity.get()
9256 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9257 mNotifyUserActivity.set(true);
9258 }
9259 }
9260
9261 /**
9262 * Called when userActivity is signalled in the power manager.
9263 * This is safe to call from any thread, with any window manager locks held or not.
9264 */
9265 @Override
9266 public void userActivity() {
9267 // ***************************************
9268 // * Inherited from PhoneWindowManager *
9269 // ***************************************
9270 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9271 // WITH ITS LOCKS HELD.
9272 //
9273 // This code must be VERY careful about the locks
9274 // it acquires.
9275 // In fact, the current code acquires way too many,
9276 // and probably has lurking deadlocks.
9277
9278 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9279 throw new SecurityException("Only the OS may call notifyUserActivity()");
9280 }
9281
9282 if (mNotifyUserActivity.getAndSet(false)) {
9283 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9284 USER_ACTIVITY_NOTIFICATION_DELAY);
9285 }
9286 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009287
Malcolm Chen884180b2020-04-13 11:59:40 -07009288 @Override
9289 public boolean canConnectTo5GInDsdsMode() {
9290 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9291 }
Jack Yud10cdd42020-09-28 20:28:01 -07009292
9293 @Override
9294 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9295 String callingFeatureId) {
9296 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9297 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9298 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9299 }
9300
9301 Phone phone = getPhone(subId);
9302 if (phone == null) {
9303 throw new RuntimeException("phone is not available");
9304 }
9305 // Now that all security checks passes, perform the operation as ourselves.
9306 final long identity = Binder.clearCallingIdentity();
9307 try {
9308 return phone.getEquivalentHomePlmns();
9309 } finally {
9310 Binder.restoreCallingIdentity(identity);
9311 }
9312 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009313
Hui Wang0866fcc2020-10-12 12:14:23 -07009314 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009315 public boolean isRadioInterfaceCapabilitySupported(
9316 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009317 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009318 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9319 if (radioInterfaceCapabilities == null) {
9320 throw new RuntimeException("radio interface capabilities are not available");
9321 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009322 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009323 }
9324 }
9325
9326 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009327 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9328 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009329 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9330 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9331 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9332 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9333 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009334 if (DBG) {
9335 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9336 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9337 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9338 }
9339
9340 if (!SubscriptionManager.isValidSubscriptionId(subId)
9341 || appType < TelephonyManager.APPTYPE_UNKNOWN
9342 || appType > TelephonyManager.APPTYPE_ISIM
9343 || nafUrl == null || securityProtocol == null || callback == null) {
9344 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9345 if (callback != null) {
9346 try {
9347 callback.onAuthenticationFailure(
9348 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9349 } catch (RemoteException exception) {
9350 log("Fail to notify onAuthenticationFailure due to " + exception);
9351 }
9352 return;
9353 }
9354 }
9355
9356 final long token = Binder.clearCallingIdentity();
9357 try {
9358 getGbaManager(subId).bootstrapAuthenticationRequest(
9359 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9360 forceBootStrapping, callback));
9361 } finally {
9362 Binder.restoreCallingIdentity(token);
9363 }
9364 }
9365
Jack Nudelman24d51a52020-11-24 12:08:04 -08009366 /**
9367 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9368 * requested radio power state will actually be set. See {@link
9369 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9370 *
9371 * @param subId the subscription ID of the phone requesting to set the radio power state.
9372 * @param enable {@code true} if trying to turn radio on.
9373 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9374 * false}.
9375 */
9376 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9377 Phone phone = getPhone(subId);
9378 if (phone != null) {
9379 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9380 return true;
9381 }
9382 return false;
9383 }
9384
9385 private int handleDataThrottlingRequest(int subId,
9386 DataThrottlingRequest dataThrottlingRequest) {
9387 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9388 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9389 if (!setRadioPowerForThermal(subId, true)) {
9390 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9391 }
9392
9393 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9394
9395 int thermalMitigationResult =
9396 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9397 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9398 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9399 }
9400 return thermalMitigationResult;
9401 }
9402
9403 /**
9404 * Thermal mitigation request to control functionalities at modem.
9405 *
9406 * @param subId the id of the subscription.
9407 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9408 *
9409 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9410 */
9411 @Override
9412 @ThermalMitigationResult
9413 public int sendThermalMitigationRequest(
9414 int subId,
9415 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9416 enforceModifyPermission();
9417
9418 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9419 final long identity = Binder.clearCallingIdentity();
9420
9421 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9422 try {
9423 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9424 switch (thermalMitigationAction) {
9425 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9426 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009427 handleDataThrottlingRequest(subId,
9428 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009429 break;
9430 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9431 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9432 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9433 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9434 }
9435
9436 // Ensure that radio is on. If not able to power on due to phone being
9437 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9438 if (!setRadioPowerForThermal(subId, true)) {
9439 thermalMitigationResult =
9440 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9441 break;
9442 }
9443
9444 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9445 false);
9446 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9447 break;
9448 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9449 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9450 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9451 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9452 }
9453
9454 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9455 if (registry != null) {
9456 TelephonyConnectionService service =
9457 registry.getTelephonyConnectionService();
9458 Phone phone = getPhone(subId);
9459 if (phone == null) {
9460 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009461 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009462 break;
9463 }
9464
9465 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009466 != TelephonyManager.CALL_STATE_IDLE
9467 || phone.isInEmergencySmsMode() || phone.isInEcm()
9468 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009469 String errorMessage = "Phone state is not valid. call state = "
9470 + PhoneConstantConversions.convertCallState(phone.getState())
9471 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9472 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9473 errorMessage += service == null
9474 ? " TelephonyConnectionService is null"
9475 : " isEmergencyCallPending = "
9476 + service.isEmergencyCallPending();
9477 Log.e(LOG_TAG, errorMessage);
9478 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009479 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009480 break;
9481 }
9482 } else {
9483 thermalMitigationResult =
9484 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9485 break;
9486 }
9487
9488 // Turn radio off. If not able to power off due to phone being unavailable,
9489 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9490 if (!setRadioPowerForThermal(subId, false)) {
9491 thermalMitigationResult =
9492 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9493 break;
9494 }
9495 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009496 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009497 break;
9498 default:
9499 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9500 + "not exist. Requested action: " + thermalMitigationAction);
9501 }
9502 } catch (IllegalArgumentException e) {
9503 throw e;
9504 } catch (Exception e) {
9505 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9506 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9507 } finally {
9508 Binder.restoreCallingIdentity(identity);
9509 }
9510
9511 if (DBG) {
9512 log("thermalMitigationRequest returning with thermalMitigationResult: "
9513 + thermalMitigationResult);
9514 }
9515
9516 return thermalMitigationResult;
9517 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009518
9519 /**
9520 * Set the GbaService Package Name that Telephony will bind to.
9521 *
9522 * @param subId The sim that the GbaService is associated with.
9523 * @param packageName The name of the package to be replaced with.
9524 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9525 */
9526 @Override
9527 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9528 enforceModifyPermission();
9529
9530 final long identity = Binder.clearCallingIdentity();
9531 try {
9532 return getGbaManager(subId).overrideServicePackage(packageName);
9533 } finally {
9534 Binder.restoreCallingIdentity(identity);
9535 }
9536 }
9537
9538 /**
9539 * Return the package name of the currently bound GbaService.
9540 *
9541 * @param subId The sim that the GbaService is associated with.
9542 * @return the package name of the GbaService configuration, null if GBA is not supported.
9543 */
9544 @Override
9545 public String getBoundGbaService(int subId) {
9546 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9547
9548 final long identity = Binder.clearCallingIdentity();
9549 try {
9550 return getGbaManager(subId).getServicePackage();
9551 } finally {
9552 Binder.restoreCallingIdentity(identity);
9553 }
9554 }
9555
9556 /**
9557 * Set the release time for telephony to unbind GbaService.
9558 *
9559 * @param subId The sim that the GbaService is associated with.
9560 * @param interval The release time to unbind GbaService by millisecond.
9561 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9562 */
9563 @Override
9564 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9565 enforceModifyPermission();
9566
9567 final long identity = Binder.clearCallingIdentity();
9568 try {
9569 return getGbaManager(subId).overrideReleaseTime(interval);
9570 } finally {
9571 Binder.restoreCallingIdentity(identity);
9572 }
9573 }
9574
9575 /**
9576 * Return the release time for telephony to unbind GbaService.
9577 *
9578 * @param subId The sim that the GbaService is associated with.
9579 * @return The release time to unbind GbaService by millisecond.
9580 */
9581 @Override
9582 public int getGbaReleaseTime(int subId) {
9583 enforceReadPrivilegedPermission("getGbaReleaseTime");
9584
9585 final long identity = Binder.clearCallingIdentity();
9586 try {
9587 return getGbaManager(subId).getReleaseTime();
9588 } finally {
9589 Binder.restoreCallingIdentity(identity);
9590 }
9591 }
9592
9593 private GbaManager getGbaManager(int subId) {
9594 GbaManager instance = GbaManager.getInstance(subId);
9595 if (instance == null) {
9596 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9597 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9598 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9599 }
9600 return instance;
9601 }
Hui Wang068ab862020-10-31 05:12:53 +00009602
9603 /**
9604 * indicate whether the device and the carrier can support
9605 * RCS VoLTE single registration.
9606 */
9607 @Override
9608 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009609 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9610 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9611 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9612 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009613
9614 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9615 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9616 }
9617
9618 final long identity = Binder.clearCallingIdentity();
9619 try {
9620 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9621 if (rpm != null) {
9622 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9623 }
9624 return false;
9625 } finally {
9626 Binder.restoreCallingIdentity(identity);
9627 }
9628 }
9629
9630 /**
9631 * Register RCS provisioning callback.
9632 */
9633 @Override
9634 public void registerRcsProvisioningChangedCallback(int subId,
9635 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009636 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9637 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9638 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9639 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009640
9641 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9642 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9643 }
9644 if (!isImsAvailableOnDevice()) {
9645 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9646 "IMS not available on device.");
9647 }
9648
9649 final long identity = Binder.clearCallingIdentity();
9650 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009651 if (!RcsProvisioningMonitor.getInstance()
9652 .registerRcsProvisioningChangedCallback(subId, callback)) {
9653 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9654 "Service not available for the subscription.");
9655 }
Hui Wang068ab862020-10-31 05:12:53 +00009656 } finally {
9657 Binder.restoreCallingIdentity(identity);
9658 }
9659 }
9660
9661 /**
9662 * Unregister RCS provisioning callback.
9663 */
9664 @Override
9665 public void unregisterRcsProvisioningChangedCallback(int subId,
9666 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009667 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9668 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9669 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9670 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009671
9672 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9673 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9674 }
9675 if (!isImsAvailableOnDevice()) {
9676 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9677 "IMS not available on device.");
9678 }
9679
9680 final long identity = Binder.clearCallingIdentity();
9681 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009682 RcsProvisioningMonitor.getInstance()
9683 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009684 } finally {
9685 Binder.restoreCallingIdentity(identity);
9686 }
9687 }
9688
9689 /**
9690 * trigger RCS reconfiguration.
9691 */
9692 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009693 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9694 "triggerRcsReconfiguration",
9695 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009696
9697 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9698 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9699 }
9700 if (!isImsAvailableOnDevice()) {
9701 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9702 "IMS not available on device.");
9703 }
9704
9705 final long identity = Binder.clearCallingIdentity();
9706 try {
9707 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9708 } finally {
9709 Binder.restoreCallingIdentity(identity);
9710 }
9711 }
9712
9713 /**
9714 * Provide the client configuration parameters of the RCS application.
9715 */
9716 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009717 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9718 "setRcsClientConfiguration",
9719 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009720
9721 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9722 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9723 }
9724 if (!isImsAvailableOnDevice()) {
9725 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9726 "IMS not available on device.");
9727 }
9728
9729 final long identity = Binder.clearCallingIdentity();
9730
9731 try {
9732 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9733 if (configBinder == null) {
9734 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9735 } else {
9736 configBinder.setRcsClientConfiguration(rcc);
9737 }
9738 } catch (RemoteException e) {
9739 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9740 } finally {
9741 Binder.restoreCallingIdentity(identity);
9742 }
9743 }
9744
9745 /**
Hui Wang19a21872021-02-19 20:45:36 -08009746 * Enables or disables the test mode for RCS VoLTE single registration.
9747 */
9748 @Override
9749 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9750 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9751 "setRcsSingleRegistrationTestModeEnabled");
9752
9753 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9754 }
9755
9756 /**
9757 * Gets the test mode for RCS VoLTE single registration.
9758 */
9759 @Override
9760 public boolean getRcsSingleRegistrationTestModeEnabled() {
9761 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9762 "getRcsSingleRegistrationTestModeEnabled");
9763
9764 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9765 }
9766
9767 /**
Hui Wang068ab862020-10-31 05:12:53 +00009768 * Overrides the config of RCS VoLTE single registration enabled for the device.
9769 */
9770 @Override
9771 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9772 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9773 "setDeviceSingleRegistrationEnabledOverride");
9774 enforceModifyPermission();
9775
9776 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9777 : Boolean.parseBoolean(enabledStr);
9778 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009779 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009780 }
9781
9782 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009783 * Sends a device to device communication message. Only usable via shell.
9784 * @param message message to send.
9785 * @param value message value.
9786 */
9787 @Override
9788 public void sendDeviceToDeviceMessage(int message, int value) {
9789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9790 "setCarrierSingleRegistrationEnabledOverride");
9791 enforceModifyPermission();
9792
9793 final long identity = Binder.clearCallingIdentity();
9794 try {
9795 TelephonyConnectionService service =
9796 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9797 if (service == null) {
9798 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9799 return;
9800 }
9801 service.sendTestDeviceToDeviceMessage(message, value);
9802 } finally {
9803 Binder.restoreCallingIdentity(identity);
9804 }
9805 }
9806
9807
9808 /**
Hui Wang068ab862020-10-31 05:12:53 +00009809 * Gets the config of RCS VoLTE single registration enabled for the device.
9810 */
9811 @Override
9812 public boolean getDeviceSingleRegistrationEnabled() {
9813 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9814 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9815 }
9816
9817 /**
9818 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9819 */
9820 @Override
9821 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9822 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9823 "setCarrierSingleRegistrationEnabledOverride");
9824 enforceModifyPermission();
9825
9826 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9827 : Boolean.parseBoolean(enabledStr);
9828 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9829 subId, enabled);
9830 }
9831
9832 /**
9833 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9834 */
9835 @Override
9836 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9837 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9838 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9839 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009840
9841 /**
9842 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9843 * their mobile plan.
9844 */
9845 @Override
9846 public String getMobileProvisioningUrl() {
9847 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9848 final long identity = Binder.clearCallingIdentity();
9849 try {
9850 return getDefaultPhone().getMobileProvisioningUrl();
9851 } finally {
9852 Binder.restoreCallingIdentity(identity);
9853 }
9854 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009855
James.cf Linbcdf8b32021-01-14 16:44:13 +08009856 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009857 * Get the EAB contact from the EAB database.
9858 */
9859 @Override
9860 public String getContactFromEab(String contact) {
9861 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9862 enforceModifyPermission();
9863 final long identity = Binder.clearCallingIdentity();
9864 try {
9865 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9866 } finally {
9867 Binder.restoreCallingIdentity(identity);
9868 }
9869 }
9870
9871 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009872 * Remove the EAB contacts from the EAB database.
9873 */
9874 @Override
9875 public int removeContactFromEab(int subId, String contacts) {
9876 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9877 enforceModifyPermission();
9878 final long identity = Binder.clearCallingIdentity();
9879 try {
9880 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9881 } finally {
9882 Binder.restoreCallingIdentity(identity);
9883 }
9884 }
9885
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009886 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009887 public boolean getDeviceUceEnabled() {
9888 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9889 final long identity = Binder.clearCallingIdentity();
9890 try {
9891 return mApp.getDeviceUceEnabled();
9892 } finally {
9893 Binder.restoreCallingIdentity(identity);
9894 }
9895 }
9896
9897 @Override
9898 public void setDeviceUceEnabled(boolean isEnabled) {
9899 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9900 final long identity = Binder.clearCallingIdentity();
9901 try {
9902 mApp.setDeviceUceEnabled(isEnabled);
9903 } finally {
9904 Binder.restoreCallingIdentity(identity);
9905 }
9906 }
9907
9908 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009909 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9910 String callingPackage) {
9911 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9912 mApp, subId, "setSignalStrengthUpdateRequest");
9913
9914 final int callingUid = Binder.getCallingUid();
9915 // Verify that tha callingPackage belongs to the calling UID
9916 mApp.getSystemService(AppOpsManager.class)
9917 .checkPackage(callingUid, callingPackage);
9918
9919 validateSignalStrengthUpdateRequest(request, callingUid);
9920
9921 final long identity = Binder.clearCallingIdentity();
9922 try {
9923 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9924 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9925
9926 if (result instanceof IllegalStateException) {
9927 throw (IllegalStateException) result;
9928 }
9929 } finally {
9930 Binder.restoreCallingIdentity(identity);
9931 }
9932 }
9933
9934 @Override
9935 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9936 String callingPackage) {
9937 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9938 mApp, subId, "clearSignalStrengthUpdateRequest");
9939
9940 final int callingUid = Binder.getCallingUid();
9941 // Verify that tha callingPackage belongs to the calling UID
9942 mApp.getSystemService(AppOpsManager.class)
9943 .checkPackage(callingUid, callingPackage);
9944
9945 final long identity = Binder.clearCallingIdentity();
9946 try {
9947 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9948 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9949
9950 if (result instanceof IllegalStateException) {
9951 throw (IllegalStateException) result;
9952 }
9953 } finally {
9954 Binder.restoreCallingIdentity(identity);
9955 }
9956 }
9957
9958 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9959 int callingUid) {
9960 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9961 // phone/system process do not have further restriction on request
9962 return;
9963 }
9964
9965 // Applications has restrictions on how to use the request:
9966 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9967 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9968 // This is not system caller which has been checked above
9969 throw new IllegalArgumentException(
9970 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9971 }
9972
9973 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9974 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9975 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9976 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9977 || info.isEnabled()) {
9978 throw new IllegalArgumentException(
9979 "Only system can set hide fields in SignalThresholdInfo");
9980 }
9981
9982 // Thresholds length for each RAN need in range. This has been validated in
9983 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9984 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9985 final int[] thresholds = info.getThresholds();
9986 Objects.requireNonNull(thresholds);
9987 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9988 || thresholds.length
9989 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9990 throw new IllegalArgumentException(
9991 "thresholds length is out of range: " + thresholds.length);
9992 }
9993 }
9994 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009995
9996 /**
9997 * Prepare TelephonyManager for an unattended reboot. The reboot is
9998 * required to be done shortly after the API is invoked.
9999 */
10000 @Override
10001 @TelephonyManager.PrepareUnattendedRebootResult
10002 public int prepareForUnattendedReboot() {
10003 enforceRebootPermission();
10004
10005 final long identity = Binder.clearCallingIdentity();
10006 try {
10007 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
10008 } finally {
10009 Binder.restoreCallingIdentity(identity);
10010 }
10011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010012}