blob: 38d3299693c0fcda09da7495c5357fb82734daf2 [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");
6079 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6080 final long identity = Binder.clearCallingIdentity();
6081 try {
6082 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6083 nrDualConnectivityState, subId,
6084 workSource);
6085 if (DBG) log("enableNRDualConnectivity result: " + result);
6086 return result;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
6089 }
6090 }
6091
6092 /**
6093 * Is E-UTRA-NR Dual Connectivity enabled
6094 * @return true if dual connectivity is enabled else false
6095 */
6096 @Override
6097 public boolean isNrDualConnectivityEnabled(int subId) {
6098 TelephonyPermissions
6099 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6100 mApp, subId, "isNRDualConnectivityEnabled");
6101 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6102 final long identity = Binder.clearCallingIdentity();
6103 try {
6104 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6105 null, subId, workSource);
6106 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6107 return isEnabled;
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
6110 }
6111 }
6112
6113 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006114 * get carrier bandwidth per primary and secondary carrier
6115 * @param subId subscription id of the sim card
6116 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6117 */
6118 @Override
6119 public CarrierBandwidth getCarrierBandwidth(int subId) {
6120 TelephonyPermissions
6121 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6122 mApp, subId, "isNRDualConnectivityEnabled");
6123 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6124 final long identity = Binder.clearCallingIdentity();
6125 try {
6126 CarrierBandwidth carrierBandwidth =
6127 getPhoneFromSubId(subId).getCarrierBandwidth();
6128 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6129 return carrierBandwidth;
6130 } finally {
6131 Binder.restoreCallingIdentity(identity);
6132 }
6133 }
6134
6135 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006136 * Set the allowed network types of the device and
6137 * provide the reason triggering the allowed network change.
6138 *
6139 * @param subId the id of the subscription.
6140 * @param reason the reason the allowed network type change is taking place
6141 * @param allowedNetworkTypes the allowed network types.
6142 * @return true on success; false on any failure.
6143 */
6144 @Override
6145 public boolean setAllowedNetworkTypesForReason(int subId,
SongFerngWang9e060372020-12-21 16:41:52 +08006146 @TelephonyManager.AllowedNetworkTypesReason int reason,
6147 @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) {
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6149 mApp, subId, "setAllowedNetworkTypesForReason");
SongFerngWang9e060372020-12-21 16:41:52 +08006150 if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) {
6151 Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason);
6152 return false;
6153 }
6154
6155 if (DBG) {
6156 log("setAllowedNetworkTypesForReason: " + reason
6157 + " value: " + allowedNetworkTypes);
6158 }
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006159 final long identity = Binder.clearCallingIdentity();
6160 try {
SongFerngWang9e060372020-12-21 16:41:52 +08006161 Boolean success = (Boolean) sendRequest(
6162 CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON,
6163 new Pair<Integer, Long>(reason, allowedNetworkTypes), subId);
6164
6165 if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail"));
6166 return success;
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006167 } finally {
6168 Binder.restoreCallingIdentity(identity);
6169 }
6170 }
6171
6172 /**
Miaoa84611c2019-03-15 09:21:10 +08006173 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006174 *
Miaoa84611c2019-03-15 09:21:10 +08006175 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006176 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006177 * @hide
6178 */
6179 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006180 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006183 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184 try {
Miaoa84611c2019-03-15 09:21:10 +08006185 if (phone != null) {
6186 return phone.hasMatchedTetherApnSetting();
6187 } else {
6188 return false;
6189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190 } finally {
6191 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006192 }
Junda Liu475951f2014-11-07 16:45:03 -08006193 }
6194
6195 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006196 * Enable or disable always reporting signal strength changes from radio.
6197 *
6198 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6199 */
6200 @Override
6201 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6202 enforceModifyPermission();
6203 enforceSystemCaller();
6204
6205 final long identity = Binder.clearCallingIdentity();
6206 final Phone phone = getPhone(subId);
6207 try {
6208 if (phone != null) {
6209 if (DBG) {
6210 log("setAlwaysReportSignalStrength: subId=" + subId
6211 + " isEnable=" + isEnable);
6212 }
6213 phone.setAlwaysReportSignalStrength(isEnable);
6214 } else {
6215 loge("setAlwaysReportSignalStrength: no phone found for subId="
6216 + subId);
6217 }
6218 } finally {
6219 Binder.restoreCallingIdentity(identity);
6220 }
6221 }
6222
6223 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006224 * Get the user enabled state of Mobile Data.
6225 *
6226 * TODO: remove and use isUserDataEnabled.
6227 * This can't be removed now because some vendor codes
6228 * calls through ITelephony directly while they should
6229 * use TelephonyManager.
6230 *
6231 * @return true on enabled
6232 */
6233 @Override
6234 public boolean getDataEnabled(int subId) {
6235 return isUserDataEnabled(subId);
6236 }
6237
6238 /**
6239 * Get whether mobile data is enabled per user setting.
6240 *
6241 * There are other factors deciding whether mobile data is actually enabled, but they are
6242 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006243 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006244 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006245 *
6246 * @return {@code true} if data is enabled else {@code false}
6247 */
6248 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006249 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006250 try {
6251 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6252 null);
6253 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006254 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6255 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006257
6258 final long identity = Binder.clearCallingIdentity();
6259 try {
6260 int phoneId = mSubscriptionController.getPhoneId(subId);
6261 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6262 Phone phone = PhoneFactory.getPhone(phoneId);
6263 if (phone != null) {
6264 boolean retVal = phone.isUserDataEnabled();
6265 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6266 return retVal;
6267 } else {
6268 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6269 return false;
6270 }
6271 } finally {
6272 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006273 }
6274 }
6275
6276 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006277 * Checks if the device is capable of mobile data by considering whether whether the
6278 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6279 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006280 *
Shuo Qian985d1232020-01-08 14:30:06 -08006281 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006282 */
6283 @Override
6284 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006285 try {
6286 try {
6287 mApp.enforceCallingOrSelfPermission(
6288 android.Manifest.permission.ACCESS_NETWORK_STATE,
6289 null);
6290 } catch (Exception e) {
6291 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6292 "isDataEnabled");
6293 }
6294 } catch (Exception e) {
6295 enforceReadPrivilegedPermission("isDataEnabled");
6296 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006297
6298 final long identity = Binder.clearCallingIdentity();
6299 try {
6300 int phoneId = mSubscriptionController.getPhoneId(subId);
6301 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6302 Phone phone = PhoneFactory.getPhone(phoneId);
6303 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006304 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006305 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6306 return retVal;
6307 } else {
6308 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6309 return false;
6310 }
6311 } finally {
6312 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006313 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006314 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006315
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006316 /**
6317 * Check if data is enabled for a specific reason
6318 * @param subId Subscription index
6319 * @param reason the reason the data enable change is taking place
6320 * @return {@code true} if the overall data is enabled; {@code false} if not.
6321 */
6322 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006323 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006324 @TelephonyManager.DataEnabledReason int reason) {
6325 try {
6326 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6327 null);
6328 } catch (Exception e) {
6329 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006330 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006331 }
6332
6333
6334 final long identity = Binder.clearCallingIdentity();
6335 try {
6336 int phoneId = mSubscriptionController.getPhoneId(subId);
6337 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006338 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006339 + " reason=" + reason);
6340 }
6341 Phone phone = PhoneFactory.getPhone(phoneId);
6342 if (phone != null) {
6343 boolean retVal;
6344 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6345 retVal = phone.isUserDataEnabled();
6346 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006347 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006348 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006349 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006350 return retVal;
6351 } else {
6352 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006353 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006354 + subId + " retVal=false");
6355 }
6356 return false;
6357 }
6358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
6361 }
6362
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006363 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006364 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006365 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6366 // Skip the check if it's one of these special uids
6367 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6368 }
6369
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006370 //load access rules from carrier configs, and check those as well: b/139133814
6371 SubscriptionController subController = SubscriptionController.getInstance();
6372 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6373 || subController == null) return privilegeFromSim;
6374
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006375 PackageManager pkgMgr = phone.getContext().getPackageManager();
6376 String[] packages = pkgMgr.getPackagesForUid(uid);
6377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006380 int subId = phone.getSubId();
6381 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6382 // A test override is in place for the privileges for this subId, so don't try to
6383 // read the subscription privileges.
6384 return privilegeFromSim;
6385 }
6386 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006387 SubscriptionManager subManager = (SubscriptionManager)
6388 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6389 for (String pkg : packages) {
6390 if (subManager.canManageSubscription(subInfo, pkg)) {
6391 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6392 }
6393 }
6394 return privilegeFromSim;
6395 } finally {
6396 Binder.restoreCallingIdentity(identity);
6397 }
6398 }
6399
6400 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6401 String pkgName) {
6402 //load access rules from carrier configs, and check those as well: b/139133814
6403 SubscriptionController subController = SubscriptionController.getInstance();
6404 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6405 || subController == null) return privilegeFromSim;
6406
6407 final long identity = Binder.clearCallingIdentity();
6408 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006409 int subId = phone.getSubId();
6410 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6411 // A test override is in place for the privileges for this subId, so don't try to
6412 // read the subscription privileges.
6413 return privilegeFromSim;
6414 }
6415 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006416 SubscriptionManager subManager = (SubscriptionManager)
6417 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6418 return subManager.canManageSubscription(subInfo, pkgName)
6419 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
6423 }
6424
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006425 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006426 public int getCarrierPrivilegeStatus(int subId) {
6427 final Phone phone = getPhone(subId);
6428 if (phone == null) {
6429 loge("getCarrierPrivilegeStatus: Invalid subId");
6430 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6431 }
6432 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006433 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006434 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006435 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6436 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006437
6438 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6439 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006440 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006441 }
Junda Liu29340342014-07-10 15:23:27 -07006442
6443 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006444 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006445 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006446 final Phone phone = getPhone(subId);
6447 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006448 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006449 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6450 }
6451 UiccProfile profile =
6452 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6453 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006454 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006455 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6456 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006457 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006458 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006459 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006460 }
6461
6462 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006463 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6464 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006465 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006466 }
6467
6468 int phoneId = SubscriptionManager.getPhoneId(subId);
6469 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006470 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006471 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006472 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6473 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006474 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6475 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6476 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006477 }
6478
6479 @Override
6480 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006481 if (TextUtils.isEmpty(pkgName))
6482 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006483 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6484 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6485 UiccCard card = UiccController.getInstance().getUiccCard(i);
6486 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006487 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006488 continue;
6489 }
6490
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006491 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6492 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6493 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006494 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6495 break;
6496 }
6497 }
6498
6499 return result;
Junda Liu29340342014-07-10 15:23:27 -07006500 }
Derek Tan89e89d42014-07-08 17:00:10 -07006501
6502 @Override
Junda Liue64de782015-04-16 17:19:16 -07006503 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6504 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6505 loge("phoneId " + phoneId + " is not valid.");
6506 return null;
6507 }
6508 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006509 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006510 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006511 return null ;
6512 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006513 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006514 }
6515
Amith Yamasani6e118872016-02-19 12:53:51 -08006516 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006517 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006518 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006519 List<String> privilegedPackages = new ArrayList<>();
6520 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006521 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6522 // has UICC in that slot.
6523 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006524 if (card.hasCarrierPrivilegeRules()) {
6525 if (packages == null) {
6526 // Only check packages in user 0 for now
6527 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006528 PackageManager.MATCH_DISABLED_COMPONENTS
6529 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006530 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006531 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006532 }
6533 for (int p = packages.size() - 1; p >= 0; p--) {
6534 PackageInfo pkgInfo = packages.get(p);
6535 if (pkgInfo != null && pkgInfo.packageName != null
6536 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006537 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006538 privilegedPackages.add(pkgInfo.packageName);
6539 }
6540 }
6541 }
6542 }
6543 return privilegedPackages;
6544 }
6545
chen xuf7e9fe82019-05-09 19:31:02 -07006546 @Override
6547 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006548 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6549
6550 final long identity = Binder.clearCallingIdentity();
6551
chen xuf7e9fe82019-05-09 19:31:02 -07006552 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006553 try {
6554 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6555 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6556 }
6557 } finally {
6558 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006559 }
6560 return privilegedPackages;
6561 }
6562
Wink Savilleb564aae2014-10-23 10:18:09 -07006563 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006564 final Phone phone = getPhone(subId);
6565 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006566 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006567 return null;
6568 }
6569 String iccId = card.getIccId();
6570 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006571 return null;
6572 }
6573 return iccId;
6574 }
6575
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006576 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006577 public void setCallComposerStatus(int subId, int status) {
6578 enforceModifyPermission();
6579
6580 final long identity = Binder.clearCallingIdentity();
6581 try {
6582 Phone phone = getPhone(subId);
6583 if (phone != null) {
6584 Phone defaultPhone = phone.getImsPhone();
6585 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6586 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6587 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006588 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6589 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006590 }
6591 }
Shuo Qiand8782462020-12-22 19:10:14 -08006592 } catch (ImsException e) {
6593 throw new ServiceSpecificException(e.getCode());
6594 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006595 Binder.restoreCallingIdentity(identity);
6596 }
6597 }
6598
6599 @Override
6600 public int getCallComposerStatus(int subId) {
6601 enforceReadPrivilegedPermission("getCallComposerStatus");
6602
6603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 Phone phone = getPhone(subId);
6606 if (phone != null) {
6607 Phone defaultPhone = phone.getImsPhone();
6608 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6609 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6610 return imsPhone.getCallComposerStatus();
6611 }
6612 }
6613 } finally {
6614 Binder.restoreCallingIdentity(identity);
6615 }
6616 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6617 }
6618
6619 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006620 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6621 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006622 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006623 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006625 final long identity = Binder.clearCallingIdentity();
6626 try {
6627 final String iccId = getIccId(subId);
6628 final Phone phone = getPhone(subId);
6629 if (phone == null) {
6630 return false;
6631 }
6632 final String subscriberId = phone.getSubscriberId();
6633
6634 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006635 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006636 + subscriberId + " to " + number);
6637 }
6638
6639 if (TextUtils.isEmpty(iccId)) {
6640 return false;
6641 }
6642
6643 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6644
6645 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6646 if (alphaTag == null) {
6647 editor.remove(alphaTagPrefKey);
6648 } else {
6649 editor.putString(alphaTagPrefKey, alphaTag);
6650 }
6651
6652 // Record both the line number and IMSI for this ICCID, since we need to
6653 // track all merged IMSIs based on line number
6654 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6655 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6656 if (number == null) {
6657 editor.remove(numberPrefKey);
6658 editor.remove(subscriberPrefKey);
6659 } else {
6660 editor.putString(numberPrefKey, number);
6661 editor.putString(subscriberPrefKey, subscriberId);
6662 }
6663
6664 editor.commit();
6665 return true;
6666 } finally {
6667 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006668 }
Derek Tan7226c842014-07-02 17:42:23 -07006669 }
6670
6671 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006672 public String getLine1NumberForDisplay(int subId, String callingPackage,
6673 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006674 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006675 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006676 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006677 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006678 return null;
6679 }
Derek Tan97ebb422014-09-05 16:55:38 -07006680
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006681 final long identity = Binder.clearCallingIdentity();
6682 try {
6683 String iccId = getIccId(subId);
6684 if (iccId != null) {
6685 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6686 if (DBG_MERGE) {
6687 log("getLine1NumberForDisplay returning "
6688 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6689 }
6690 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006691 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006692 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6693 return null;
6694 } finally {
6695 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006696 }
Derek Tan7226c842014-07-02 17:42:23 -07006697 }
6698
6699 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006700 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6701 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006702 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006703 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006704 return null;
6705 }
Derek Tan97ebb422014-09-05 16:55:38 -07006706
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006707 final long identity = Binder.clearCallingIdentity();
6708 try {
6709 String iccId = getIccId(subId);
6710 if (iccId != null) {
6711 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6712 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6713 }
6714 return null;
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006717 }
Derek Tan7226c842014-07-02 17:42:23 -07006718 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006719
6720 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006721 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6722 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006723 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6724 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006725 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006726 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006727 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006728 return null;
6729 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006730
Jordan Liub49b04b2019-05-06 14:45:15 -07006731 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6732 // the process, where TelephonyManager was instantiated.
6733 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006734 final long identity = Binder.clearCallingIdentity();
6735 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006736 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006737 final TelephonyManager tele = TelephonyManager.from(context);
6738 final SubscriptionManager sub = SubscriptionManager.from(context);
6739
6740 // Figure out what subscribers are currently active
6741 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006742
Jordan Liub49b04b2019-05-06 14:45:15 -07006743 // Only consider subs which match the current subId
6744 // This logic can be simplified. See b/131189269 for progress.
6745 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006746 activeSubscriberIds.add(tele.getSubscriberId(subId));
6747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748
6749 // First pass, find a number override for an active subscriber
6750 String mergeNumber = null;
6751 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6752 for (String key : prefs.keySet()) {
6753 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6754 final String subscriberId = (String) prefs.get(key);
6755 if (activeSubscriberIds.contains(subscriberId)) {
6756 final String iccId = key.substring(
6757 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6758 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6759 mergeNumber = (String) prefs.get(numberKey);
6760 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006761 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006762 + " for active subscriber " + subscriberId);
6763 }
6764 if (!TextUtils.isEmpty(mergeNumber)) {
6765 break;
6766 }
6767 }
6768 }
6769 }
6770
6771 // Shortcut when no active merged subscribers
6772 if (TextUtils.isEmpty(mergeNumber)) {
6773 return null;
6774 }
6775
6776 // Second pass, find all subscribers under that line override
6777 final ArraySet<String> result = new ArraySet<>();
6778 for (String key : prefs.keySet()) {
6779 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6780 final String number = (String) prefs.get(key);
6781 if (mergeNumber.equals(number)) {
6782 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6783 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6784 final String subscriberId = (String) prefs.get(subscriberKey);
6785 if (!TextUtils.isEmpty(subscriberId)) {
6786 result.add(subscriberId);
6787 }
6788 }
6789 }
6790 }
6791
6792 final String[] resultArray = result.toArray(new String[result.size()]);
6793 Arrays.sort(resultArray);
6794 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006795 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6797 }
6798 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006799 } finally {
6800 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006801 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006802 }
6803
6804 @Override
zoey chen38003472019-12-13 17:16:31 +08006805 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6806 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006807
6808 final long identity = Binder.clearCallingIdentity();
6809 try {
6810 final TelephonyManager telephonyManager = mApp.getSystemService(
6811 TelephonyManager.class);
6812 String subscriberId = telephonyManager.getSubscriberId(subId);
6813 if (subscriberId == null) {
6814 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006815 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006816 + subId);
6817 }
6818 return null;
6819 }
6820
6821 final SubscriptionInfo info = SubscriptionController.getInstance()
6822 .getSubscriptionInfo(subId);
6823 final ParcelUuid groupUuid = info.getGroupUuid();
6824 // If it doesn't belong to any group, return just subscriberId of itself.
6825 if (groupUuid == null) {
6826 return new String[]{subscriberId};
6827 }
6828
6829 // Get all subscriberIds from the group.
6830 final List<String> mergedSubscriberIds = new ArrayList<>();
6831 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006832 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006833 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006834 for (SubscriptionInfo subInfo : groupInfos) {
6835 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6836 if (subscriberId != null) {
6837 mergedSubscriberIds.add(subscriberId);
6838 }
6839 }
6840
6841 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6842 } finally {
6843 Binder.restoreCallingIdentity(identity);
6844
6845 }
6846 }
6847
6848 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006849 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006850 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006851 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852
6853 final long identity = Binder.clearCallingIdentity();
6854 try {
6855 final Phone phone = getPhone(subId);
6856 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6857 } finally {
6858 Binder.restoreCallingIdentity(identity);
6859 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006860 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006861
6862 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006863 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006864 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6865 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006866 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6867 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868
6869 final long identity = Binder.clearCallingIdentity();
6870 try {
6871 final Phone phone = getPhone(subId);
6872 if (phone == null) {
6873 return false;
6874 }
6875 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6876 cdmaNonRoamingList);
6877 } finally {
6878 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006879 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006880 }
6881
6882 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006883 @Deprecated
6884 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6885 enforceModifyPermission();
6886
6887 int returnValue = 0;
6888 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006889 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006890 if(result.exception == null) {
6891 if (result.result != null) {
6892 byte[] responseData = (byte[])(result.result);
6893 if(responseData.length > oemResp.length) {
6894 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6895 responseData.length + "bytes. Buffer Size is " +
6896 oemResp.length + "bytes.");
6897 }
6898 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6899 returnValue = responseData.length;
6900 }
6901 } else {
6902 CommandException ex = (CommandException) result.exception;
6903 returnValue = ex.getCommandError().ordinal();
6904 if(returnValue > 0) returnValue *= -1;
6905 }
6906 } catch (RuntimeException e) {
6907 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6908 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6909 if(returnValue > 0) returnValue *= -1;
6910 }
6911
6912 return returnValue;
6913 }
6914
6915 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006916 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006917 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006918 try {
6919 TelephonyPermissions
6920 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6921 mApp, phone.getSubId(), "getRadioAccessFamily");
6922 } catch (SecurityException e) {
6923 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6924 throw e;
6925 }
chen xub97461a2018-10-26 14:17:57 -07006926 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006927 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006928 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006929 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006930 final long identity = Binder.clearCallingIdentity();
6931 try {
chen xub97461a2018-10-26 14:17:57 -07006932 TelephonyPermissions
6933 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6934 mApp, phone.getSubId(), "getRadioAccessFamily");
6935 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006936 } finally {
6937 Binder.restoreCallingIdentity(identity);
6938 }
chen xub97461a2018-10-26 14:17:57 -07006939 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006940 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006941
6942 @Override
6943 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006945 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946
6947 final long identity = Binder.clearCallingIdentity();
6948 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006949 ImsManager.getInstance(defaultPhone.getContext(),
6950 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006954 }
6955
6956 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006957 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006958 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006959 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6960 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006961 return false;
6962 }
Svet Ganovb320e182015-04-16 12:30:10 -07006963
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006964 final long identity = Binder.clearCallingIdentity();
6965 try {
6966 // Check the user preference and the system-level IMS setting. Even if the user has
6967 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6968 // In the long run, we may instead need to check if there exists a connection service
6969 // which can support video calling.
6970 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006971 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006972 return imsManager.isVtEnabledByPlatform()
6973 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6974 && imsManager.isVtEnabledByUser();
6975 } finally {
6976 Binder.restoreCallingIdentity(identity);
6977 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006978 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006979
Andrew Leea1239f22015-03-02 17:44:07 -08006980 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006981 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6982 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006983 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006984 mApp, subId, callingPackage, callingFeatureId,
6985 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006986 return false;
6987 }
6988
6989 final long identity = Binder.clearCallingIdentity();
6990 try {
6991 CarrierConfigManager configManager =
6992 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006993 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006994 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
6997 }
Andrew Leea1239f22015-03-02 17:44:07 -08006998 }
6999
7000 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007001 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007003 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007004 return false;
7005 }
7006
7007 final long identity = Binder.clearCallingIdentity();
7008 try {
7009 CarrierConfigManager configManager =
7010 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007011 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007012 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
7015 }
Andrew Leea1239f22015-03-02 17:44:07 -08007016 }
7017
Andrew Lee9431b832015-03-09 18:46:45 -07007018 @Override
7019 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007020 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007021 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007022 }
7023
7024 @Override
7025 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007026 final long identity = Binder.clearCallingIdentity();
7027 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007028 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007029 } finally {
7030 Binder.restoreCallingIdentity(identity);
7031 }
Andrew Lee9431b832015-03-09 18:46:45 -07007032 }
7033
Hall Liuf6668912018-10-31 17:05:23 -07007034 /**
7035 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7036 * support for the feature and device firmware support.
7037 *
7038 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7039 */
7040 @Override
7041 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007042 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007043 final Phone phone = getPhone(subscriptionId);
7044 if (phone == null) {
7045 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7046 return false;
7047 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007048 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007049 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007050 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7051 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007052 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007053 return isCarrierSupported && isDeviceSupported;
7054 } finally {
7055 Binder.restoreCallingIdentity(identity);
7056 }
Hall Liu98187582018-01-22 19:15:32 -08007057 }
7058
Hall Liuf6668912018-10-31 17:05:23 -07007059 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007060 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7061 * RTT setting, will return true if the device and carrier both support RTT.
7062 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007063 */
7064 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065 final long identity = Binder.clearCallingIdentity();
7066 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007067 boolean isRttSupported = isRttSupported(subscriptionId);
7068 boolean isUserRttSettingOn = Settings.Secure.getInt(
7069 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7070 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7071 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7072 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 } finally {
7074 Binder.restoreCallingIdentity(identity);
7075 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007076 }
7077
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007078 @Deprecated
7079 @Override
7080 public String getDeviceId(String callingPackage) {
7081 return getDeviceIdWithFeature(callingPackage, null);
7082 }
7083
Sanket Padawe7310cc72015-01-14 09:53:20 -08007084 /**
7085 * Returns the unique device ID of phone, for example, the IMEI for
7086 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7087 *
7088 * <p>Requires Permission:
7089 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7090 */
7091 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007092 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007093 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007094 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007095 return null;
7096 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007097 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007098 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007099 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007100 return null;
7101 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007102
7103 final long identity = Binder.clearCallingIdentity();
7104 try {
7105 return phone.getDeviceId();
7106 } finally {
7107 Binder.restoreCallingIdentity(identity);
7108 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007109 }
7110
Ping Sunc67b7c22016-03-02 19:16:45 +08007111 /**
7112 * {@hide}
7113 * Returns the IMS Registration Status on a particular subid
7114 *
7115 * @param subId
7116 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007117 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007118 Phone phone = getPhone(subId);
7119 if (phone != null) {
7120 return phone.isImsRegistered();
7121 } else {
7122 return false;
7123 }
7124 }
7125
Santos Cordon7a1885b2015-02-03 11:15:19 -08007126 @Override
7127 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128 final long identity = Binder.clearCallingIdentity();
7129 try {
7130 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
7133 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007134 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007135
Tyler Gunnf70ed162019-04-03 15:28:53 -07007136 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007137 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007138 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007139 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007140 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007141 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7142 }
7143 final long identity = Binder.clearCallingIdentity();
7144 try {
7145 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7146 } finally {
7147 Binder.restoreCallingIdentity(identity);
7148 }
7149 }
7150
7151 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007152 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007153 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7154 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007155 final long identity = Binder.clearCallingIdentity();
7156 try {
7157 Phone phone = getPhone(subscriptionId);
7158 if (phone == null) {
7159 return null;
7160 }
7161 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7162 } finally {
7163 Binder.restoreCallingIdentity(identity);
7164 }
7165 }
7166
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007167 /**
7168 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007169 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007170 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171 final long identity = Binder.clearCallingIdentity();
7172 try {
7173 Phone phone = getPhone(subId);
7174 if (phone != null) {
7175 return phone.isWifiCallingEnabled();
7176 } else {
7177 return false;
7178 }
7179 } finally {
7180 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007181 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007182 }
7183
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007184 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007185 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007186 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007187 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007188 final long identity = Binder.clearCallingIdentity();
7189 try {
7190 Phone phone = getPhone(subId);
7191 if (phone != null) {
7192 return phone.isVideoEnabled();
7193 } else {
7194 return false;
7195 }
7196 } finally {
7197 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007198 }
7199 }
7200
7201 /**
7202 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7203 * defined in {@link ImsRegistrationImplBase}.
7204 */
7205 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206 final long identity = Binder.clearCallingIdentity();
7207 try {
7208 Phone phone = getPhone(subId);
7209 if (phone != null) {
7210 return phone.getImsRegistrationTech();
7211 } else {
7212 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7213 }
7214 } finally {
7215 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007216 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007217 }
7218
Stuart Scott8eef64f2015-04-08 15:13:54 -07007219 @Override
7220 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007221 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007222 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7223 return;
7224 }
7225
Svet Ganovcc087f82015-05-12 20:35:54 -07007226 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007227
Svet Ganovcc087f82015-05-12 20:35:54 -07007228 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007229 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7230 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007231 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007232 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007233 setNetworkSelectionModeAutomatic(subId);
SongFerngWang9e060372020-12-21 16:41:52 +08007234 setAllowedNetworkTypesForReason(subId,
7235 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER,
7236 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7237 setAllowedNetworkTypesForReason(subId,
7238 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER,
7239 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
7240 setAllowedNetworkTypesForReason(subId,
7241 TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER,
7242 RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId)));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007243 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7244 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007245 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007246 // There has been issues when Sms raw table somehow stores orphan
7247 // fragments. They lead to garbled message when new fragments come
7248 // in and combined with those stale ones. In case this happens again,
7249 // user can reset all network settings which will clean up this table.
7250 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007251 // Clean up IMS settings as well here.
7252 int slotId = getSlotIndex(subId);
7253 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7254 ImsManager.getInstance(mApp, slotId).factoryReset();
7255 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007256
7257 // Erase modem config if erase modem on network setting is enabled.
7258 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7259 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7260 if (configValue != null && Boolean.parseBoolean(configValue)) {
7261 sendEraseModemConfig(getDefaultPhone());
7262 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007263 } finally {
7264 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007265 }
7266 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007267
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007268 private void cleanUpSmsRawTable(Context context) {
7269 ContentResolver resolver = context.getContentResolver();
7270 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7271 resolver.delete(uri, null, null);
7272 }
7273
Narayan Kamath1c496c22015-04-16 14:40:19 +01007274 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007275 public String getSimLocaleForSubscriber(int subId) {
7276 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7277 final Phone phone = getPhone(subId);
7278 if (phone == null) {
7279 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007280 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007282 final long identity = Binder.clearCallingIdentity();
7283 try {
chen xu5d3637b2019-01-21 23:31:38 -08007284 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007285 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007286 if (info == null) {
7287 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7288 return null;
7289 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 // Try and fetch the locale from the carrier properties or from the SIM language
7291 // preferences (EF-PL and EF-LI)...
7292 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007293 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007294 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7295 if (localeFromDefaultSim != null) {
7296 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7297 if (DBG) log("Using locale from subId: " + subId + " locale: "
7298 + localeFromDefaultSim);
7299 return localeFromDefaultSim.toLanguageTag();
7300 } else {
7301 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007302 }
7303 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007305 // The SIM language preferences only store a language (e.g. fr = French), not an
7306 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7307 // the SIM and carrier preferences does not include a country we add the country
7308 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007309 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007310 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007311 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 return mccLocale.toLanguageTag();
7313 }
7314
7315 if (DBG) log("No locale found - returning null");
7316 return null;
7317 } finally {
7318 Binder.restoreCallingIdentity(identity);
7319 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007320 }
7321
7322 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007323 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007324 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007325 }
7326
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 /**
7328 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7329 */
7330 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007331 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007332 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007333 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007334
Chenjie Yu1ba97252018-01-11 18:16:20 -08007335 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007336 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007337
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007338 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007339 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7340 * representing the state of the modem.
7341 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007342 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7343 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007344 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007345 */
7346 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007347 public void requestModemActivityInfo(ResultReceiver result) {
7348 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350
7351 final long identity = Binder.clearCallingIdentity();
7352 try {
sqian1a1be542020-03-05 11:37:28 -08007353 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 } finally {
7355 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007356 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007357 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007358
Siddharth Rayb8114062018-06-17 15:02:38 -07007359 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7360 // less than total activity duration.
7361 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7362 if (info == null) {
7363 return false;
7364 }
7365 int activityDurationMs =
7366 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7367 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007368 int[] txTimeMs = info.getTransmitTimeMillis();
7369 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7370 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007371 }
7372 return (info.isValid()
7373 && (info.getSleepTimeMillis() <= activityDurationMs)
7374 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007375 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007376 && (totalTxTimeMs <= activityDurationMs));
7377 }
7378
Jack Yu85bd38a2015-11-09 11:34:32 -08007379 /**
7380 * {@hide}
7381 * Returns the service state information on specified subscription.
7382 */
7383 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007384 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7385 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007387 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007388 return null;
7389 }
7390
Hall Liuf19c44f2018-11-27 14:38:17 -08007391 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7392 LocationAccessPolicy.checkLocationPermission(mApp,
7393 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7394 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007395 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007396 .setCallingPid(Binder.getCallingPid())
7397 .setCallingUid(Binder.getCallingUid())
7398 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007399 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007400 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7401 .build());
7402
7403 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7404 LocationAccessPolicy.checkLocationPermission(mApp,
7405 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7406 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007407 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007408 .setCallingPid(Binder.getCallingPid())
7409 .setCallingUid(Binder.getCallingUid())
7410 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007411 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007412 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7413 .build());
7414 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7415 boolean hasFinePermission =
7416 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7417 boolean hasCoarsePermission =
7418 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7419
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007420 final long identity = Binder.clearCallingIdentity();
7421 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007422 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7423 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7424 Rlog.d(LOG_TAG,
7425 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7426 return null;
7427 }
7428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 final Phone phone = getPhone(subId);
7430 if (phone == null) {
7431 return null;
7432 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007433
Hall Liuf19c44f2018-11-27 14:38:17 -08007434 ServiceState ss = phone.getServiceState();
7435
7436 // Scrub out the location info in ServiceState depending on what level of access
7437 // the caller has.
7438 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007439 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7440 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 } finally {
7442 Binder.restoreCallingIdentity(identity);
7443 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007444 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007445
7446 /**
7447 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7448 *
7449 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7450 * voicemail ringtone.
7451 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7452 * PhoneAccount.
7453 */
7454 @Override
7455 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007456 final long identity = Binder.clearCallingIdentity();
7457 try {
7458 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7459 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007460 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007461 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007462
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7464 } finally {
7465 Binder.restoreCallingIdentity(identity);
7466 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007467 }
7468
7469 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007470 * Sets the per-account voicemail ringtone.
7471 *
7472 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7473 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7474 *
7475 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7476 * voicemail ringtone.
7477 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7478 * PhoneAccount.
7479 */
7480 @Override
7481 public void setVoicemailRingtoneUri(String callingPackage,
7482 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007483 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007484 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007485 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7486 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7488 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7489 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007491
7492 final long identity = Binder.clearCallingIdentity();
7493 try {
7494 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7495 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007496 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007497 }
7498 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7499 } finally {
7500 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007501 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007502 }
7503
7504 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007505 * Returns whether vibration is set for voicemail notification in Phone settings.
7506 *
7507 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7508 * voicemail vibration setting.
7509 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7510 */
7511 @Override
7512 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007513 final long identity = Binder.clearCallingIdentity();
7514 try {
7515 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7516 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007517 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007518 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007519
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007520 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7521 } finally {
7522 Binder.restoreCallingIdentity(identity);
7523 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007524 }
7525
Youhan Wange64578a2016-05-02 15:32:42 -07007526 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007527 * Sets the per-account voicemail vibration.
7528 *
7529 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7530 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7531 *
7532 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7533 * voicemail vibration setting.
7534 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7535 * specific PhoneAccount.
7536 */
7537 @Override
7538 public void setVoicemailVibrationEnabled(String callingPackage,
7539 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007540 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007541 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007542 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7543 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7545 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7546 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007547 }
7548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007549 final long identity = Binder.clearCallingIdentity();
7550 try {
7551 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7552 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007553 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 }
7555 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7556 } finally {
7557 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007558 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007559 }
7560
7561 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007562 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7563 *
7564 * @throws SecurityException if the caller does not have the required permission
7565 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007566 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007567 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007568 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007569 }
7570
7571 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007572 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7573 * permission.
7574 *
7575 * @throws SecurityException if the caller does not have the required permission
7576 */
7577 private void enforceSendSmsPermission() {
7578 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7579 }
7580
7581 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007582 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007583 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007584 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007585 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007586 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007587 final long identity = Binder.clearCallingIdentity();
7588 try {
7589 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007590 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007591 if (componentName == null) {
7592 throw new SecurityException(
7593 "Caller not current active visual voicemail package[null]");
7594 }
7595 String vvmPackage = componentName.getPackageName();
7596 if (!callingPackage.equals(vvmPackage)) {
7597 throw new SecurityException("Caller not current active visual voicemail package["
7598 + vvmPackage + "]");
7599 }
7600 } finally {
7601 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007602 }
7603 }
7604
7605 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007606 * Return the application ID for the app type.
7607 *
7608 * @param subId the subscription ID that this request applies to.
7609 * @param appType the uicc app type.
7610 * @return Application ID for specificied app type, or null if no uicc.
7611 */
7612 @Override
7613 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007614 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007615 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616
7617 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007618 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007619 if (phone == null) {
7620 return null;
7621 }
7622 String aid = null;
7623 try {
7624 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7625 .getApplicationByType(appType).getAid();
7626 } catch (Exception e) {
7627 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7628 }
7629 return aid;
7630 } finally {
7631 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007632 }
Youhan Wange64578a2016-05-02 15:32:42 -07007633 }
7634
Youhan Wang4001d252016-05-11 10:29:41 -07007635 /**
7636 * Return the Electronic Serial Number.
7637 *
7638 * @param subId the subscription ID that this request applies to.
7639 * @return ESN or null if error.
7640 */
7641 @Override
7642 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007643 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007644 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007645
7646 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007647 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 if (phone == null) {
7649 return null;
7650 }
7651 String esn = null;
7652 try {
7653 esn = phone.getEsn();
7654 } catch (Exception e) {
7655 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7656 }
7657 return esn;
7658 } finally {
7659 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007660 }
Youhan Wang4001d252016-05-11 10:29:41 -07007661 }
7662
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007663 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007664 * Return the Preferred Roaming List Version.
7665 *
7666 * @param subId the subscription ID that this request applies to.
7667 * @return PRLVersion or null if error.
7668 */
7669 @Override
7670 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007671 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007672 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007673
7674 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007675 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007676 if (phone == null) {
7677 return null;
7678 }
7679 String cdmaPrlVersion = null;
7680 try {
7681 cdmaPrlVersion = phone.getCdmaPrlVersion();
7682 } catch (Exception e) {
7683 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7684 }
7685 return cdmaPrlVersion;
7686 } finally {
7687 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007688 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007689 }
7690
7691 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007692 * Get snapshot of Telephony histograms
7693 * @return List of Telephony histograms
7694 * @hide
7695 */
7696 @Override
7697 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007698 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7699 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007700
7701 final long identity = Binder.clearCallingIdentity();
7702 try {
7703 return RIL.getTelephonyRILTimingHistograms();
7704 } finally {
7705 Binder.restoreCallingIdentity(identity);
7706 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007707 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007708
7709 /**
7710 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007711 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7712 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007713 * Require system privileges. In the future we may add this to carrier APIs.
7714 *
Michele Berionne482f8202018-11-27 18:57:59 -08007715 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007716 */
7717 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007718 @TelephonyManager.SetCarrierRestrictionResult
7719 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007720 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007722
Michele Berionne482f8202018-11-27 18:57:59 -08007723 if (carrierRestrictionRules == null) {
7724 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007725 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007726
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007727 final long identity = Binder.clearCallingIdentity();
7728 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007729 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007730 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007731 } finally {
7732 Binder.restoreCallingIdentity(identity);
7733 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007734 }
7735
7736 /**
7737 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007738 * Get the allowed carrier list and the excluded carrier list, including the priority between
7739 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007740 * Require system privileges. In the future we may add this to carrier APIs.
7741 *
Michele Berionne482f8202018-11-27 18:57:59 -08007742 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007743 */
7744 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007745 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007746 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007748
7749 final long identity = Binder.clearCallingIdentity();
7750 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007751 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7752 if (response instanceof CarrierRestrictionRules) {
7753 return (CarrierRestrictionRules) response;
7754 }
7755 // Response is an Exception of some kind,
7756 // which is signalled to the user as a NULL retval
7757 return null;
7758 } catch (Exception e) {
7759 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7760 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761 } finally {
7762 Binder.restoreCallingIdentity(identity);
7763 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007764 }
7765
fionaxu59545b42016-05-25 15:53:37 -07007766 /**
fionaxu59545b42016-05-25 15:53:37 -07007767 * Action set from carrier signalling broadcast receivers to enable/disable radio
7768 * @param subId the subscription ID that this action applies to.
7769 * @param enabled control enable or disable radio.
7770 * {@hide}
7771 */
7772 @Override
7773 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7774 enforceModifyPermission();
7775 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007776
7777 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007778 if (phone == null) {
7779 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7780 return;
7781 }
7782 try {
7783 phone.carrierActionSetRadioEnabled(enabled);
7784 } catch (Exception e) {
7785 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786 } finally {
7787 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007788 }
7789 }
7790
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007791 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007792 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7793 * network status based on which carrier apps could apply actions accordingly,
7794 * enable/disable default url handler for example.
7795 *
7796 * @param subId the subscription ID that this action applies to.
7797 * @param report control start/stop reporting the default network status.
7798 * {@hide}
7799 */
7800 @Override
7801 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7802 enforceModifyPermission();
7803 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007804
7805 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007806 if (phone == null) {
7807 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7808 return;
7809 }
7810 try {
7811 phone.carrierActionReportDefaultNetworkStatus(report);
7812 } catch (Exception e) {
7813 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007814 } finally {
7815 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007816 }
7817 }
7818
7819 /**
fionaxud9622282017-07-17 17:51:30 -07007820 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7821 * @param subId the subscription ID that this action applies to.
7822 * {@hide}
7823 */
7824 @Override
7825 public void carrierActionResetAll(int subId) {
7826 enforceModifyPermission();
7827 final Phone phone = getPhone(subId);
7828 if (phone == null) {
7829 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7830 return;
7831 }
7832 try {
7833 phone.carrierActionResetAll();
7834 } catch (Exception e) {
7835 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7836 }
7837 }
7838
7839 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007840 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7841 * bug report is being generated.
7842 */
7843 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007844 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007845 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7846 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007847 writer.println("Permission Denial: can't dump Phone from pid="
7848 + Binder.getCallingPid()
7849 + ", uid=" + Binder.getCallingUid()
7850 + "without permission "
7851 + android.Manifest.permission.DUMP);
7852 return;
7853 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007854 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007855 }
Jack Yueb89b242016-06-22 13:27:47 -07007856
Brad Ebingerdac2f002018-04-03 15:17:52 -07007857 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007858 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7859 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7860 @NonNull String[] args) {
7861 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7862 this, in.getFileDescriptor(), out.getFileDescriptor(),
7863 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007864 }
7865
Jack Yueb89b242016-06-22 13:27:47 -07007866 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007867 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007868 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007869 * @param reason the reason the data enable change is taking place
7870 * @param enabled True if enabling the data, otherwise disabling.
7871 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007872 */
7873 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007874 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007875 boolean enabled) {
7876 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7877 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7878 try {
7879 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007880 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007881 } catch (SecurityException se) {
7882 enforceModifyPermission();
7883 }
7884 } else {
7885 enforceModifyPermission();
7886 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007887
7888 final long identity = Binder.clearCallingIdentity();
7889 try {
7890 Phone phone = getPhone(subId);
7891 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007892 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7893 phone.carrierActionSetMeteredApnsEnabled(enabled);
7894 } else {
7895 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007897 }
7898 } finally {
7899 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007900 }
7901 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007902
7903 /**
7904 * Get Client request stats
7905 * @return List of Client Request Stats
7906 * @hide
7907 */
7908 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007909 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7910 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007912 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007913 return null;
7914 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007915 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007916
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 if (phone != null) {
7920 return phone.getClientRequestStats();
7921 }
7922
7923 return null;
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007927 }
7928
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007929 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007930 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007931 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007932 }
Jack Yueb4124c2017-02-16 15:32:43 -08007933
7934 /**
Grace Chen70990072017-03-24 17:21:30 -07007935 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007936 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007937 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007938 * @param state State of SIM (power down, power up, pass through)
7939 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7940 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7941 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007942 *
7943 **/
7944 @Override
Grace Chen70990072017-03-24 17:21:30 -07007945 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007946 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007947 Phone phone = PhoneFactory.getPhone(slotIndex);
7948
vagdeviaf9a5b92018-08-15 16:01:53 -07007949 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7950
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007951 final long identity = Binder.clearCallingIdentity();
7952 try {
7953 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007954 phone.setSimPowerState(state, null, workSource);
7955 }
7956 } finally {
7957 Binder.restoreCallingIdentity(identity);
7958 }
7959 }
7960
7961 /**
7962 * Set SIM card power state.
7963 *
7964 * @param slotIndex SIM slot id.
7965 * @param state State of SIM (power down, power up, pass through)
7966 * @param callback callback to trigger after success or failure
7967 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7968 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7969 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7970 *
7971 **/
7972 @Override
7973 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7974 IIntegerConsumer callback) {
7975 enforceModifyPermission();
7976 Phone phone = PhoneFactory.getPhone(slotIndex);
7977
7978 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7979
7980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 if (phone != null) {
7983 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7984 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007985 }
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007988 }
7989 }
Shuo Qiandd210312017-04-12 22:11:33 +00007990
Tyler Gunn65d45c22017-06-05 11:22:26 -07007991 private boolean isUssdApiAllowed(int subId) {
7992 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007993 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007994 if (configManager == null) {
7995 return false;
7996 }
7997 PersistableBundle pb = configManager.getConfigForSubId(subId);
7998 if (pb == null) {
7999 return false;
8000 }
8001 return pb.getBoolean(
8002 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8003 }
8004
Shuo Qiandd210312017-04-12 22:11:33 +00008005 /**
8006 * Check if phone is in emergency callback mode
8007 * @return true if phone is in emergency callback mode
8008 * @param subId sub id
8009 */
goneil9c5f4872017-12-05 14:07:56 -08008010 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008011 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008012 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008013 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008014
8015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 if (phone != null) {
8018 return phone.isInEcm();
8019 } else {
8020 return false;
8021 }
8022 } finally {
8023 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008024 }
8025 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008026
8027 /**
8028 * Get the current signal strength information for the given subscription.
8029 * Because this information is not updated when the device is in a low power state
8030 * it should not be relied-upon to be current.
8031 * @param subId Subscription index
8032 * @return the most recent cached signal strength info from the modem
8033 */
8034 @Override
8035 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008036 final long identity = Binder.clearCallingIdentity();
8037 try {
8038 Phone p = getPhone(subId);
8039 if (p == null) {
8040 return null;
8041 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008042
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008043 return p.getSignalStrength();
8044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008047 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008048
Pengquan Meng77b7f132018-08-22 14:49:57 -07008049 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008050 * Get the current modem radio state for the given slot.
8051 * @param slotIndex slot index.
8052 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008053 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008054 * @return the current radio power state from the modem
8055 */
8056 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008057 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008058 Phone phone = PhoneFactory.getPhone(slotIndex);
8059 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008060 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8061 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008062 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8063 }
8064
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
8067 return phone.getRadioPowerState();
8068 } finally {
8069 Binder.restoreCallingIdentity(identity);
8070 }
8071 }
8072 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8073 }
8074
8075 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008076 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8077 *
8078 * <p>Requires one of the following permissions:
8079 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8080 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8081 * privileges.
8082 *
8083 * @param subId subscription id
8084 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8085 * {@code false}.
8086 */
8087 @Override
8088 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008089 try {
8090 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8091 null);
8092 } catch (Exception e) {
8093 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8094 mApp, subId, "isDataRoamingEnabled");
8095 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008096
Pengquan Menga1bb6272018-09-06 09:59:22 -07008097 boolean isEnabled = false;
8098 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008099 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008100 Phone phone = getPhone(subId);
8101 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008102 } finally {
8103 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008104 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008105 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008106 }
8107
8108
8109 /**
8110 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8111 *
8112 * <p> Requires permission:
8113 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8114 * privileges.
8115 *
8116 * @param subId subscription id
8117 * @param isEnabled {@code true} means enable, {@code false} means disable.
8118 */
8119 @Override
8120 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008121 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8122 mApp, subId, "setDataRoamingEnabled");
8123
Pengquan Menga1bb6272018-09-06 09:59:22 -07008124 final long identity = Binder.clearCallingIdentity();
8125 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008126 Phone phone = getPhone(subId);
8127 if (phone != null) {
8128 phone.setDataRoamingEnabled(isEnabled);
8129 }
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008132 }
8133 }
8134
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008135 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008136 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008137 TelephonyPermissions
8138 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008139 mApp, subId, "isManualNetworkSelectionAllowed");
8140
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008141 boolean isAllowed = true;
8142 final long identity = Binder.clearCallingIdentity();
8143 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008144 Phone phone = getPhone(subId);
8145 if (phone != null) {
8146 isAllowed = phone.isCspPlmnEnabled();
8147 }
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 return isAllowed;
8152 }
8153
8154 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008155 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008156 // Verify that tha callingPackage belongs to the calling UID
8157 mApp.getSystemService(AppOpsManager.class)
8158 .checkPackage(Binder.getCallingUid(), callingPackage);
8159
Jordan Liu1e142fc2019-04-22 15:10:43 -07008160 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008161 try {
8162 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008163 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008164 } catch (SecurityException e) {
8165 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8166 // has carrier privileges on an active UICC
8167 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8168 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008169 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008170 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008171 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008172
8173 final long identity = Binder.clearCallingIdentity();
8174 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008175 UiccController uiccController = UiccController.getInstance();
8176 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008177 if (hasReadPermission) {
8178 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008179 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008180
8181 // Remove private info if the caller doesn't have access
8182 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8183 for (UiccCardInfo cardInfo : cardInfos) {
8184 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8185 // is available
8186 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8187 if (card == null || card.getUiccProfile() == null) {
8188 // assume no access if the card or profile is unavailable
8189 filteredInfos.add(cardInfo.getUnprivileged());
8190 continue;
8191 }
8192 UiccProfile profile = card.getUiccProfile();
8193 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8194 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8195 filteredInfos.add(cardInfo);
8196 } else {
8197 filteredInfos.add(cardInfo.getUnprivileged());
8198 }
8199 }
8200 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008201 } finally {
8202 Binder.restoreCallingIdentity(identity);
8203 }
8204 }
8205
8206 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008207 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008208 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008209
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008210 final long identity = Binder.clearCallingIdentity();
8211 try {
8212 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8213 if (slots == null) {
8214 Rlog.i(LOG_TAG, "slots is null.");
8215 return null;
8216 }
8217
8218 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8219 for (int i = 0; i < slots.length; i++) {
8220 UiccSlot slot = slots[i];
8221 if (slot == null) {
8222 continue;
8223 }
8224
Jordan Liu7be7e652019-05-06 18:55:02 +00008225 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008226 UiccCard card = slot.getUiccCard();
8227 if (card != null) {
8228 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008229 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008230 cardId = slot.getEid();
8231 if (TextUtils.isEmpty(cardId)) {
8232 cardId = slot.getIccId();
8233 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008234 }
8235
Jordan Liu857451f2019-05-09 16:35:35 -07008236 if (cardId != null) {
8237 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8238 // if cardId is an EID, it's all digits so this is fine
8239 cardId = IccUtils.stripTrailingFs(cardId);
8240 }
8241
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008242 int cardState = 0;
8243 switch (slot.getCardState()) {
8244 case CARDSTATE_ABSENT:
8245 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8246 break;
8247 case CARDSTATE_PRESENT:
8248 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8249 break;
8250 case CARDSTATE_ERROR:
8251 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8252 break;
8253 case CARDSTATE_RESTRICTED:
8254 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8255 break;
8256 default:
8257 break;
8258
8259 }
8260
8261 infos[i] = new UiccSlotInfo(
8262 slot.isActive(),
8263 slot.isEuicc(),
8264 cardId,
8265 cardState,
8266 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008267 slot.isExtendedApduSupported(),
8268 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008269 }
8270 return infos;
8271 } finally {
8272 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008273 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008274 }
8275
8276 @Override
8277 public boolean switchSlots(int[] physicalSlots) {
8278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008279
8280 final long identity = Binder.clearCallingIdentity();
8281 try {
8282 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008286 }
Jack Yu4c988042018-02-27 15:30:01 -08008287
8288 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008289 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008290 final long identity = Binder.clearCallingIdentity();
8291 try {
8292 return UiccController.getInstance().getCardIdForDefaultEuicc();
8293 } finally {
8294 Binder.restoreCallingIdentity(identity);
8295 }
8296 }
8297
Pengquan Meng85728fb2018-03-12 16:31:21 -07008298 /**
goneil47ffb6e2018-04-06 15:40:58 -07008299 * A test API to reload the UICC profile.
8300 *
8301 * <p>Requires that the calling app has permission
8302 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8303 * @hide
8304 */
8305 @Override
8306 public void refreshUiccProfile(int subId) {
8307 enforceModifyPermission();
8308
8309 final long identity = Binder.clearCallingIdentity();
8310 try {
8311 Phone phone = getPhone(subId);
8312 if (phone == null) {
8313 return;
8314 }
8315 UiccCard uiccCard = phone.getUiccCard();
8316 if (uiccCard == null) {
8317 return;
8318 }
8319 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8320 if (uiccProfile == null) {
8321 return;
8322 }
8323 uiccProfile.refresh();
8324 } finally {
8325 Binder.restoreCallingIdentity(identity);
8326 }
8327 }
8328
8329 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008330 * Returns false if the mobile data is disabled by default, otherwise return true.
8331 */
8332 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008333 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008334 }
8335
8336 /**
8337 * Returns true if the data roaming is enabled by default, i.e the system property
8338 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8339 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8340 */
8341 private boolean getDefaultDataRoamingEnabled(int subId) {
8342 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008343 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008344 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008345 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8346 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8347 return isDataRoamingEnabled;
8348 }
8349
8350 /**
8351 * Returns the default network type for the given {@code subId}, if the default network type is
8352 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8353 */
8354 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008355 List<Integer> list = TelephonyProperties.default_network();
8356 int phoneId = mSubscriptionController.getPhoneId(subId);
8357 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8358 return list.get(phoneId);
8359 }
8360 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008361 }
fionaxua13278b2018-03-21 00:08:13 -07008362
8363 @Override
8364 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008365 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008366 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008367
8368 final long identity = Binder.clearCallingIdentity();
8369 try {
8370 final Phone phone = getPhone(subId);
8371 if (phone == null) {
8372 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8373 return;
8374 }
chen xueaba88a2019-03-15 13:15:10 -07008375 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8376 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008377 if (carrierPrivilegeRules == null) {
8378 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8379 } else {
8380 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008382 } finally {
8383 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008384 }
fionaxua13278b2018-03-21 00:08:13 -07008385 }
8386
8387 @Override
8388 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008389 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008390
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
8393 final Phone phone = getPhone(subId);
8394 if (phone == null) {
8395 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8396 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8397 }
8398 return phone.getCarrierIdListVersion();
8399 } finally {
8400 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008401 }
fionaxua13278b2018-03-21 00:08:13 -07008402 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008403
8404 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008405 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8406 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008407 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008408 mApp, subId, callingPackage, callingFeatureId,
8409 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008410 return -1;
8411 }
8412
8413 final long identity = Binder.clearCallingIdentity();
8414 try {
8415 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
8419 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008420
8421 @Override
8422 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008423 TelephonyPermissions
8424 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008425 mApp, subId, "getCdmaRoamingMode");
8426
8427 final long identity = Binder.clearCallingIdentity();
8428 try {
8429 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8430 } finally {
8431 Binder.restoreCallingIdentity(identity);
8432 }
8433 }
8434
8435 @Override
8436 public boolean setCdmaRoamingMode(int subId, int mode) {
8437 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8438 mApp, subId, "setCdmaRoamingMode");
8439
8440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8443 } finally {
8444 Binder.restoreCallingIdentity(identity);
8445 }
8446 }
8447
8448 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008449 public int getCdmaSubscriptionMode(int subId) {
8450 TelephonyPermissions
8451 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8452 mApp, subId, "getCdmaSubscriptionMode");
8453
8454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8457 } finally {
8458 Binder.restoreCallingIdentity(identity);
8459 }
8460 }
8461
8462 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008463 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8465 mApp, subId, "setCdmaSubscriptionMode");
8466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8470 } finally {
8471 Binder.restoreCallingIdentity(identity);
8472 }
8473 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008474
sqianc5eccab2018-10-19 18:46:41 -07008475 @Override
sqian8c685422019-02-22 15:55:18 -08008476 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008477 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008478 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008479 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8480 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008481 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8482 }
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
sqian854d44b2018-12-12 16:48:18 -08008485 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8486 for (Phone phone: PhoneFactory.getPhones()) {
8487 if (phone.getEmergencyNumberTracker() != null
8488 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8489 emergencyNumberListInternal.put(
8490 phone.getSubId(),
8491 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8492 }
sqian11b7a0e2018-12-05 18:48:28 -08008493 }
sqian854d44b2018-12-12 16:48:18 -08008494 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008495 } finally {
8496 Binder.restoreCallingIdentity(identity);
8497 }
sqianc5eccab2018-10-19 18:46:41 -07008498 }
8499
8500 @Override
sqian8c685422019-02-22 15:55:18 -08008501 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008502 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008503 if (!exactMatch) {
8504 TelephonyPermissions
8505 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008506 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008507 }
8508 final long identity = Binder.clearCallingIdentity();
8509 try {
sqian854d44b2018-12-12 16:48:18 -08008510 for (Phone phone: PhoneFactory.getPhones()) {
8511 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008512 && phone.getEmergencyNumberTracker()
8513 .isEmergencyNumber(number, exactMatch)) {
8514 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008515 }
sqian11b7a0e2018-12-05 18:48:28 -08008516 }
8517 return false;
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
sqianf4ca7ed2019-01-15 18:32:07 -08008523 /**
8524 * Update emergency number list for test mode.
8525 */
8526 @Override
8527 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8528 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8529 "updateEmergencyNumberListTestMode");
8530
8531 final long identity = Binder.clearCallingIdentity();
8532 try {
8533 for (Phone phone: PhoneFactory.getPhones()) {
8534 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8535 if (tracker != null) {
8536 tracker.executeEmergencyNumberTestModeCommand(action, num);
8537 }
8538 }
8539 } finally {
8540 Binder.restoreCallingIdentity(identity);
8541 }
8542 }
8543
8544 /**
8545 * Get the full emergency number list for test mode.
8546 */
8547 @Override
8548 public List<String> getEmergencyNumberListTestMode() {
8549 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8550 "getEmergencyNumberListTestMode");
8551
8552 final long identity = Binder.clearCallingIdentity();
8553 try {
8554 Set<String> emergencyNumbers = new HashSet<>();
8555 for (Phone phone: PhoneFactory.getPhones()) {
8556 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8557 if (tracker != null) {
8558 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8559 emergencyNumbers.add(num.getNumber());
8560 }
8561 }
8562 }
8563 return new ArrayList<>(emergencyNumbers);
8564 } finally {
8565 Binder.restoreCallingIdentity(identity);
8566 }
8567 }
8568
chen xud6b45bd2018-10-30 22:27:10 -07008569 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008570 public int getEmergencyNumberDbVersion(int subId) {
8571 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 final Phone phone = getPhone(subId);
8576 if (phone == null) {
8577 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8578 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8579 }
8580 return phone.getEmergencyNumberDbVersion();
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
8585
8586 @Override
8587 public void notifyOtaEmergencyNumberDbInstalled() {
8588 enforceModifyPermission();
8589
8590 final long identity = Binder.clearCallingIdentity();
8591 try {
8592 for (Phone phone: PhoneFactory.getPhones()) {
8593 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8594 if (tracker != null) {
8595 tracker.updateOtaEmergencyNumberDatabase();
8596 }
8597 }
8598 } finally {
8599 Binder.restoreCallingIdentity(identity);
8600 }
8601 }
8602
8603 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008604 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008605 enforceActiveEmergencySessionPermission();
8606
8607 final long identity = Binder.clearCallingIdentity();
8608 try {
8609 for (Phone phone: PhoneFactory.getPhones()) {
8610 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8611 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008612 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8613 }
8614 }
8615 } finally {
8616 Binder.restoreCallingIdentity(identity);
8617 }
8618 }
8619
8620 @Override
8621 public void resetOtaEmergencyNumberDbFilePath() {
8622 enforceActiveEmergencySessionPermission();
8623
8624 final long identity = Binder.clearCallingIdentity();
8625 try {
8626 for (Phone phone: PhoneFactory.getPhones()) {
8627 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8628 if (tracker != null) {
8629 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008630 }
8631 }
8632 } finally {
8633 Binder.restoreCallingIdentity(identity);
8634 }
8635 }
8636
8637 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008638 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8639 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8640 Phone phone = getPhone(subId);
8641 if (phone == null) {
8642 return null;
8643 }
8644 final long identity = Binder.clearCallingIdentity();
8645 try {
8646 UiccProfile profile = UiccController.getInstance()
8647 .getUiccProfileForPhone(phone.getPhoneId());
8648 if (profile != null) {
8649 return profile.getCertsFromCarrierPrivilegeAccessRules();
8650 }
8651 } finally {
8652 Binder.restoreCallingIdentity(identity);
8653 }
8654 return null;
8655 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008656
8657 /**
8658 * Enable or disable a modem stack.
8659 */
8660 @Override
8661 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8662 enforceModifyPermission();
8663
8664 final long identity = Binder.clearCallingIdentity();
8665 try {
8666 Phone phone = PhoneFactory.getPhone(slotIndex);
8667 if (phone == null) {
8668 return false;
8669 } else {
8670 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8671 }
8672 } finally {
8673 Binder.restoreCallingIdentity(identity);
8674 }
8675 }
Michelecea4cf22018-12-21 15:00:11 -08008676
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008677 /**
8678 * Whether a modem stack is enabled or not.
8679 */
8680 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008681 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8682 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008683 Phone phone = PhoneFactory.getPhone(slotIndex);
8684 if (phone == null) return false;
8685
8686 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008687 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8688 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008689 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8690 }
8691
8692 final long identity = Binder.clearCallingIdentity();
8693 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008694 try {
8695 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8696 } catch (NoSuchElementException ex) {
8697 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8698 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008699 } finally {
8700 Binder.restoreCallingIdentity(identity);
8701 }
8702 }
8703
Michelecea4cf22018-12-21 15:00:11 -08008704 @Override
Michele0ea7d782019-03-19 14:58:42 -07008705 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008706 enforceModifyPermission();
8707
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008711 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008712 .commit();
8713 } finally {
8714 Binder.restoreCallingIdentity(identity);
8715 }
8716 }
8717
8718 @Override
Michele0ea7d782019-03-19 14:58:42 -07008719 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008720 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008721 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008722 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8723 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008724 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008725 }
Michelecea4cf22018-12-21 15:00:11 -08008726
8727 final long identity = Binder.clearCallingIdentity();
8728 try {
Michele0ea7d782019-03-19 14:58:42 -07008729 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008730 } finally {
8731 Binder.restoreCallingIdentity(identity);
8732 }
8733 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008734
Michele0ea7d782019-03-19 14:58:42 -07008735 @TelephonyManager.IsMultiSimSupportedResult
8736 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008737 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8738 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8739 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008740 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8741 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008742 }
8743 // Check if the hardware supports multisim functionality. If usage of multisim is not
8744 // supported by the modem, indicate that it is restricted.
8745 PhoneCapability staticCapability =
8746 mPhoneConfigurationManager.getStaticPhoneCapability();
8747 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008748 loge("isMultiSimSupportedInternal: no static configuration available");
8749 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008750 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008751 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008752 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8753 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008754 }
8755 // Check if support of multiple SIMs is restricted by carrier
8756 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008757 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008758 }
8759
Michele0ea7d782019-03-19 14:58:42 -07008760 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008761 }
8762
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008763 /**
8764 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008765 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8766 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8767 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008768 * @param numOfSims number of active sims we want to switch to
8769 */
8770 @Override
8771 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008772 if (numOfSims == 1) {
8773 enforceModifyPermission();
8774 } else {
8775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8776 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8777 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008778 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008779
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008780 try {
Michele30b57b22019-03-01 12:01:14 -08008781 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008782 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008783 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8784 return;
8785 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008786 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8787 } finally {
8788 Binder.restoreCallingIdentity(identity);
8789 }
8790 }
8791
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008792 @Override
8793 public boolean isApplicationOnUicc(int subId, int appType) {
8794 enforceReadPrivilegedPermission("isApplicationOnUicc");
8795 Phone phone = getPhone(subId);
8796 if (phone == null) {
8797 return false;
8798 }
8799 final long identity = Binder.clearCallingIdentity();
8800 try {
8801 UiccCard uiccCard = phone.getUiccCard();
8802 if (uiccCard == null) {
8803 return false;
8804 }
8805 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8806 if (uiccProfile == null) {
8807 return false;
8808 }
8809 if (TelephonyManager.APPTYPE_SIM <= appType
8810 && appType <= TelephonyManager.APPTYPE_ISIM) {
8811 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8812 }
8813 return false;
8814 } finally {
8815 Binder.restoreCallingIdentity(identity);
8816 }
8817 }
8818
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008819 /**
chen xub4baa772019-04-03 10:23:41 -07008820 * Get whether making changes to modem configurations will trigger reboot.
8821 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008822 */
8823 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008824 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8825 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008826 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008827 mApp, subId, callingPackage, callingFeatureId,
8828 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008829 return false;
8830 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008831 final long identity = Binder.clearCallingIdentity();
8832 try {
8833 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8834 } finally {
8835 Binder.restoreCallingIdentity(identity);
8836 }
8837 }
8838
Nathan Harold29f5f052019-02-15 13:41:57 -08008839 private void updateModemStateMetrics() {
8840 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8841 // TODO: check the state for each modem if the api is ready.
8842 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8843 }
8844
Pengquan Meng3889a572019-01-23 11:16:29 -08008845 @Override
8846 public int[] getSlotsMapping() {
8847 enforceReadPrivilegedPermission("getSlotsMapping");
8848
8849 final long identity = Binder.clearCallingIdentity();
8850 try {
8851 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8852 // All logical slots should have a mapping to a physical slot.
8853 int[] logicalSlotsMapping = new int[phoneCount];
8854 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8855 for (int i = 0; i < slotInfos.length; i++) {
8856 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8857 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8858 }
8859 }
8860 return logicalSlotsMapping;
8861 } finally {
8862 Binder.restoreCallingIdentity(identity);
8863 }
8864 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008865
8866 /**
8867 * Get the IRadio HAL Version
8868 */
8869 @Override
8870 public int getRadioHalVersion() {
8871 Phone phone = getDefaultPhone();
8872 if (phone == null) return -1;
8873 HalVersion hv = phone.getHalVersion();
8874 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8875 return hv.major * 100 + hv.minor;
8876 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008877
8878 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008879 * Get the current calling package name.
8880 * @return the current calling package name
8881 */
8882 @Override
8883 public String getCurrentPackageName() {
8884 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8885 }
8886
8887 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008888 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8889 * corresponding network requests on a subId.
8890 *
8891 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008892 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008893 * 2) APN is un-metered for this subscription, or
8894 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008895 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008896 *
8897 * @return whether data is allowed for a apn type.
8898 *
8899 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008900 */
8901 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008902 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008903 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8904 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008905
8906 // Now that all security checks passes, perform the operation as ourselves.
8907 final long identity = Binder.clearCallingIdentity();
8908 try {
8909 Phone phone = getPhone(subId);
8910 if (phone == null) return false;
8911
Jack Yu41407ee2019-05-13 16:54:09 -07008912 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008913 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8914 } finally {
8915 Binder.restoreCallingIdentity(identity);
8916 }
8917 }
8918
8919 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008920 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008921 enforceReadPrivilegedPermission("isApnMetered");
8922
8923 // Now that all security checks passes, perform the operation as ourselves.
8924 final long identity = Binder.clearCallingIdentity();
8925 try {
8926 Phone phone = getPhone(subId);
8927 if (phone == null) return true; // By default return true.
8928
Jack Yu41407ee2019-05-13 16:54:09 -07008929 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008930 } finally {
8931 Binder.restoreCallingIdentity(identity);
8932 }
8933 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008934
8935 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008936 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8937 int subscriptionId, IBooleanConsumer resultCallback) {
8938 enforceModifyPermission();
8939 long token = Binder.clearCallingIdentity();
8940 try {
8941 Phone phone = getPhone(subscriptionId);
8942 if (phone == null) {
8943 try {
8944 if (resultCallback != null) {
8945 resultCallback.accept(false);
8946 }
8947 } catch (RemoteException e) {
8948 // ignore
8949 }
8950 return;
8951 }
8952 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8953 Pair.create(specifiers, (x) -> {
8954 try {
8955 if (resultCallback != null) {
8956 resultCallback.accept(x);
8957 }
8958 } catch (RemoteException e) {
8959 // ignore
8960 }
8961 });
8962 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8963 } finally {
8964 Binder.restoreCallingIdentity(token);
8965 }
8966 }
8967
8968 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008969 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8970 TelephonyPermissions
8971 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8972 mApp, subId, "getSystemSelectionChannels");
8973 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8974 final long identity = Binder.clearCallingIdentity();
8975 try {
8976 List<RadioAccessSpecifier> specifiers =
8977 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8978 null, subId, workSource);
8979 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8980 return specifiers;
8981 } finally {
8982 Binder.restoreCallingIdentity(identity);
8983 }
8984 }
8985
8986 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008987 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008988 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008989 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8990 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8991 if (iccRecords == null) {
8992 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8993 return false;
8994 }
8995 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8996 }
8997
8998 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008999 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9000 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009001 if (callingPackage == null) {
9002 callingPackage = getCurrentPackageName();
9003 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009004 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9005 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009006 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9007 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009008 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9009 }
9010 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9011 Intent intent = new Intent();
9012 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9013 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9014 // Bring up choose default SMS subscription dialog right now
9015 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9016 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9017 mApp.startActivity(intent);
9018 }
chen xud5ca2d52019-05-28 15:20:57 -07009019
9020 @Override
9021 public String getMmsUAProfUrl(int subId) {
9022 //TODO investigate if this API should require proper permission check in R b/133791609
9023 final long identity = Binder.clearCallingIdentity();
9024 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009025 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9026 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9027 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9028 return carrierUAProfUrl;
9029 }
chen xud5ca2d52019-05-28 15:20:57 -07009030 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9031 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9032 } finally {
9033 Binder.restoreCallingIdentity(identity);
9034 }
9035 }
9036
9037 @Override
9038 public String getMmsUserAgent(int subId) {
9039 //TODO investigate if this API should require proper permission check in R b/133791609
9040 final long identity = Binder.clearCallingIdentity();
9041 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009042 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9043 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9044 if (!TextUtils.isEmpty(carrierUserAgent)) {
9045 return carrierUserAgent;
9046 }
chen xud5ca2d52019-05-28 15:20:57 -07009047 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9048 .getString(com.android.internal.R.string.config_mms_user_agent);
9049 } finally {
9050 Binder.restoreCallingIdentity(identity);
9051 }
9052 }
Jack Yub07d4972019-05-28 16:12:25 -07009053
9054 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009055 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9056 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9057
9058 final long identity = Binder.clearCallingIdentity();
9059 try {
9060 Phone phone = getPhone(subscriptionId);
9061 if (phone == null) return false;
9062
9063 switch (policy) {
9064 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9065 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9066 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9067 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9068 default:
9069 throw new IllegalArgumentException(policy + " is not a valid policy");
9070 }
9071 } finally {
9072 Binder.restoreCallingIdentity(identity);
9073 }
9074 }
9075
9076 @Override
9077 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9078 boolean enabled) {
9079 enforceModifyPermission();
9080
9081 final long identity = Binder.clearCallingIdentity();
9082 try {
9083 Phone phone = getPhone(subscriptionId);
9084 if (phone == null) return;
9085
9086 switch (policy) {
9087 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9088 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9089 break;
9090 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9091 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9092 break;
9093 default:
9094 throw new IllegalArgumentException(policy + " is not a valid policy");
9095 }
9096 } finally {
9097 Binder.restoreCallingIdentity(identity);
9098 }
9099 }
9100
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009101 /**
Hall Liub48cf452020-09-25 11:13:49 -07009102 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009103 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9104 * otherwise.
9105 */
9106 @Override
9107 public void setCepEnabled(boolean isCepEnabled) {
9108 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9109
9110 final long identity = Binder.clearCallingIdentity();
9111 try {
9112 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9113 for (Phone phone : PhoneFactory.getPhones()) {
9114 Phone defaultPhone = phone.getImsPhone();
9115 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9116 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9117 ImsPhoneCallTracker imsPhoneCallTracker =
9118 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9119 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9120 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9121 + imsPhone.getMsisdn());
9122 }
9123 }
9124 } finally {
9125 Binder.restoreCallingIdentity(identity);
9126 }
9127 }
allenwtsu46dcc572020-01-08 18:24:03 +08009128
9129 /**
9130 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9131 *
9132 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9133 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9134 * before being read.
9135 */
9136 @Override
9137 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9138 isCompressed) {
9139 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9140 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009141 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9142 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9143 }
9144 if (!isImsAvailableOnDevice()) {
9145 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9146 "IMS not available on device.");
9147 }
9148
9149 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009150 try {
Hui Wang068ab862020-10-31 05:12:53 +00009151 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9152 } finally {
9153 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009154 }
9155 }
zoey chenf95ca592019-12-30 16:11:23 +08009156
9157 @Override
9158 public boolean isIccLockEnabled(int subId) {
9159 enforceReadPrivilegedPermission("isIccLockEnabled");
9160
9161 // Now that all security checks passes, perform the operation as ourselves.
9162 final long identity = Binder.clearCallingIdentity();
9163 try {
9164 Phone phone = getPhone(subId);
9165 if (phone != null && phone.getIccCard() != null) {
9166 return phone.getIccCard().getIccLockEnabled();
9167 } else {
9168 return false;
9169 }
9170 } finally {
9171 Binder.restoreCallingIdentity(identity);
9172 }
9173 }
9174
9175 /**
zoey chene02881a2019-12-30 16:11:23 +08009176 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009177 *
zoey chene02881a2019-12-30 16:11:23 +08009178 * @return an integer representing the status of IccLock enabled or disabled in the following
9179 * three cases:
9180 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9181 * successfully.
9182 * - Positive number and zero for remaining password attempts.
9183 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009184 *
9185 */
9186 @Override
9187 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9188 enforceModifyPermission();
9189
9190 Phone phone = getPhone(subId);
9191 if (phone == null) {
9192 return 0;
9193 }
9194 // Now that all security checks passes, perform the operation as ourselves.
9195 final long identity = Binder.clearCallingIdentity();
9196 try {
9197 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9198 new Pair<Boolean, String>(enabled, password), phone, null);
9199 return attemptsRemaining;
9200
9201 } catch (Exception e) {
9202 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9203 } finally {
9204 Binder.restoreCallingIdentity(identity);
9205 }
9206 return 0;
9207 }
9208
9209 /**
9210 * Change the ICC password used in ICC pin lock.
9211 *
zoey chene02881a2019-12-30 16:11:23 +08009212 * @return an integer representing the status of IccLock changed in the following three cases:
9213 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9214 * - Positive number and zero for remaining password attempts.
9215 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009216 *
9217 */
9218 @Override
9219 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9220 enforceModifyPermission();
9221
9222 Phone phone = getPhone(subId);
9223 if (phone == null) {
9224 return 0;
9225 }
9226 // Now that all security checks passes, perform the operation as ourselves.
9227 final long identity = Binder.clearCallingIdentity();
9228 try {
9229 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9230 new Pair<String, String>(oldPassword, newPassword), phone, null);
9231 return attemptsRemaining;
9232
9233 } catch (Exception e) {
9234 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9235 } finally {
9236 Binder.restoreCallingIdentity(identity);
9237 }
9238 return 0;
9239 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009240
Peter Wangdafb9ac2020-01-15 14:13:38 -08009241 /**
9242 * Request for receiving user activity notification
9243 */
9244 @Override
9245 public void requestUserActivityNotification() {
9246 if (!mNotifyUserActivity.get()
9247 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9248 mNotifyUserActivity.set(true);
9249 }
9250 }
9251
9252 /**
9253 * Called when userActivity is signalled in the power manager.
9254 * This is safe to call from any thread, with any window manager locks held or not.
9255 */
9256 @Override
9257 public void userActivity() {
9258 // ***************************************
9259 // * Inherited from PhoneWindowManager *
9260 // ***************************************
9261 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9262 // WITH ITS LOCKS HELD.
9263 //
9264 // This code must be VERY careful about the locks
9265 // it acquires.
9266 // In fact, the current code acquires way too many,
9267 // and probably has lurking deadlocks.
9268
9269 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9270 throw new SecurityException("Only the OS may call notifyUserActivity()");
9271 }
9272
9273 if (mNotifyUserActivity.getAndSet(false)) {
9274 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9275 USER_ACTIVITY_NOTIFICATION_DELAY);
9276 }
9277 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009278
Malcolm Chen884180b2020-04-13 11:59:40 -07009279 @Override
9280 public boolean canConnectTo5GInDsdsMode() {
9281 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9282 }
Jack Yud10cdd42020-09-28 20:28:01 -07009283
9284 @Override
9285 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9286 String callingFeatureId) {
9287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9288 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9289 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9290 }
9291
9292 Phone phone = getPhone(subId);
9293 if (phone == null) {
9294 throw new RuntimeException("phone is not available");
9295 }
9296 // Now that all security checks passes, perform the operation as ourselves.
9297 final long identity = Binder.clearCallingIdentity();
9298 try {
9299 return phone.getEquivalentHomePlmns();
9300 } finally {
9301 Binder.restoreCallingIdentity(identity);
9302 }
9303 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009304
Hui Wang0866fcc2020-10-12 12:14:23 -07009305 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009306 public boolean isRadioInterfaceCapabilitySupported(
9307 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
Daniel Bright0176b322021-02-24 21:03:28 +00009308 Set<String> radioInterfaceCapabilities =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009309 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9310 if (radioInterfaceCapabilities == null) {
9311 throw new RuntimeException("radio interface capabilities are not available");
9312 } else {
Daniel Bright0176b322021-02-24 21:03:28 +00009313 return radioInterfaceCapabilities.contains(capability);
Daniel Bright74f1ca82020-11-13 11:49:37 -08009314 }
9315 }
9316
9317 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009318 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9319 UaSecurityProtocolIdentifier securityProtocol,
Brad Ebinger4df7e242021-02-17 23:23:21 +00009320 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) {
9321 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9322 Binder.getCallingUid(), "bootstrapAuthenticationRequest",
9323 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9324 Manifest.permission.MODIFY_PHONE_STATE);
Hui Wang0866fcc2020-10-12 12:14:23 -07009325 if (DBG) {
9326 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9327 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9328 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9329 }
9330
9331 if (!SubscriptionManager.isValidSubscriptionId(subId)
9332 || appType < TelephonyManager.APPTYPE_UNKNOWN
9333 || appType > TelephonyManager.APPTYPE_ISIM
9334 || nafUrl == null || securityProtocol == null || callback == null) {
9335 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9336 if (callback != null) {
9337 try {
9338 callback.onAuthenticationFailure(
9339 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9340 } catch (RemoteException exception) {
9341 log("Fail to notify onAuthenticationFailure due to " + exception);
9342 }
9343 return;
9344 }
9345 }
9346
9347 final long token = Binder.clearCallingIdentity();
9348 try {
9349 getGbaManager(subId).bootstrapAuthenticationRequest(
9350 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9351 forceBootStrapping, callback));
9352 } finally {
9353 Binder.restoreCallingIdentity(token);
9354 }
9355 }
9356
Jack Nudelman24d51a52020-11-24 12:08:04 -08009357 /**
9358 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9359 * requested radio power state will actually be set. See {@link
9360 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9361 *
9362 * @param subId the subscription ID of the phone requesting to set the radio power state.
9363 * @param enable {@code true} if trying to turn radio on.
9364 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9365 * false}.
9366 */
9367 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9368 Phone phone = getPhone(subId);
9369 if (phone != null) {
9370 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9371 return true;
9372 }
9373 return false;
9374 }
9375
9376 private int handleDataThrottlingRequest(int subId,
9377 DataThrottlingRequest dataThrottlingRequest) {
9378 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9379 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9380 if (!setRadioPowerForThermal(subId, true)) {
9381 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9382 }
9383
9384 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9385
9386 int thermalMitigationResult =
9387 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9388 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9389 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9390 }
9391 return thermalMitigationResult;
9392 }
9393
9394 /**
9395 * Thermal mitigation request to control functionalities at modem.
9396 *
9397 * @param subId the id of the subscription.
9398 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9399 *
9400 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9401 */
9402 @Override
9403 @ThermalMitigationResult
9404 public int sendThermalMitigationRequest(
9405 int subId,
9406 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9407 enforceModifyPermission();
9408
9409 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9410 final long identity = Binder.clearCallingIdentity();
9411
9412 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9413 try {
9414 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9415 switch (thermalMitigationAction) {
9416 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9417 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009418 handleDataThrottlingRequest(subId,
9419 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009420 break;
9421 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9422 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9423 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9424 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9425 }
9426
9427 // Ensure that radio is on. If not able to power on due to phone being
9428 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9429 if (!setRadioPowerForThermal(subId, true)) {
9430 thermalMitigationResult =
9431 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9432 break;
9433 }
9434
9435 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9436 false);
9437 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9438 break;
9439 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9440 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9441 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9442 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9443 }
9444
9445 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9446 if (registry != null) {
9447 TelephonyConnectionService service =
9448 registry.getTelephonyConnectionService();
9449 Phone phone = getPhone(subId);
9450 if (phone == null) {
9451 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009452 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009453 break;
9454 }
9455
9456 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009457 != TelephonyManager.CALL_STATE_IDLE
9458 || phone.isInEmergencySmsMode() || phone.isInEcm()
9459 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009460 String errorMessage = "Phone state is not valid. call state = "
9461 + PhoneConstantConversions.convertCallState(phone.getState())
9462 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9463 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9464 errorMessage += service == null
9465 ? " TelephonyConnectionService is null"
9466 : " isEmergencyCallPending = "
9467 + service.isEmergencyCallPending();
9468 Log.e(LOG_TAG, errorMessage);
9469 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009470 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009471 break;
9472 }
9473 } else {
9474 thermalMitigationResult =
9475 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9476 break;
9477 }
9478
9479 // Turn radio off. If not able to power off due to phone being unavailable,
9480 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9481 if (!setRadioPowerForThermal(subId, false)) {
9482 thermalMitigationResult =
9483 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9484 break;
9485 }
9486 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009487 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009488 break;
9489 default:
9490 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9491 + "not exist. Requested action: " + thermalMitigationAction);
9492 }
9493 } catch (IllegalArgumentException e) {
9494 throw e;
9495 } catch (Exception e) {
9496 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9497 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9498 } finally {
9499 Binder.restoreCallingIdentity(identity);
9500 }
9501
9502 if (DBG) {
9503 log("thermalMitigationRequest returning with thermalMitigationResult: "
9504 + thermalMitigationResult);
9505 }
9506
9507 return thermalMitigationResult;
9508 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009509
9510 /**
9511 * Set the GbaService Package Name that Telephony will bind to.
9512 *
9513 * @param subId The sim that the GbaService is associated with.
9514 * @param packageName The name of the package to be replaced with.
9515 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9516 */
9517 @Override
9518 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9519 enforceModifyPermission();
9520
9521 final long identity = Binder.clearCallingIdentity();
9522 try {
9523 return getGbaManager(subId).overrideServicePackage(packageName);
9524 } finally {
9525 Binder.restoreCallingIdentity(identity);
9526 }
9527 }
9528
9529 /**
9530 * Return the package name of the currently bound GbaService.
9531 *
9532 * @param subId The sim that the GbaService is associated with.
9533 * @return the package name of the GbaService configuration, null if GBA is not supported.
9534 */
9535 @Override
9536 public String getBoundGbaService(int subId) {
9537 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9538
9539 final long identity = Binder.clearCallingIdentity();
9540 try {
9541 return getGbaManager(subId).getServicePackage();
9542 } finally {
9543 Binder.restoreCallingIdentity(identity);
9544 }
9545 }
9546
9547 /**
9548 * Set the release time for telephony to unbind GbaService.
9549 *
9550 * @param subId The sim that the GbaService is associated with.
9551 * @param interval The release time to unbind GbaService by millisecond.
9552 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9553 */
9554 @Override
9555 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9556 enforceModifyPermission();
9557
9558 final long identity = Binder.clearCallingIdentity();
9559 try {
9560 return getGbaManager(subId).overrideReleaseTime(interval);
9561 } finally {
9562 Binder.restoreCallingIdentity(identity);
9563 }
9564 }
9565
9566 /**
9567 * Return the release time for telephony to unbind GbaService.
9568 *
9569 * @param subId The sim that the GbaService is associated with.
9570 * @return The release time to unbind GbaService by millisecond.
9571 */
9572 @Override
9573 public int getGbaReleaseTime(int subId) {
9574 enforceReadPrivilegedPermission("getGbaReleaseTime");
9575
9576 final long identity = Binder.clearCallingIdentity();
9577 try {
9578 return getGbaManager(subId).getReleaseTime();
9579 } finally {
9580 Binder.restoreCallingIdentity(identity);
9581 }
9582 }
9583
9584 private GbaManager getGbaManager(int subId) {
9585 GbaManager instance = GbaManager.getInstance(subId);
9586 if (instance == null) {
9587 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9588 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9589 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9590 }
9591 return instance;
9592 }
Hui Wang068ab862020-10-31 05:12:53 +00009593
9594 /**
9595 * indicate whether the device and the carrier can support
9596 * RCS VoLTE single registration.
9597 */
9598 @Override
9599 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009600 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9601 Binder.getCallingUid(), "isRcsVolteSingleRegistrationCapable",
9602 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9603 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009604
9605 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9606 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9607 }
9608
9609 final long identity = Binder.clearCallingIdentity();
9610 try {
9611 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9612 if (rpm != null) {
9613 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9614 }
9615 return false;
9616 } finally {
9617 Binder.restoreCallingIdentity(identity);
9618 }
9619 }
9620
9621 /**
9622 * Register RCS provisioning callback.
9623 */
9624 @Override
9625 public void registerRcsProvisioningChangedCallback(int subId,
9626 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009627 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9628 Binder.getCallingUid(), "registerRcsProvisioningChangedCallback",
9629 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9630 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009631
9632 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9633 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9634 }
9635 if (!isImsAvailableOnDevice()) {
9636 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9637 "IMS not available on device.");
9638 }
9639
9640 final long identity = Binder.clearCallingIdentity();
9641 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009642 if (!RcsProvisioningMonitor.getInstance()
9643 .registerRcsProvisioningChangedCallback(subId, callback)) {
9644 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9645 "Service not available for the subscription.");
9646 }
Hui Wang068ab862020-10-31 05:12:53 +00009647 } finally {
9648 Binder.restoreCallingIdentity(identity);
9649 }
9650 }
9651
9652 /**
9653 * Unregister RCS provisioning callback.
9654 */
9655 @Override
9656 public void unregisterRcsProvisioningChangedCallback(int subId,
9657 IRcsConfigCallback callback) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009658 TelephonyPermissions.enforceAnyPermissionGrantedOrCarrierPrivileges(mApp, subId,
9659 Binder.getCallingUid(), "unregisterRcsProvisioningChangedCallback",
9660 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION,
9661 permission.READ_PRIVILEGED_PHONE_STATE);
Hui Wang068ab862020-10-31 05:12:53 +00009662
9663 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9664 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9665 }
9666 if (!isImsAvailableOnDevice()) {
9667 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9668 "IMS not available on device.");
9669 }
9670
9671 final long identity = Binder.clearCallingIdentity();
9672 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009673 RcsProvisioningMonitor.getInstance()
9674 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009675 } finally {
9676 Binder.restoreCallingIdentity(identity);
9677 }
9678 }
9679
9680 /**
9681 * trigger RCS reconfiguration.
9682 */
9683 public void triggerRcsReconfiguration(int subId) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009684 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9685 "triggerRcsReconfiguration",
9686 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009687
9688 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9689 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9690 }
9691 if (!isImsAvailableOnDevice()) {
9692 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9693 "IMS not available on device.");
9694 }
9695
9696 final long identity = Binder.clearCallingIdentity();
9697 try {
9698 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9699 } finally {
9700 Binder.restoreCallingIdentity(identity);
9701 }
9702 }
9703
9704 /**
9705 * Provide the client configuration parameters of the RCS application.
9706 */
9707 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
Brad Ebinger4df7e242021-02-17 23:23:21 +00009708 TelephonyPermissions.enforceAnyPermissionGranted(mApp, Binder.getCallingUid(),
9709 "setRcsClientConfiguration",
9710 Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION);
Hui Wang068ab862020-10-31 05:12:53 +00009711
9712 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9713 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9714 }
9715 if (!isImsAvailableOnDevice()) {
9716 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9717 "IMS not available on device.");
9718 }
9719
9720 final long identity = Binder.clearCallingIdentity();
9721
9722 try {
9723 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9724 if (configBinder == null) {
9725 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9726 } else {
9727 configBinder.setRcsClientConfiguration(rcc);
9728 }
9729 } catch (RemoteException e) {
9730 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9731 } finally {
9732 Binder.restoreCallingIdentity(identity);
9733 }
9734 }
9735
9736 /**
Hui Wang19a21872021-02-19 20:45:36 -08009737 * Enables or disables the test mode for RCS VoLTE single registration.
9738 */
9739 @Override
9740 public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) {
9741 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9742 "setRcsSingleRegistrationTestModeEnabled");
9743
9744 RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled);
9745 }
9746
9747 /**
9748 * Gets the test mode for RCS VoLTE single registration.
9749 */
9750 @Override
9751 public boolean getRcsSingleRegistrationTestModeEnabled() {
9752 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9753 "getRcsSingleRegistrationTestModeEnabled");
9754
9755 return RcsProvisioningMonitor.getInstance().getTestModeEnabled();
9756 }
9757
9758 /**
Hui Wang068ab862020-10-31 05:12:53 +00009759 * Overrides the config of RCS VoLTE single registration enabled for the device.
9760 */
9761 @Override
9762 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9763 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9764 "setDeviceSingleRegistrationEnabledOverride");
9765 enforceModifyPermission();
9766
9767 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9768 : Boolean.parseBoolean(enabledStr);
9769 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009770 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009771 }
9772
9773 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009774 * Sends a device to device communication message. Only usable via shell.
9775 * @param message message to send.
9776 * @param value message value.
9777 */
9778 @Override
9779 public void sendDeviceToDeviceMessage(int message, int value) {
9780 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9781 "setCarrierSingleRegistrationEnabledOverride");
9782 enforceModifyPermission();
9783
9784 final long identity = Binder.clearCallingIdentity();
9785 try {
9786 TelephonyConnectionService service =
9787 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9788 if (service == null) {
9789 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9790 return;
9791 }
9792 service.sendTestDeviceToDeviceMessage(message, value);
9793 } finally {
9794 Binder.restoreCallingIdentity(identity);
9795 }
9796 }
9797
9798
9799 /**
Hui Wang068ab862020-10-31 05:12:53 +00009800 * Gets the config of RCS VoLTE single registration enabled for the device.
9801 */
9802 @Override
9803 public boolean getDeviceSingleRegistrationEnabled() {
9804 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9805 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9806 }
9807
9808 /**
9809 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9810 */
9811 @Override
9812 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9813 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9814 "setCarrierSingleRegistrationEnabledOverride");
9815 enforceModifyPermission();
9816
9817 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9818 : Boolean.parseBoolean(enabledStr);
9819 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9820 subId, enabled);
9821 }
9822
9823 /**
9824 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9825 */
9826 @Override
9827 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9828 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9829 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9830 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009831
9832 /**
9833 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9834 * their mobile plan.
9835 */
9836 @Override
9837 public String getMobileProvisioningUrl() {
9838 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9839 final long identity = Binder.clearCallingIdentity();
9840 try {
9841 return getDefaultPhone().getMobileProvisioningUrl();
9842 } finally {
9843 Binder.restoreCallingIdentity(identity);
9844 }
9845 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009846
James.cf Linbcdf8b32021-01-14 16:44:13 +08009847 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009848 * Get the EAB contact from the EAB database.
9849 */
9850 @Override
9851 public String getContactFromEab(String contact) {
9852 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9853 enforceModifyPermission();
9854 final long identity = Binder.clearCallingIdentity();
9855 try {
9856 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9857 } finally {
9858 Binder.restoreCallingIdentity(identity);
9859 }
9860 }
9861
9862 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009863 * Remove the EAB contacts from the EAB database.
9864 */
9865 @Override
9866 public int removeContactFromEab(int subId, String contacts) {
9867 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9868 enforceModifyPermission();
9869 final long identity = Binder.clearCallingIdentity();
9870 try {
9871 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9872 } finally {
9873 Binder.restoreCallingIdentity(identity);
9874 }
9875 }
9876
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009877 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009878 public boolean getDeviceUceEnabled() {
9879 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 return mApp.getDeviceUceEnabled();
9883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 }
9887
9888 @Override
9889 public void setDeviceUceEnabled(boolean isEnabled) {
9890 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9891 final long identity = Binder.clearCallingIdentity();
9892 try {
9893 mApp.setDeviceUceEnabled(isEnabled);
9894 } finally {
9895 Binder.restoreCallingIdentity(identity);
9896 }
9897 }
9898
9899 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009900 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9901 String callingPackage) {
9902 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9903 mApp, subId, "setSignalStrengthUpdateRequest");
9904
9905 final int callingUid = Binder.getCallingUid();
9906 // Verify that tha callingPackage belongs to the calling UID
9907 mApp.getSystemService(AppOpsManager.class)
9908 .checkPackage(callingUid, callingPackage);
9909
9910 validateSignalStrengthUpdateRequest(request, callingUid);
9911
9912 final long identity = Binder.clearCallingIdentity();
9913 try {
9914 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9915 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9916
9917 if (result instanceof IllegalStateException) {
9918 throw (IllegalStateException) result;
9919 }
9920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
9924
9925 @Override
9926 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9927 String callingPackage) {
9928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9929 mApp, subId, "clearSignalStrengthUpdateRequest");
9930
9931 final int callingUid = Binder.getCallingUid();
9932 // Verify that tha callingPackage belongs to the calling UID
9933 mApp.getSystemService(AppOpsManager.class)
9934 .checkPackage(callingUid, callingPackage);
9935
9936 final long identity = Binder.clearCallingIdentity();
9937 try {
9938 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9939 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9940
9941 if (result instanceof IllegalStateException) {
9942 throw (IllegalStateException) result;
9943 }
9944 } finally {
9945 Binder.restoreCallingIdentity(identity);
9946 }
9947 }
9948
9949 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9950 int callingUid) {
9951 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9952 // phone/system process do not have further restriction on request
9953 return;
9954 }
9955
9956 // Applications has restrictions on how to use the request:
9957 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9958 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9959 // This is not system caller which has been checked above
9960 throw new IllegalArgumentException(
9961 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9962 }
9963
9964 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9965 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9966 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9967 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9968 || info.isEnabled()) {
9969 throw new IllegalArgumentException(
9970 "Only system can set hide fields in SignalThresholdInfo");
9971 }
9972
9973 // Thresholds length for each RAN need in range. This has been validated in
9974 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
9975 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
9976 final int[] thresholds = info.getThresholds();
9977 Objects.requireNonNull(thresholds);
9978 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
9979 || thresholds.length
9980 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
9981 throw new IllegalArgumentException(
9982 "thresholds length is out of range: " + thresholds.length);
9983 }
9984 }
9985 }
Michele Berionned9fbae52020-11-13 02:36:59 +00009986
9987 /**
9988 * Prepare TelephonyManager for an unattended reboot. The reboot is
9989 * required to be done shortly after the API is invoked.
9990 */
9991 @Override
9992 @TelephonyManager.PrepareUnattendedRebootResult
9993 public int prepareForUnattendedReboot() {
9994 enforceRebootPermission();
9995
9996 final long identity = Binder.clearCallingIdentity();
9997 try {
9998 return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null);
9999 } finally {
10000 Binder.restoreCallingIdentity(identity);
10001 }
10002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010003}