blob: 576052709a2340781c9346f701f809e7d8dc50cf [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Derek Tan740e1672017-06-27 14:56:27 -070034import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080035import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070036import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070037import android.net.Uri;
38import android.os.AsyncResult;
39import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080040import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041import android.os.Bundle;
42import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070043import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Looper;
45import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080047import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070048import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070049import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080050import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080051import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070052import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070053import android.os.ServiceSpecificException;
Rambo Wang0f050d82021-02-12 11:43:36 -080054import android.os.SystemClock;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080067import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080068import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070069import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080079import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070080import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070081import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070082import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080083import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070084import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080085import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070086import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080087import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080088import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070089import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080090import android.telephony.RadioAccessSpecifier;
Daniel Bright74f1ca82020-11-13 11:49:37 -080091import android.telephony.RadioInterfaceCapabilities;
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;
Svet Ganovb320e182015-04-16 12:30:10 -0700162import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700163import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700164import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700165import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800166import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800167import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800168import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700169import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800170import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700171import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800172import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700173import com.android.internal.telephony.imsphone.ImsPhone;
174import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800175import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900176import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700177import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800178import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700179import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800180import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700181import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800182import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700183import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800184import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000185import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800186import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700187import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700188import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800189import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700190import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700191import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800192import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700193import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700194import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800195import com.android.services.telephony.TelecomAccountRegistry;
196import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800197import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800198
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700199import java.io.FileDescriptor;
200import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800203import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800205import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100206import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700208import java.util.NoSuchElementException;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800209import java.util.Objects;
sqianf4ca7ed2019-01-15 18:32:07 -0800210import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800211import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800212import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700213
214/**
215 * Implementation of the ITelephony interface.
216 */
Santos Cordon117fee72014-05-16 17:56:12 -0700217public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700218 private static final String LOG_TAG = "PhoneInterfaceManager";
219 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
220 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800221 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700222
223 // Message codes used with mMainThreadHandler
224 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700225 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
226 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700227 private static final int CMD_OPEN_CHANNEL = 9;
228 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
229 private static final int CMD_CLOSE_CHANNEL = 11;
230 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800231 private static final int CMD_NV_READ_ITEM = 13;
232 private static final int EVENT_NV_READ_ITEM_DONE = 14;
233 private static final int CMD_NV_WRITE_ITEM = 15;
234 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
235 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
236 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700237 private static final int CMD_RESET_MODEM_CONFIG = 19;
238 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800239 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
240 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
241 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
242 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800243 private static final int CMD_SEND_ENVELOPE = 25;
244 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000245 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
246 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700247 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
248 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
249 private static final int CMD_EXCHANGE_SIM_IO = 31;
250 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800251 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
252 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700253 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700255 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
256 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700257 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
258 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
259 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
260 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700261 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
262 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
263 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
264 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700265 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800266 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
267 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000268 private static final int CMD_SWITCH_SLOTS = 50;
269 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700270 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
271 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
272 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
273 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
274 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
275 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
276 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
277 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700278 private static final int CMD_GET_ALL_CELL_INFO = 60;
279 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
280 private static final int CMD_GET_CELL_LOCATION = 62;
281 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700282 private static final int CMD_MODEM_REBOOT = 64;
283 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700284 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
285 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800286 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
287 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700288 private static final int CMD_GET_MODEM_STATUS = 70;
289 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700290 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
291 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700292 private static final int CMD_ERASE_MODEM_CONFIG = 74;
293 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800294 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
295 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
296 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
297 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800298 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
299 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800300 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800301 private static final int CMD_GET_CALL_FORWARDING = 83;
302 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
303 private static final int CMD_SET_CALL_FORWARDING = 85;
304 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
305 private static final int CMD_GET_CALL_WAITING = 87;
306 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
307 private static final int CMD_SET_CALL_WAITING = 89;
308 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700309 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
310 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
311 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
312 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700313 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
314 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800315 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
316 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800317 private static final int CMD_SET_DATA_THROTTLING = 99;
318 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800319 private static final int CMD_SET_SIM_POWER = 101;
320 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Rambo Wanga5cc9b72021-01-07 10:51:54 -0800321 private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103;
322 private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104;
323 private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105;
324 private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106;
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
Jake Hamby7c27be32014-03-03 13:25:59 -0800875 case CMD_GET_PREFERRED_NETWORK_TYPE:
876 request = (MainThreadRequest) msg.obj;
877 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700878 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800879 break;
880
881 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
882 ar = (AsyncResult) msg.obj;
883 request = (MainThreadRequest) ar.userObj;
884 if (ar.exception == null && ar.result != null) {
885 request.result = ar.result; // Integer
886 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530887 // request.result must be set to something non-null
888 // for the calling thread to unblock
889 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800890 if (ar.result == null) {
891 loge("getPreferredNetworkType: Empty response");
892 } else if (ar.exception instanceof CommandException) {
893 loge("getPreferredNetworkType: CommandException: " +
894 ar.exception);
895 } else {
896 loge("getPreferredNetworkType: Unknown exception");
897 }
898 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700899 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800900 break;
901
902 case CMD_SET_PREFERRED_NETWORK_TYPE:
903 request = (MainThreadRequest) msg.obj;
904 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
905 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700906 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800907 break;
908
909 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
910 handleNullReturnEvent(msg, "setPreferredNetworkType");
911 break;
912
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000913 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
914 request = (MainThreadRequest)msg.obj;
915 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800916 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000917 break;
918
919 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
920 ar = (AsyncResult)msg.obj;
921 request = (MainThreadRequest)ar.userObj;
922 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700923 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000924 break;
925
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800926 case CMD_SET_VOICEMAIL_NUMBER:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
929 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800930 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
931 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800932 break;
933
934 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
935 handleNullReturnEvent(msg, "setVoicemailNumber");
936 break;
937
Stuart Scott54788802015-03-30 13:18:01 -0700938 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
939 request = (MainThreadRequest) msg.obj;
940 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
941 request);
942 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
943 break;
944
945 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
946 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
947 break;
948
Shishir Agrawal302c8692015-06-19 13:49:39 -0700949 case CMD_PERFORM_NETWORK_SCAN:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
952 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
953 break;
954
Hall Liua1acea22020-09-18 19:04:59 -0700955 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700958 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
959 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
960 request.argument;
961 int callForwardingReason = args.first;
962 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800963 break;
Hall Liua1acea22020-09-18 19:04:59 -0700964 }
965 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800966 ar = (AsyncResult) msg.obj;
967 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700968 TelephonyManager.CallForwardingInfoCallback callback =
969 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
970 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800971 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700972 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800973 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
974 for (CallForwardInfo callForwardInfo : callForwardInfos) {
975 // Service Class is a bit mask per 3gpp 27.007. Search for
976 // any service for voice call.
977 if ((callForwardInfo.serviceClass
978 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700979 callForwardingInfo = new CallForwardingInfo(true,
980 callForwardInfo.reason,
981 callForwardInfo.number,
982 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800983 break;
984 }
985 }
986 // Didn't find a call forward info for voice call.
987 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700988 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
989 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800990 }
Hall Liua1acea22020-09-18 19:04:59 -0700991 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800992 } else {
993 if (ar.result == null) {
994 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
995 }
996 if (ar.exception != null) {
997 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
998 }
Hall Liuae527aa2020-09-29 17:10:18 -0700999 int errorCode = TelephonyManager
1000 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -08001001 if (ar.exception instanceof CommandException) {
1002 CommandException.Error error =
1003 ((CommandException) (ar.exception)).getCommandError();
1004 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001005 errorCode = TelephonyManager
1006 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -08001007 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001008 errorCode = TelephonyManager
1009 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -08001010 }
1011 }
Hall Liua1acea22020-09-18 19:04:59 -07001012 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001013 }
sqian80370722020-01-29 15:02:51 -08001014 break;
Hall Liua1acea22020-09-18 19:04:59 -07001015 }
sqian80370722020-01-29 15:02:51 -08001016
Hall Liua1acea22020-09-18 19:04:59 -07001017 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001018 request = (MainThreadRequest) msg.obj;
1019 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001020 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001021 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001022 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1023 request.argument).first;
1024 request.phone.setCallForwardingOption(
1025 callForwardingInfoToSet.isEnabled()
1026 ? CommandsInterface.CF_ACTION_ENABLE
1027 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001028 callForwardingInfoToSet.getReason(),
1029 callForwardingInfoToSet.getNumber(),
1030 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1031 break;
Hall Liua1acea22020-09-18 19:04:59 -07001032 }
sqian80370722020-01-29 15:02:51 -08001033
Hall Liua1acea22020-09-18 19:04:59 -07001034 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001035 ar = (AsyncResult) msg.obj;
1036 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001037 Consumer<Integer> callback =
1038 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1039 request.argument).second;
1040 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001041 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001042 int errorCode = TelephonyManager.CallForwardingInfoCallback
1043 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001044 if (ar.exception instanceof CommandException) {
1045 CommandException.Error error =
1046 ((CommandException) (ar.exception)).getCommandError();
1047 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001048 errorCode = TelephonyManager.CallForwardingInfoCallback
1049 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001050 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001051 errorCode = TelephonyManager.CallForwardingInfoCallback
1052 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001053 }
1054 }
1055 callback.accept(errorCode);
1056 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001057 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001058 }
sqian80370722020-01-29 15:02:51 -08001059 break;
Hall Liua1acea22020-09-18 19:04:59 -07001060 }
sqian80370722020-01-29 15:02:51 -08001061
Hall Liua1acea22020-09-18 19:04:59 -07001062 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001063 request = (MainThreadRequest) msg.obj;
1064 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1065 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1066 break;
Hall Liua1acea22020-09-18 19:04:59 -07001067 }
sqian80370722020-01-29 15:02:51 -08001068
Hall Liua1acea22020-09-18 19:04:59 -07001069 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001070 ar = (AsyncResult) msg.obj;
1071 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001072 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001073 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1074 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001075 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001076 // Service Class is a bit mask per 3gpp 27.007.
1077 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001078 if (callForwardResults.length > 1
1079 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001080 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001081 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001082 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1083 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001084 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001085 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001086 }
1087 } else {
1088 if (ar.result == null) {
1089 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1090 }
1091 if (ar.exception != null) {
1092 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1093 }
1094 if (ar.exception instanceof CommandException) {
1095 CommandException.Error error =
1096 ((CommandException) (ar.exception)).getCommandError();
1097 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1098 callForwardingStatus =
1099 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1100 }
1101 }
1102 }
Hall Liua1acea22020-09-18 19:04:59 -07001103 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001104 break;
Hall Liua1acea22020-09-18 19:04:59 -07001105 }
sqian80370722020-01-29 15:02:51 -08001106
Hall Liua1acea22020-09-18 19:04:59 -07001107 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001108 request = (MainThreadRequest) msg.obj;
1109 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001110 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1111 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001112 break;
Hall Liua1acea22020-09-18 19:04:59 -07001113 }
sqian80370722020-01-29 15:02:51 -08001114
Hall Liua1acea22020-09-18 19:04:59 -07001115 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001116 ar = (AsyncResult) msg.obj;
1117 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001118 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1119 Consumer<Integer> callback =
1120 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1121 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001122 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001123 if (ar.exception instanceof CommandException) {
1124 CommandException.Error error =
1125 ((CommandException) (ar.exception)).getCommandError();
1126 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1127 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1128 } else {
1129 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1130 }
1131 } else {
1132 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1133 }
1134 } else {
1135 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1136 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001137 }
sqian80370722020-01-29 15:02:51 -08001138 break;
Hall Liua1acea22020-09-18 19:04:59 -07001139 }
sqian80370722020-01-29 15:02:51 -08001140
Shishir Agrawal302c8692015-06-19 13:49:39 -07001141 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 CellNetworkScanResult cellScanResult;
1145 if (ar.exception == null && ar.result != null) {
1146 cellScanResult = new CellNetworkScanResult(
1147 CellNetworkScanResult.STATUS_SUCCESS,
1148 (List<OperatorInfo>) ar.result);
1149 } else {
1150 if (ar.result == null) {
1151 loge("getCellNetworkScanResults: Empty response");
1152 }
1153 if (ar.exception != null) {
1154 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1155 }
1156 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1157 if (ar.exception instanceof CommandException) {
1158 CommandException.Error error =
1159 ((CommandException) (ar.exception)).getCommandError();
1160 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1161 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1162 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1163 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1164 }
1165 }
1166 cellScanResult = new CellNetworkScanResult(errorCode, null);
1167 }
1168 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001169 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001170 break;
1171
1172 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1173 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001174 ManualNetworkSelectionArgument selArg =
1175 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001176 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1177 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001178 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1179 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001180 break;
1181
1182 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001183 ar = (AsyncResult) msg.obj;
1184 request = (MainThreadRequest) ar.userObj;
1185 if (ar.exception == null) {
1186 request.result = true;
1187 } else {
1188 request.result = false;
1189 loge("setNetworkSelectionModeManual " + ar.exception);
1190 }
1191 notifyRequester(request);
1192 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001193 break;
1194
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001195 case CMD_GET_MODEM_ACTIVITY_INFO:
1196 request = (MainThreadRequest) msg.obj;
1197 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001198 if (defaultPhone != null) {
1199 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001200 } else {
1201 ResultReceiver result = (ResultReceiver) request.argument;
1202 Bundle bundle = new Bundle();
1203 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1204 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1205 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001206 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001207 break;
1208
1209 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001212 ResultReceiver result = (ResultReceiver) request.argument;
1213
1214 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001215 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001216 // Update the last modem activity info and the result of the request.
1217 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1218 if (isModemActivityInfoValid(info)) {
1219 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1220 int[] txTimeMs = info.getTransmitTimeMillis();
1221 int[] lastModemTxTimeMs = mLastModemActivityInfo
1222 .getTransmitTimeMillis();
1223 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1224 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1225 }
1226 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1227 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1228 + mLastModemActivityInfo.getSleepTimeMillis());
1229 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1230 + mLastModemActivityInfo.getIdleTimeMillis());
1231 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1232 mLastModemActivityInfo.setReceiveTimeMillis(
1233 info.getReceiveTimeMillis()
1234 + mLastModemActivityInfo.getReceiveTimeMillis());
1235 }
1236 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1237 mLastModemActivityInfo.getSleepTimeMillis(),
1238 mLastModemActivityInfo.getIdleTimeMillis(),
1239 mLastModemActivityInfo.getTransmitTimeMillis(),
1240 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001241 } else {
1242 if (ar.result == null) {
1243 loge("queryModemActivityInfo: Empty response");
1244 } else if (ar.exception instanceof CommandException) {
1245 loge("queryModemActivityInfo: CommandException: " +
1246 ar.exception);
1247 } else {
1248 loge("queryModemActivityInfo: Unknown exception");
1249 }
1250 }
sqian1a1be542020-03-05 11:37:28 -08001251 Bundle bundle = new Bundle();
1252 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1253 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001254 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001255 break;
1256
Meng Wang1a7c35a2016-05-05 20:56:15 -07001257 case CMD_SET_ALLOWED_CARRIERS:
1258 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001259 CarrierRestrictionRules argument =
1260 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001261 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001262 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001263 break;
1264
1265 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1266 ar = (AsyncResult) msg.obj;
1267 request = (MainThreadRequest) ar.userObj;
1268 if (ar.exception == null && ar.result != null) {
1269 request.result = ar.result;
1270 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001271 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1272 if (ar.exception instanceof CommandException) {
1273 loge("setAllowedCarriers: CommandException: " + ar.exception);
1274 CommandException.Error error =
1275 ((CommandException) (ar.exception)).getCommandError();
1276 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1277 request.result =
1278 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1279 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001280 } else {
1281 loge("setAllowedCarriers: Unknown exception");
1282 }
1283 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001284 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001285 break;
1286
1287 case CMD_GET_ALLOWED_CARRIERS:
1288 request = (MainThreadRequest) msg.obj;
1289 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001290 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001291 break;
1292
1293 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1294 ar = (AsyncResult) msg.obj;
1295 request = (MainThreadRequest) ar.userObj;
1296 if (ar.exception == null && ar.result != null) {
1297 request.result = ar.result;
1298 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001299 request.result = new IllegalStateException(
1300 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001301 if (ar.result == null) {
1302 loge("getAllowedCarriers: Empty response");
1303 } else if (ar.exception instanceof CommandException) {
1304 loge("getAllowedCarriers: CommandException: " +
1305 ar.exception);
1306 } else {
1307 loge("getAllowedCarriers: Unknown exception");
1308 }
1309 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001310 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001311 break;
1312
Nathan Haroldb3014052017-01-25 15:57:32 -08001313 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1314 ar = (AsyncResult) msg.obj;
1315 request = (MainThreadRequest) ar.userObj;
1316 if (ar.exception == null && ar.result != null) {
1317 request.result = ar.result;
1318 } else {
1319 request.result = new IllegalArgumentException(
1320 "Failed to retrieve Forbidden Plmns");
1321 if (ar.result == null) {
1322 loge("getForbiddenPlmns: Empty response");
1323 } else {
1324 loge("getForbiddenPlmns: Unknown exception");
1325 }
1326 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001327 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001328 break;
1329
1330 case CMD_GET_FORBIDDEN_PLMNS:
1331 request = (MainThreadRequest) msg.obj;
1332 uiccCard = getUiccCardFromRequest(request);
1333 if (uiccCard == null) {
1334 loge("getForbiddenPlmns() UiccCard is null");
1335 request.result = new IllegalArgumentException(
1336 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001337 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001338 break;
1339 }
1340 Integer appType = (Integer) request.argument;
1341 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1342 if (uiccApp == null) {
1343 loge("getForbiddenPlmns() no app with specified type -- "
1344 + appType);
1345 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001346 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001347 break;
1348 } else {
1349 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1350 + " specified type -- " + appType);
1351 }
1352 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1353 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1354 onCompleted);
1355 break;
1356
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001357 case CMD_SWITCH_SLOTS:
1358 request = (MainThreadRequest) msg.obj;
1359 int[] physicalSlots = (int[]) request.argument;
1360 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1361 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1362 break;
1363
1364 case EVENT_SWITCH_SLOTS_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001368 notifyRequester(request);
1369 break;
1370 case CMD_GET_NETWORK_SELECTION_MODE:
1371 request = (MainThreadRequest) msg.obj;
1372 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1373 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1374 break;
1375
1376 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1377 ar = (AsyncResult) msg.obj;
1378 request = (MainThreadRequest) ar.userObj;
1379 if (ar.exception != null) {
1380 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1381 } else {
1382 int mode = ((int[]) ar.result)[0];
1383 if (mode == 0) {
1384 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1385 } else {
1386 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1387 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001388 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001389 notifyRequester(request);
1390 break;
1391 case CMD_GET_CDMA_ROAMING_MODE:
1392 request = (MainThreadRequest) msg.obj;
1393 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1394 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1395 break;
1396 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 if (ar.exception != null) {
1400 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1401 } else {
1402 request.result = ((int[]) ar.result)[0];
1403 }
1404 notifyRequester(request);
1405 break;
1406 case CMD_SET_CDMA_ROAMING_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1409 int mode = (int) request.argument;
1410 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1411 break;
1412 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1413 ar = (AsyncResult) msg.obj;
1414 request = (MainThreadRequest) ar.userObj;
1415 request.result = ar.exception == null;
1416 notifyRequester(request);
1417 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001418 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1419 request = (MainThreadRequest) msg.obj;
1420 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1421 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1422 break;
1423 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1424 ar = (AsyncResult) msg.obj;
1425 request = (MainThreadRequest) ar.userObj;
1426 if (ar.exception != null) {
1427 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1428 } else {
1429 request.result = ((int[]) ar.result)[0];
1430 }
1431 notifyRequester(request);
1432 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001433 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1434 request = (MainThreadRequest) msg.obj;
1435 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1436 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001437 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1438 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001439 break;
1440 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1441 ar = (AsyncResult) msg.obj;
1442 request = (MainThreadRequest) ar.userObj;
1443 request.result = ar.exception == null;
1444 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001445 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001446 case CMD_GET_ALL_CELL_INFO:
1447 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001448 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001449 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001450 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001451 case EVENT_GET_ALL_CELL_INFO_DONE:
1452 ar = (AsyncResult) msg.obj;
1453 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001454 // If a timeout occurs, the response will be null
1455 request.result = (ar.exception == null && ar.result != null)
1456 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001457 synchronized (request) {
1458 request.notifyAll();
1459 }
1460 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001461 case CMD_REQUEST_CELL_INFO_UPDATE:
1462 request = (MainThreadRequest) msg.obj;
1463 request.phone.requestCellInfoUpdate(request.workSource,
1464 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1465 break;
1466 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1467 ar = (AsyncResult) msg.obj;
1468 request = (MainThreadRequest) ar.userObj;
1469 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1470 try {
1471 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001472 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001473 cb.onError(
1474 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1475 ar.exception.getClass().getName(),
1476 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001477 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001478 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001479 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001480 } else {
1481 // use the result as returned
1482 cb.onCellInfo((List<CellInfo>) ar.result);
1483 }
1484 } catch (RemoteException re) {
1485 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1486 }
1487 break;
Sarah Chincc055732020-11-18 13:39:35 -08001488 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001489 request = (MainThreadRequest) msg.obj;
1490 WorkSource ws = (WorkSource) request.argument;
1491 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001492 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001493 break;
Sarah Chincc055732020-11-18 13:39:35 -08001494 }
1495 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001496 ar = (AsyncResult) msg.obj;
1497 request = (MainThreadRequest) ar.userObj;
1498 if (ar.exception == null) {
1499 request.result = ar.result;
1500 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001501 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001502 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001503 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001504 }
1505
1506 synchronized (request) {
1507 request.notifyAll();
1508 }
1509 break;
Sarah Chincc055732020-11-18 13:39:35 -08001510 }
chen xu6dac5ab2018-10-26 17:39:23 -07001511 case CMD_MODEM_REBOOT:
1512 request = (MainThreadRequest) msg.obj;
1513 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001514 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001515 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001516 case EVENT_CMD_MODEM_REBOOT_DONE:
1517 handleNullReturnEvent(msg, "rebootModem");
1518 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001519 case CMD_REQUEST_ENABLE_MODEM:
1520 request = (MainThreadRequest) msg.obj;
1521 boolean enable = (boolean) request.argument;
1522 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001523 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001524 PhoneConfigurationManager.getInstance()
1525 .enablePhone(request.phone, enable, onCompleted);
1526 break;
1527 case EVENT_ENABLE_MODEM_DONE:
1528 ar = (AsyncResult) msg.obj;
1529 request = (MainThreadRequest) ar.userObj;
1530 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001531 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001532 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001533 if ((boolean) request.result) {
1534 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1535 updateModemStateMetrics();
1536 } else {
1537 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1538 + ar.exception);
1539 }
1540 notifyRequester(request);
1541 break;
1542 case CMD_GET_MODEM_STATUS:
1543 request = (MainThreadRequest) msg.obj;
1544 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1545 PhoneConfigurationManager.getInstance()
1546 .getPhoneStatusFromModem(request.phone, onCompleted);
1547 break;
1548 case EVENT_GET_MODEM_STATUS_DONE:
1549 ar = (AsyncResult) msg.obj;
1550 request = (MainThreadRequest) ar.userObj;
1551 int id = request.phone.getPhoneId();
1552 if (ar.exception == null && ar.result != null) {
1553 request.result = ar.result;
1554 //update the cache as modem status has changed
1555 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1556 (boolean) request.result);
1557 } else {
1558 // Return true if modem status cannot be retrieved. For most cases,
1559 // modem status is on. And for older version modems, GET_MODEM_STATUS
1560 // and disable modem are not supported. Modem is always on.
1561 // TODO: this should be fixed in R to support a third
1562 // status UNKNOWN b/131631629
1563 request.result = true;
1564 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1565 + ar.exception);
1566 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001567 notifyRequester(request);
1568 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001569 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1570 request = (MainThreadRequest) msg.obj;
1571 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1572 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1573 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1574 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1575 break;
1576 }
1577 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1578 ar = (AsyncResult) msg.obj;
1579 request = (MainThreadRequest) ar.userObj;
1580 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1581 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1582 args.second.accept(ar.exception == null);
1583 notifyRequester(request);
1584 break;
1585 }
Sarah Chincc055732020-11-18 13:39:35 -08001586 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1587 request = (MainThreadRequest) msg.obj;
1588 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1589 Phone phone = getPhoneFromRequest(request);
1590 if (phone != null) {
1591 phone.getSystemSelectionChannels(onCompleted);
1592 } else {
1593 loge("getSystemSelectionChannels: No phone object");
1594 request.result = new ArrayList<RadioAccessSpecifier>();
1595 notifyRequester(request);
1596 }
1597 break;
1598 }
1599 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1600 ar = (AsyncResult) msg.obj;
1601 request = (MainThreadRequest) ar.userObj;
1602 if (ar.exception == null && ar.result != null) {
1603 request.result = ar.result;
1604 } else {
1605 request.result = new IllegalArgumentException(
1606 "Failed to retrieve system selection channels");
1607 if (ar.result == null) {
1608 loge("getSystemSelectionChannels: Empty response");
1609 } else {
1610 loge("getSystemSelectionChannels: Unknown exception");
1611 }
1612 }
1613 notifyRequester(request);
1614 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001615 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1616 ar = (AsyncResult) msg.obj;
1617 request = (MainThreadRequest) ar.userObj;
1618 if (ar.exception == null && ar.result != null) {
1619 request.result = ar.result;
1620 } else {
1621 request.result = -1;
1622 loge("Failed to set Forbidden Plmns");
1623 if (ar.result == null) {
1624 loge("setForbidenPlmns: Empty response");
1625 } else if (ar.exception != null) {
1626 loge("setForbiddenPlmns: Exception: " + ar.exception);
1627 request.result = -1;
1628 } else {
1629 loge("setForbiddenPlmns: Unknown exception");
1630 }
1631 }
1632 notifyRequester(request);
1633 break;
1634 case CMD_SET_FORBIDDEN_PLMNS:
1635 request = (MainThreadRequest) msg.obj;
1636 uiccCard = getUiccCardFromRequest(request);
1637 if (uiccCard == null) {
1638 loge("setForbiddenPlmns: UiccCard is null");
1639 request.result = -1;
1640 notifyRequester(request);
1641 break;
1642 }
1643 Pair<Integer, List<String>> setFplmnsArgs =
1644 (Pair<Integer, List<String>>) request.argument;
1645 appType = setFplmnsArgs.first;
1646 List<String> fplmns = setFplmnsArgs.second;
1647 uiccApp = uiccCard.getApplicationByType(appType);
1648 if (uiccApp == null) {
1649 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1650 request.result = -1;
1651 loge("Failed to get UICC App");
1652 notifyRequester(request);
1653 } else {
1654 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1655 ((SIMRecords) uiccApp.getIccRecords())
1656 .setForbiddenPlmns(onCompleted, fplmns);
1657 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001658 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001659 case CMD_ERASE_MODEM_CONFIG:
1660 request = (MainThreadRequest) msg.obj;
1661 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1662 defaultPhone.eraseModemConfig(onCompleted);
1663 break;
1664 case EVENT_ERASE_MODEM_CONFIG_DONE:
1665 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001666 break;
zoey chenf95ca592019-12-30 16:11:23 +08001667
1668 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1669 request = (MainThreadRequest) msg.obj;
1670 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1671 Pair<String, String> changed = (Pair<String, String>) request.argument;
1672 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1673 changed.first, changed.second, onCompleted);
1674 break;
1675 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1676 ar = (AsyncResult) msg.obj;
1677 request = (MainThreadRequest) ar.userObj;
1678 if (ar.exception == null) {
1679 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1680 } else {
1681 request.result = msg.arg1;
1682 }
1683 notifyRequester(request);
1684 break;
1685
1686 case CMD_SET_ICC_LOCK_ENABLED:
1687 request = (MainThreadRequest) msg.obj;
1688 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1689 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1690 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1691 enabled.first, enabled.second, onCompleted);
1692 break;
1693 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1694 ar = (AsyncResult) msg.obj;
1695 request = (MainThreadRequest) ar.userObj;
1696 if (ar.exception == null) {
1697 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1698 } else {
1699 request.result = msg.arg1;
1700 }
1701 notifyRequester(request);
1702 break;
1703
Peter Wangdafb9ac2020-01-15 14:13:38 -08001704 case MSG_NOTIFY_USER_ACTIVITY:
1705 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001706 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001707 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1708 getDefaultPhone().getContext().sendBroadcastAsUser(
1709 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1710 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001711
1712 case CMD_SET_DATA_THROTTLING: {
1713 request = (MainThreadRequest) msg.obj;
1714 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1715 DataThrottlingRequest dataThrottlingRequest =
1716 (DataThrottlingRequest) request.argument;
1717 Phone phone = getPhoneFromRequest(request);
1718 if (phone != null) {
1719 phone.setDataThrottling(onCompleted,
1720 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1721 dataThrottlingRequest.getCompletionDurationMillis());
1722 } else {
1723 loge("setDataThrottling: No phone object");
1724 request.result =
1725 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1726 notifyRequester(request);
1727 }
1728
1729 break;
1730 }
1731 case EVENT_SET_DATA_THROTTLING_DONE:
1732 ar = (AsyncResult) msg.obj;
1733 request = (MainThreadRequest) ar.userObj;
1734
1735 if (ar.exception == null) {
1736 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1737 } else if (ar.exception instanceof CommandException) {
1738 loge("setDataThrottling: CommandException: " + ar.exception);
1739 CommandException.Error error =
1740 ((CommandException) (ar.exception)).getCommandError();
1741
1742 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1743 request.result = TelephonyManager
1744 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1745 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1746 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1747 } else {
1748 request.result =
1749 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1750 }
1751 } else {
1752 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1753 }
1754 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1755 notifyRequester(request);
1756 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001757
1758 case CMD_SET_SIM_POWER: {
1759 request = (MainThreadRequest) msg.obj;
1760 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1761 request = (MainThreadRequest) msg.obj;
1762 int stateToSet =
1763 ((Pair<Integer, IIntegerConsumer>)
1764 request.argument).first;
1765 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1766 break;
1767 }
1768 case EVENT_SET_SIM_POWER_DONE: {
1769 ar = (AsyncResult) msg.obj;
1770 request = (MainThreadRequest) ar.userObj;
1771 IIntegerConsumer callback =
1772 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1773 if (ar.exception != null) {
1774 loge("setSimPower exception: " + ar.exception);
1775 int errorCode = TelephonyManager.CallForwardingInfoCallback
1776 .RESULT_ERROR_UNKNOWN;
1777 if (ar.exception instanceof CommandException) {
1778 CommandException.Error error =
1779 ((CommandException) (ar.exception)).getCommandError();
1780 if (error == CommandException.Error.SIM_ERR) {
1781 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1782 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1783 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1784 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1785 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1786 } else {
1787 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1788 }
1789 }
1790 try {
1791 callback.accept(errorCode);
1792 } catch (RemoteException e) {
1793 // Ignore if the remote process is no longer available to call back.
1794 Log.w(LOG_TAG, "setSimPower: callback not available.");
1795 }
1796 } else {
1797 try {
1798 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1799 } catch (RemoteException e) {
1800 // Ignore if the remote process is no longer available to call back.
1801 Log.w(LOG_TAG, "setSimPower: callback not available.");
1802 }
1803 }
1804 break;
1805 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08001806 case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1807 request = (MainThreadRequest) msg.obj;
1808
1809 final Phone phone = getPhoneFromRequest(request);
1810 if (phone == null || phone.getServiceStateTracker() == null) {
1811 request.result = new IllegalStateException("Phone or SST is null");
1812 notifyRequester(request);
1813 break;
1814 }
1815
1816 Pair<Integer, SignalStrengthUpdateRequest> pair =
1817 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1818 onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1819 request);
1820 phone.getServiceStateTracker().setSignalStrengthUpdateRequest(
1821 request.subId, pair.first /*callingUid*/,
1822 pair.second /*request*/, onCompleted);
1823 break;
1824 }
1825 case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1826 ar = (AsyncResult) msg.obj;
1827 request = (MainThreadRequest) ar.userObj;
1828 // request.result will be the exception of ar if present, true otherwise.
1829 // Be cautious not to leave result null which will wait() forever
1830 request.result = ar.exception != null ? ar.exception : true;
1831 notifyRequester(request);
1832 break;
1833 }
1834 case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: {
1835 request = (MainThreadRequest) msg.obj;
1836
1837 Phone phone = getPhoneFromRequest(request);
1838 if (phone == null || phone.getServiceStateTracker() == null) {
1839 request.result = new IllegalStateException("Phone or SST is null");
1840 notifyRequester(request);
1841 break;
1842 }
1843
1844 Pair<Integer, SignalStrengthUpdateRequest> pair =
1845 (Pair<Integer, SignalStrengthUpdateRequest>) request.argument;
1846 onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE,
1847 request);
1848 phone.getServiceStateTracker().clearSignalStrengthUpdateRequest(
1849 request.subId, pair.first /*callingUid*/,
1850 pair.second /*request*/, onCompleted);
1851 break;
1852 }
1853 case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: {
1854 ar = (AsyncResult) msg.obj;
1855 request = (MainThreadRequest) ar.userObj;
1856 request.result = ar.exception != null ? ar.exception : true;
1857 notifyRequester(request);
1858 break;
1859 }
Jordan Liud5366d92020-11-24 14:50:34 -08001860
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001861 default:
1862 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1863 break;
1864 }
1865 }
Jake Hambye994d462014-02-03 13:10:13 -08001866
Pengquan Menga1bb6272018-09-06 09:59:22 -07001867 private void notifyRequester(MainThreadRequest request) {
1868 synchronized (request) {
1869 request.notifyAll();
1870 }
1871 }
1872
Jake Hambye994d462014-02-03 13:10:13 -08001873 private void handleNullReturnEvent(Message msg, String command) {
1874 AsyncResult ar = (AsyncResult) msg.obj;
1875 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1876 if (ar.exception == null) {
1877 request.result = true;
1878 } else {
1879 request.result = false;
1880 if (ar.exception instanceof CommandException) {
1881 loge(command + ": CommandException: " + ar.exception);
1882 } else {
1883 loge(command + ": Unknown exception");
1884 }
1885 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001886 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001887 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001888 }
1889
1890 /**
1891 * Posts the specified command to be executed on the main thread,
1892 * waits for the request to complete, and returns the result.
1893 * @see #sendRequestAsync
1894 */
1895 private Object sendRequest(int command, Object argument) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001896 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null,
1897 null, -1 /*timeoutInMs*/);
vagdeviaf9a5b92018-08-15 16:01:53 -07001898 }
1899
1900 /**
1901 * Posts the specified command to be executed on the main thread,
1902 * waits for the request to complete, and returns the result.
1903 * @see #sendRequestAsync
1904 */
1905 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1906 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Rambo Wang0f050d82021-02-12 11:43:36 -08001907 null, workSource, -1 /*timeoutInMs*/);
Wink Saville36469e72014-06-11 15:17:00 -07001908 }
1909
1910 /**
1911 * Posts the specified command to be executed on the main thread,
1912 * waits for the request to complete, and returns the result.
1913 * @see #sendRequestAsync
1914 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001915 private Object sendRequest(int command, Object argument, Integer subId) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001916 return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/);
1917 }
1918
1919 /**
1920 * Posts the specified command to be executed on the main thread,
1921 * waits for the request to complete for at most {@code timeoutInMs}, and returns the result
1922 * if not timeout or null otherwise.
1923 * @see #sendRequestAsync
1924 */
1925 private @Nullable Object sendRequest(int command, Object argument, Integer subId,
1926 long timeoutInMs) {
1927 return sendRequest(command, argument, subId, null, null, timeoutInMs);
vagdeviaf9a5b92018-08-15 16:01:53 -07001928 }
1929
1930 /**
1931 * Posts the specified command to be executed on the main thread,
1932 * waits for the request to complete, and returns the result.
1933 * @see #sendRequestAsync
1934 */
Nathan Harold92bed182018-10-12 18:16:49 -07001935 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001936 return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001937 }
1938
1939 /**
1940 * Posts the specified command to be executed on the main thread,
1941 * waits for the request to complete, and returns the result.
1942 * @see #sendRequestAsync
1943 */
1944 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001945 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone,
1946 workSource, -1 /*timeoutInMs*/);
Nathan Harold92bed182018-10-12 18:16:49 -07001947 }
1948
1949 /**
Rambo Wang0f050d82021-02-12 11:43:36 -08001950 * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is
1951 * negative, waits for the request to complete, and returns the result. Otherwise, wait for
1952 * maximum of {@code timeoutInMs} milliseconds, interrupt and return null.
Nathan Harold92bed182018-10-12 18:16:49 -07001953 * @see #sendRequestAsync
1954 */
Rambo Wang0f050d82021-02-12 11:43:36 -08001955 private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone,
1956 WorkSource workSource, long timeoutInMs) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001957 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1958 throw new RuntimeException("This method will deadlock if called from the main thread.");
1959 }
1960
Nathan Harold92bed182018-10-12 18:16:49 -07001961 MainThreadRequest request = null;
1962 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1963 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1964 } else if (phone != null) {
1965 request = new MainThreadRequest(argument, phone, workSource);
1966 } else {
1967 request = new MainThreadRequest(argument, subId, workSource);
1968 }
1969
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001970 Message msg = mMainThreadHandler.obtainMessage(command, request);
1971 msg.sendToTarget();
1972
Rambo Wang0f050d82021-02-12 11:43:36 -08001973
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001974 synchronized (request) {
Rambo Wang0f050d82021-02-12 11:43:36 -08001975 if (timeoutInMs >= 0) {
1976 // Wait for at least timeoutInMs before returning null request result
1977 long now = SystemClock.elapsedRealtime();
1978 long deadline = now + timeoutInMs;
1979 while (request == null && now < deadline) {
1980 try {
1981 request.wait(deadline - now);
1982 } catch (InterruptedException e) {
1983 // Do nothing, go back and check if request is completed or timeout
1984 } finally {
1985 now = SystemClock.elapsedRealtime();
1986 }
1987 }
1988 } else {
1989 // Wait for the request to complete
1990 while (request.result == null) {
1991 try {
1992 request.wait();
1993 } catch (InterruptedException e) {
1994 // Do nothing, go back and wait until the request is complete
1995 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001996 }
1997 }
1998 }
Rambo Wang0f050d82021-02-12 11:43:36 -08001999 if (request.result == null) {
2000 Log.wtf(LOG_TAG,
2001 "sendRequest: Blocking command timed out. Something has gone terribly wrong.");
2002 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002003 return request.result;
2004 }
2005
2006 /**
2007 * Asynchronous ("fire and forget") version of sendRequest():
2008 * Posts the specified command to be executed on the main thread, and
2009 * returns immediately.
2010 * @see #sendRequest
2011 */
2012 private void sendRequestAsync(int command) {
2013 mMainThreadHandler.sendEmptyMessage(command);
2014 }
2015
2016 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002017 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002018 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002019 */
2020 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002021 sendRequestAsync(command, argument, null, null);
2022 }
2023
2024 /**
2025 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
2026 * @see {@link #sendRequest(int,Object)}
2027 */
2028 private void sendRequestAsync(
2029 int command, Object argument, Phone phone, WorkSource workSource) {
2030 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002031 Message msg = mMainThreadHandler.obtainMessage(command, request);
2032 msg.sendToTarget();
2033 }
2034
2035 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 * Initialize the singleton PhoneInterfaceManager instance.
2037 * This is only done once, at startup, from PhoneApp.onCreate().
2038 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002039 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 synchronized (PhoneInterfaceManager.class) {
2041 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002042 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002043 } else {
2044 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
2045 }
2046 return sInstance;
2047 }
2048 }
2049
2050 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00002051 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002052 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08002054 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07002055 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
2057 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00002058 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002059 mTelephonySharedPreferences =
2060 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07002061 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07002062 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08002063 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08002064
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002065 publish();
2066 }
2067
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002068 private Phone getDefaultPhone() {
2069 Phone thePhone = getPhone(getDefaultSubscription());
2070 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
2071 }
2072
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 private void publish() {
2074 if (DBG) log("publish: " + this);
2075
Peter Wangc035ce42020-01-08 21:00:22 -08002076 TelephonyFrameworkInitializer
2077 .getTelephonyServiceManager()
2078 .getTelephonyServiceRegisterer()
2079 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002080 }
2081
Stuart Scott584921c2015-01-15 17:10:34 -08002082 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08002083 if (request.phone != null) {
2084 return request.phone;
2085 } else {
2086 return getPhoneFromSubId(request.subId);
2087 }
2088 }
2089
2090 private Phone getPhoneFromSubId(int subId) {
2091 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
2092 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08002093 }
2094
Shishir Agrawalc04d9752016-02-19 10:41:00 -08002095 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
2096 Phone phone = getPhoneFromRequest(request);
2097 return phone == null ? null :
2098 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2099 }
2100
Wink Saville36469e72014-06-11 15:17:00 -07002101 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002102 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002103 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002104 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002105
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002106 private void sendEraseModemConfig(Phone phone) {
2107 if (phone != null) {
2108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2109 mApp, phone.getSubId(), "eraseModemConfig");
2110 final long identity = Binder.clearCallingIdentity();
2111 try {
2112 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2113 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2114 } finally {
2115 Binder.restoreCallingIdentity(identity);
2116 }
2117 }
2118 }
2119
Peter Wang050bb052020-01-13 23:33:09 -08002120 private boolean isImsAvailableOnDevice() {
2121 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2122 if (pm == null) {
2123 // For some reason package manger is not available.. This will fail internally anyway,
2124 // so do not throw error and allow.
2125 return true;
2126 }
2127 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2128 }
2129
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002131 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
Wink Savilleb564aae2014-10-23 10:18:09 -07002134 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 if (DBG) log("dial: " + number);
2136 // No permission check needed here: This is just a wrapper around the
2137 // ACTION_DIAL intent, which is available to any app since it puts up
2138 // the UI before it does anything.
2139
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 String url = createTelUrl(number);
2143 if (url == null) {
2144 return;
2145 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 // PENDING: should we just silently fail if phone is offhook or ringing?
2148 PhoneConstants.State state = mCM.getState(subId);
2149 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2150 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2151 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2152 mApp.startActivity(intent);
2153 }
2154 } finally {
2155 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002156 }
2157 }
2158
2159 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002160 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002161 }
2162
Wink Savilleb564aae2014-10-23 10:18:09 -07002163 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002164 if (DBG) log("call: " + number);
2165
2166 // This is just a wrapper around the ACTION_CALL intent, but we still
2167 // need to do a permission check since we're calling startActivity()
2168 // from the context of the phone app.
2169 enforceCallPermission();
2170
Jordan Liu1617b712019-07-10 15:06:26 -07002171 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 != AppOpsManager.MODE_ALLOWED) {
2173 return;
2174 }
2175
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 String url = createTelUrl(number);
2179 if (url == null) {
2180 return;
2181 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002182
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002183 boolean isValid = false;
2184 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2185 if (slist != null) {
2186 for (SubscriptionInfo subInfoRecord : slist) {
2187 if (subInfoRecord.getSubscriptionId() == subId) {
2188 isValid = true;
2189 break;
2190 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002191 }
Wink Saville08874612014-08-31 19:19:58 -07002192 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193 if (!isValid) {
2194 return;
2195 }
Wink Saville08874612014-08-31 19:19:58 -07002196
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2198 intent.putExtra(SUBSCRIPTION_KEY, subId);
2199 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2200 mApp.startActivity(intent);
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
2203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
Wink Savilleb564aae2014-10-23 10:18:09 -07002206 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002207 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002208 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2209 }
2210
Wink Savilleb564aae2014-10-23 10:18:09 -07002211 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002212 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002213 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2214 }
2215
Wink Savilleb564aae2014-10-23 10:18:09 -07002216 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002218
2219 final long identity = Binder.clearCallingIdentity();
2220 try {
2221 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2222 checkSimPin.start();
2223 return checkSimPin.unlockSim(null, pin);
2224 } finally {
2225 Binder.restoreCallingIdentity(identity);
2226 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002227 }
2228
Wink Savilleb564aae2014-10-23 10:18:09 -07002229 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002230 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002231
2232 final long identity = Binder.clearCallingIdentity();
2233 try {
2234 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2235 checkSimPuk.start();
2236 return checkSimPuk.unlockSim(puk, pin);
2237 } finally {
2238 Binder.restoreCallingIdentity(identity);
2239 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 }
2241
2242 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002243 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002244 * a synchronous one.
2245 */
2246 private static class UnlockSim extends Thread {
2247
2248 private final IccCard mSimCard;
2249
2250 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002251 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2252 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253
2254 // For replies from SimCard interface
2255 private Handler mHandler;
2256
2257 // For async handler to identify request type
2258 private static final int SUPPLY_PIN_COMPLETE = 100;
2259
2260 public UnlockSim(IccCard simCard) {
2261 mSimCard = simCard;
2262 }
2263
2264 @Override
2265 public void run() {
2266 Looper.prepare();
2267 synchronized (UnlockSim.this) {
2268 mHandler = new Handler() {
2269 @Override
2270 public void handleMessage(Message msg) {
2271 AsyncResult ar = (AsyncResult) msg.obj;
2272 switch (msg.what) {
2273 case SUPPLY_PIN_COMPLETE:
2274 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2275 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002276 mRetryCount = msg.arg1;
2277 if (ar.exception != null) {
2278 if (ar.exception instanceof CommandException &&
2279 ((CommandException)(ar.exception)).getCommandError()
2280 == CommandException.Error.PASSWORD_INCORRECT) {
2281 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002282 } //When UiccCardApp dispose,handle message and return exception
2283 else if (ar.exception instanceof CommandException &&
2284 ((CommandException) (ar.exception)).getCommandError()
2285 == CommandException.Error.ABORTED) {
2286 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002287 } else {
2288 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2289 }
2290 } else {
2291 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 mDone = true;
2294 UnlockSim.this.notifyAll();
2295 }
2296 break;
2297 }
2298 }
2299 };
2300 UnlockSim.this.notifyAll();
2301 }
2302 Looper.loop();
2303 }
2304
2305 /*
2306 * Use PIN or PUK to unlock SIM card
2307 *
2308 * If PUK is null, unlock SIM card with PIN
2309 *
2310 * If PUK is not null, unlock SIM card with PUK and set PIN code
2311 */
Wink Saville9de0f752013-10-22 19:04:03 -07002312 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002313
2314 while (mHandler == null) {
2315 try {
2316 wait();
2317 } catch (InterruptedException e) {
2318 Thread.currentThread().interrupt();
2319 }
2320 }
2321 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2322
2323 if (puk == null) {
2324 mSimCard.supplyPin(pin, callback);
2325 } else {
2326 mSimCard.supplyPuk(puk, pin, callback);
2327 }
2328
2329 while (!mDone) {
2330 try {
2331 Log.d(LOG_TAG, "wait for done");
2332 wait();
2333 } catch (InterruptedException e) {
2334 // Restore the interrupted status
2335 Thread.currentThread().interrupt();
2336 }
2337 }
2338 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002339 int[] resultArray = new int[2];
2340 resultArray[0] = mResult;
2341 resultArray[1] = mRetryCount;
2342 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002343 }
2344 }
2345
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002346 /**
2347 * This method has been removed due to privacy and stability concerns.
2348 */
2349 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002350 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002351 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2352 return;
Wink Saville36469e72014-06-11 15:17:00 -07002353 }
2354
Nathan Harold1f889d82020-06-04 17:05:26 -07002355 @Override
2356 public void updateServiceLocationWithPackageName(String callingPackage) {
2357 mApp.getSystemService(AppOpsManager.class)
2358 .checkPackage(Binder.getCallingUid(), callingPackage);
2359
Nathan Haroldf096d982020-11-18 17:18:06 -08002360 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002361 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2362 // Callers targeting S have no business invoking this method.
2363 return;
2364 }
2365
2366 LocationAccessPolicy.LocationPermissionResult locationResult =
2367 LocationAccessPolicy.checkLocationPermission(mApp,
2368 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2369 .setCallingPackage(callingPackage)
2370 .setCallingFeatureId(null)
2371 .setCallingPid(Binder.getCallingPid())
2372 .setCallingUid(Binder.getCallingUid())
2373 .setMethod("updateServiceLocation")
2374 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2375 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2376 .build());
2377 // Apps that lack location permission have no business calling this method;
2378 // however, because no permission was declared in the public API, denials must
2379 // all be "soft".
2380 switch (locationResult) {
2381 case DENIED_HARD: /* fall through */
2382 case DENIED_SOFT:
2383 return;
2384 }
2385
2386 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002387 final long identity = Binder.clearCallingIdentity();
2388 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002389 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002390 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002391 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002392 }
2393 } finally {
2394 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002395 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 }
2397
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002398 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002399 @Override
2400 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002401 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002402 }
2403
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002404
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002405 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002406 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2407 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2408 callingFeatureId);
2409 }
2410
2411 @Deprecated
2412 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002413 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002414 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2415 }
2416
2417 @Override
2418 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2419 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002420 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002421 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002422 return false;
2423 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002424
2425 final long identity = Binder.clearCallingIdentity();
2426 try {
2427 return isRadioOnForSubscriber(subId);
2428 } finally {
2429 Binder.restoreCallingIdentity(identity);
2430 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002431 }
2432
2433 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002434 final long identity = Binder.clearCallingIdentity();
2435 try {
2436 final Phone phone = getPhone(subId);
2437 if (phone != null) {
2438 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2439 } else {
2440 return false;
2441 }
2442 } finally {
2443 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002444 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
2447 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002448 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 }
Wink Saville36469e72014-06-11 15:17:00 -07002450
Wink Savilleb564aae2014-10-23 10:18:09 -07002451 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002452 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002453
2454 final long identity = Binder.clearCallingIdentity();
2455 try {
2456 final Phone phone = getPhone(subId);
2457 if (phone != null) {
2458 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Wink Saville36469e72014-06-11 15:17:00 -07002463 }
2464
2465 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002466 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002467 }
2468
Wink Savilleb564aae2014-10-23 10:18:09 -07002469 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002470 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002471
2472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 final Phone phone = getPhone(subId);
2475 if (phone == null) {
2476 return false;
2477 }
2478 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2479 toggleRadioOnOffForSubscriber(subId);
2480 }
2481 return true;
2482 } finally {
2483 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002484 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002485 }
Wink Saville36469e72014-06-11 15:17:00 -07002486
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002487 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002488 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002489 /*
2490 * If any of the Radios are available, it will need to be
2491 * shutdown. So return true if any Radio is available.
2492 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002493 final long identity = Binder.clearCallingIdentity();
2494 try {
2495 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2496 Phone phone = PhoneFactory.getPhone(i);
2497 if (phone != null && phone.isRadioAvailable()) return true;
2498 }
2499 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2500 return false;
2501 } finally {
2502 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002503 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002504 }
2505
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002506 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002507 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002508 enforceModifyPermission();
2509
2510 final long identity = Binder.clearCallingIdentity();
2511 try {
2512 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2513 logv("Shutting down Phone " + i);
2514 shutdownRadioUsingPhoneId(i);
2515 }
2516 } finally {
2517 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002518 }
2519 }
2520
2521 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002522 Phone phone = PhoneFactory.getPhone(phoneId);
2523 if (phone != null && phone.isRadioAvailable()) {
2524 phone.shutdownRadio();
2525 }
2526 }
2527
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002528 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002529 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002530
2531 final long identity = Binder.clearCallingIdentity();
2532 try {
2533 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2534 if (defaultPhone != null) {
2535 defaultPhone.setRadioPower(turnOn);
2536 return true;
2537 } else {
2538 loge("There's no default phone.");
2539 return false;
2540 }
2541 } finally {
2542 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002543 }
Wink Saville36469e72014-06-11 15:17:00 -07002544 }
2545
Wink Savilleb564aae2014-10-23 10:18:09 -07002546 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002547 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002548
2549 final long identity = Binder.clearCallingIdentity();
2550 try {
2551 final Phone phone = getPhone(subId);
2552 if (phone != null) {
2553 phone.setRadioPower(turnOn);
2554 return true;
2555 } else {
2556 return false;
2557 }
2558 } finally {
2559 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002560 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002561 }
2562
Wink Saville36469e72014-06-11 15:17:00 -07002563 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002564 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002565 public boolean enableDataConnectivity() {
2566 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 int subId = mSubscriptionController.getDefaultDataSubId();
2571 final Phone phone = getPhone(subId);
2572 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002573 phone.getDataEnabledSettings().setDataEnabled(
2574 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002575 return true;
2576 } else {
2577 return false;
2578 }
2579 } finally {
2580 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002581 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002582 }
2583
Wink Saville36469e72014-06-11 15:17:00 -07002584 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002585 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002586 public boolean disableDataConnectivity() {
2587 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002588
2589 final long identity = Binder.clearCallingIdentity();
2590 try {
2591 int subId = mSubscriptionController.getDefaultDataSubId();
2592 final Phone phone = getPhone(subId);
2593 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002594 phone.getDataEnabledSettings().setDataEnabled(
2595 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002596 return true;
2597 } else {
2598 return false;
2599 }
2600 } finally {
2601 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002602 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002603 }
2604
Sanket Padawe356d7632015-06-22 14:03:32 -07002605 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002606 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002607 final long identity = Binder.clearCallingIdentity();
2608 try {
2609 final Phone phone = getPhone(subId);
2610 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002611 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002612 } else {
2613 return false;
2614 }
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002617 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002618 }
2619
2620 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002621 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002622 }
2623
pkanwarae03a6b2016-11-06 20:37:09 -08002624 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002625 enforceCallPermission();
2626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2630 return;
2631 }
2632 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2633 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
pkanwar32d516d2016-10-14 19:37:38 -07002637 };
2638
Wink Savilleb564aae2014-10-23 10:18:09 -07002639 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002640 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641
2642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2645 return false;
2646 }
2647 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002650 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002651 }
2652
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002653 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002654 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002655 }
2656
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002657 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002658 final long identity = Binder.clearCallingIdentity();
2659 try {
2660 Phone phone = PhoneFactory.getPhone(slotIndex);
2661 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2662 PhoneConstantConversions.convertCallState(phone.getState());
2663 } finally {
2664 Binder.restoreCallingIdentity(identity);
2665 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002666 }
2667
Sanket Padawe356d7632015-06-22 14:03:32 -07002668 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002669 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002670 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2671 }
2672
2673 @Override
2674 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002675 final long identity = Binder.clearCallingIdentity();
2676 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002677 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002678 if (phone != null) {
2679 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2680 } else {
2681 return PhoneConstantConversions.convertDataState(
2682 PhoneConstants.DataState.DISCONNECTED);
2683 }
2684 } finally {
2685 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002686 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002687 }
2688
Sanket Padawe356d7632015-06-22 14:03:32 -07002689 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002690 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002691 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2692 }
2693
2694 @Override
2695 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002696 final long identity = Binder.clearCallingIdentity();
2697 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002698 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002699 if (phone != null) {
2700 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2701 } else {
2702 return TelephonyManager.DATA_ACTIVITY_NONE;
2703 }
2704 } finally {
2705 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002707 }
2708
2709 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002710 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002711 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002712 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002713
2714 LocationAccessPolicy.LocationPermissionResult locationResult =
2715 LocationAccessPolicy.checkLocationPermission(mApp,
2716 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2717 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002718 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002719 .setCallingPid(Binder.getCallingPid())
2720 .setCallingUid(Binder.getCallingUid())
2721 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002722 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002723 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2724 .build());
2725 switch (locationResult) {
2726 case DENIED_HARD:
2727 throw new SecurityException("Not allowed to access cell location");
2728 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002729 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2730 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002731 }
2732
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002733 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002734 final long identity = Binder.clearCallingIdentity();
2735 try {
2736 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002737 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002738 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002739 } finally {
2740 Binder.restoreCallingIdentity(identity);
2741 }
Svetoslav64fad262015-04-14 14:35:21 -07002742 }
2743
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 @Override
Jack Yu01425032020-02-22 19:38:58 -08002745 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002746 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2747 // registered cell info, so return a NULL country instead.
2748 final long identity = Binder.clearCallingIdentity();
2749 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002750 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2751 // Get default phone in this case.
2752 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2753 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002754 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002755 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002756 if (phone == null) return "";
2757 ServiceStateTracker sst = phone.getServiceStateTracker();
2758 if (sst == null) return "";
2759 LocaleTracker lt = sst.getLocaleTracker();
2760 if (lt == null) return "";
2761 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2762 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2763 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002764 } finally {
2765 Binder.restoreCallingIdentity(identity);
2766 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002767 }
2768
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002769 /**
2770 * This method was removed due to potential issues caused by performing partial
2771 * updates of service state, and lack of a credible use case.
2772 *
2773 * This has the ability to break the telephony implementation by disabling notification of
2774 * changes in device connectivity. DO NOT USE THIS!
2775 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002776 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 public void enableLocationUpdates() {
2778 mApp.enforceCallingOrSelfPermission(
2779 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 }
2781
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002782 /**
2783 * This method was removed due to potential issues caused by performing partial
2784 * updates of service state, and lack of a credible use case.
2785 *
2786 * This has the ability to break the telephony implementation by disabling notification of
2787 * changes in device connectivity. DO NOT USE THIS!
2788 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002789 @Override
2790 public void disableLocationUpdates() {
2791 mApp.enforceCallingOrSelfPermission(
2792 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002793 }
2794
2795 @Override
2796 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002797 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2798 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002799 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002800 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2801 throw new SecurityException(
2802 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2803 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002804
Jordan Liu1617b712019-07-10 15:06:26 -07002805 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002806 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2807 return null;
2808 }
Svetoslav64fad262015-04-14 14:35:21 -07002809
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002810 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002811
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002813 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814
Nathan Haroldf180aac2018-06-01 18:43:55 -07002815 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2816 for (CellInfo ci : info) {
2817 if (ci instanceof CellInfoGsm) {
2818 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2819 } else if (ci instanceof CellInfoWcdma) {
2820 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002822 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002823 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002824 }
2825
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002826 private List<CellInfo> getCachedCellInfo() {
2827 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2828 for (Phone phone : PhoneFactory.getPhones()) {
2829 List<CellInfo> info = phone.getAllCellInfo();
2830 if (info != null) cellInfos.addAll(info);
2831 }
2832 return cellInfos;
2833 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002834
2835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002836 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002837 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002838 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002839
2840 LocationAccessPolicy.LocationPermissionResult locationResult =
2841 LocationAccessPolicy.checkLocationPermission(mApp,
2842 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2843 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002844 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002845 .setCallingPid(Binder.getCallingPid())
2846 .setCallingUid(Binder.getCallingUid())
2847 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002848 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002849 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2850 .build());
2851 switch (locationResult) {
2852 case DENIED_HARD:
2853 throw new SecurityException("Not allowed to access cell info");
2854 case DENIED_SOFT:
2855 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002856 }
2857
Nathan Haroldf096d982020-11-18 17:18:06 -08002858 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002859 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2860 return getCachedCellInfo();
2861 }
2862
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002863 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002864 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2868 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002869 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002870 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002871 if (info != null) cellInfos.addAll(info);
2872 }
2873 return cellInfos;
2874 } finally {
2875 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877 }
2878
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002879 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002880 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2881 String callingFeatureId) {
2882 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2883 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002884 }
2885
2886 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002887 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2888 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002889 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002890 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002891 }
2892
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002893 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2894 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002895 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002896 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002897
2898 LocationAccessPolicy.LocationPermissionResult locationResult =
2899 LocationAccessPolicy.checkLocationPermission(mApp,
2900 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2901 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002902 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002903 .setCallingPid(Binder.getCallingPid())
2904 .setCallingUid(Binder.getCallingUid())
2905 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002906 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2907 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002908 .build());
2909 switch (locationResult) {
2910 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002911 if (TelephonyPermissions
2912 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002913 // Safetynet logging for b/154934934
2914 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2915 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002916 throw new SecurityException("Not allowed to access cell info");
2917 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002918 if (TelephonyPermissions
2919 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002920 // Safetynet logging for b/154934934
2921 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2922 }
Nathan Harold5320c422019-05-09 10:26:08 -07002923 try {
2924 cb.onCellInfo(new ArrayList<CellInfo>());
2925 } catch (RemoteException re) {
2926 // Drop without consequences
2927 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002928 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002929 }
2930
Nathan Harolda939a962019-05-09 10:13:47 -07002931
2932 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002933 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2934
2935 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2936 }
2937
2938 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002939 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002940 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002941 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942
2943 final long identity = Binder.clearCallingIdentity();
2944 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002945 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002946 } finally {
2947 Binder.restoreCallingIdentity(identity);
2948 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002949 }
2950
Shishir Agrawala9f32182016-04-12 12:00:16 -07002951 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002952 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002953 Phone phone = PhoneFactory.getPhone(slotIndex);
2954 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002955 return null;
2956 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002957 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002958 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002959 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002960 return null;
2961 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002962
2963 final long identity = Binder.clearCallingIdentity();
2964 try {
2965 return phone.getImei();
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002969 }
2970
2971 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002972 public String getTypeAllocationCodeForSlot(int slotIndex) {
2973 Phone phone = PhoneFactory.getPhone(slotIndex);
2974 String tac = null;
2975 if (phone != null) {
2976 String imei = phone.getImei();
2977 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2978 }
2979 return tac;
2980 }
2981
2982 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002983 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002984 Phone phone = PhoneFactory.getPhone(slotIndex);
2985 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002986 return null;
2987 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002988
Jeff Davidson913390f2018-02-23 17:11:49 -08002989 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002990 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002992 return null;
2993 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002994
2995 final long identity = Binder.clearCallingIdentity();
2996 try {
2997 return phone.getMeid();
2998 } finally {
2999 Binder.restoreCallingIdentity(identity);
3000 }
Jack Yu2af8d712017-03-15 17:14:14 -07003001 }
3002
3003 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00003004 public String getManufacturerCodeForSlot(int slotIndex) {
3005 Phone phone = PhoneFactory.getPhone(slotIndex);
3006 String manufacturerCode = null;
3007 if (phone != null) {
3008 String meid = phone.getMeid();
3009 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
3010 }
3011 return manufacturerCode;
3012 }
3013
3014 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003015 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
3016 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003017 Phone phone = PhoneFactory.getPhone(slotIndex);
3018 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003019 return null;
3020 }
Jeff Davidson913390f2018-02-23 17:11:49 -08003021 int subId = phone.getSubId();
3022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003023 mApp, subId, callingPackage, callingFeatureId,
3024 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08003025 return null;
3026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 return phone.getDeviceSvn();
3031 } finally {
3032 Binder.restoreCallingIdentity(identity);
3033 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07003034 }
3035
fionaxu43304da2017-11-27 22:51:16 -08003036 @Override
3037 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 final long identity = Binder.clearCallingIdentity();
3039 try {
3040 final Phone phone = getPhone(subId);
3041 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
3042 } finally {
3043 Binder.restoreCallingIdentity(identity);
3044 }
fionaxu43304da2017-11-27 22:51:16 -08003045 }
3046
3047 @Override
3048 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 final Phone phone = getPhone(subId);
3052 return phone == null ? null : phone.getCarrierName();
3053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
fionaxu43304da2017-11-27 22:51:16 -08003056 }
3057
calvinpanffe225e2018-11-01 19:43:06 +08003058 @Override
chen xu0026ca62019-03-06 15:28:50 -08003059 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08003060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 final Phone phone = getPhone(subId);
3063 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08003064 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
3068 }
3069
3070 @Override
chen xu0026ca62019-03-06 15:28:50 -08003071 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08003072 final long identity = Binder.clearCallingIdentity();
3073 try {
3074 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08003075 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08003076 } finally {
3077 Binder.restoreCallingIdentity(identity);
3078 }
3079 }
3080
chen xu651eec72018-11-11 19:03:44 -08003081 @Override
chen xu864e11c2018-12-06 22:10:03 -08003082 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
3083 if (!isSubscriptionMccMnc) {
3084 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
3085 }
chen xu651eec72018-11-11 19:03:44 -08003086 final Phone phone = PhoneFactory.getPhone(slotIndex);
3087 if (phone == null) {
3088 return TelephonyManager.UNKNOWN_CARRIER_ID;
3089 }
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
3093 } finally {
3094 Binder.restoreCallingIdentity(identity);
3095 }
3096 }
3097
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003098 //
3099 // Internal helper methods.
3100 //
3101
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003102 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003103 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3104 *
3105 * @throws SecurityException if the caller does not have the required permission
3106 */
3107 private void enforceModifyPermission() {
3108 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3109 }
3110
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003111 /**
3112 * Make sure the caller is system.
3113 *
3114 * @throws SecurityException if the caller is not system.
3115 */
Rambo Wanga5cc9b72021-01-07 10:51:54 -08003116 private static void enforceSystemCaller() {
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003117 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3118 throw new SecurityException("Caller must be system");
3119 }
3120 }
3121
Shuo Qianf2b2df42019-11-13 17:43:31 -08003122 private void enforceActiveEmergencySessionPermission() {
3123 mApp.enforceCallingOrSelfPermission(
3124 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3125 }
3126
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003127 /**
3128 * Make sure the caller has the CALL_PHONE permission.
3129 *
3130 * @throws SecurityException if the caller does not have the required permission
3131 */
3132 private void enforceCallPermission() {
3133 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3134 }
3135
paulhu423b5f22019-08-23 19:17:33 +08003136 private void enforceSettingsPermission() {
3137 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003138 }
3139
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003140 private String createTelUrl(String number) {
3141 if (TextUtils.isEmpty(number)) {
3142 return null;
3143 }
3144
Jake Hambye994d462014-02-03 13:10:13 -08003145 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003146 }
3147
Ihab Awadf9e92732013-12-05 18:02:52 -08003148 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003149 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3150 }
3151
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003152 private static void logv(String msg) {
3153 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3154 }
3155
Ihab Awadf9e92732013-12-05 18:02:52 -08003156 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003157 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3158 }
3159
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003160 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003161 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003162 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003163 }
3164
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003166 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003167 final long identity = Binder.clearCallingIdentity();
3168 try {
3169 final Phone phone = PhoneFactory.getPhone(slotIndex);
3170 if (phone == null) {
3171 return PhoneConstants.PHONE_TYPE_NONE;
3172 } else {
3173 return phone.getPhoneType();
3174 }
3175 } finally {
3176 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003177 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003178 }
3179
3180 /**
3181 * Returns the CDMA ERI icon index to display
3182 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003183 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003184 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3185 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3186 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003187 }
3188
Sanket Padawe356d7632015-06-22 14:03:32 -07003189 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003190 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3191 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003192 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003193 mApp, subId, callingPackage, callingFeatureId,
3194 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003195 return -1;
3196 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003197
3198 final long identity = Binder.clearCallingIdentity();
3199 try {
3200 final Phone phone = getPhone(subId);
3201 if (phone != null) {
3202 return phone.getCdmaEriIconIndex();
3203 } else {
3204 return -1;
3205 }
3206 } finally {
3207 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003208 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003209 }
3210
3211 /**
3212 * Returns the CDMA ERI icon mode,
3213 * 0 - ON
3214 * 1 - FLASHING
3215 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003216 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003217 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3218 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3219 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003220 }
3221
Sanket Padawe356d7632015-06-22 14:03:32 -07003222 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003223 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3224 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003225 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003226 mApp, subId, callingPackage, callingFeatureId,
3227 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003228 return -1;
3229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
3233 final Phone phone = getPhone(subId);
3234 if (phone != null) {
3235 return phone.getCdmaEriIconMode();
3236 } else {
3237 return -1;
3238 }
3239 } finally {
3240 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003241 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003242 }
3243
3244 /**
3245 * Returns the CDMA ERI text,
3246 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003247 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003248 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3249 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3250 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003251 }
3252
Sanket Padawe356d7632015-06-22 14:03:32 -07003253 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003254 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3255 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003256 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003257 mApp, subId, callingPackage, callingFeatureId,
3258 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003259 return null;
3260 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003261
3262 final long identity = Binder.clearCallingIdentity();
3263 try {
3264 final Phone phone = getPhone(subId);
3265 if (phone != null) {
3266 return phone.getCdmaEriText();
3267 } else {
3268 return null;
3269 }
3270 } finally {
3271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003273 }
3274
3275 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003276 * Returns the CDMA MDN.
3277 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003278 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003279 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003280 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3281 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003286 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003287 return phone.getLine1Number();
3288 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290 return null;
3291 }
3292 } finally {
3293 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003294 }
3295 }
3296
3297 /**
3298 * Returns the CDMA MIN.
3299 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003300 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003301 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3303 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
3305 final long identity = Binder.clearCallingIdentity();
3306 try {
3307 final Phone phone = getPhone(subId);
3308 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3309 return phone.getCdmaMin();
3310 } else {
3311 return null;
3312 }
3313 } finally {
3314 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003315 }
3316 }
3317
Hall Liud892bec2018-11-30 14:51:45 -08003318 @Override
3319 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3320 INumberVerificationCallback callback, String callingPackage) {
3321 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3322 != PERMISSION_GRANTED) {
3323 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3324 }
3325 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3326
3327 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3328 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
Hall Liub9d8feb2021-01-13 10:28:04 -08003329 throw new SecurityException("Calling package must be configured in the device config: "
3330 + "calling package: " + callingPackage
3331 + ", configured package: " + authorizedPackage);
Hall Liud892bec2018-11-30 14:51:45 -08003332 }
3333
3334 if (range == null) {
3335 throw new NullPointerException("Range must be non-null");
3336 }
3337
3338 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003339 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003340
3341 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3342 }
3343
Junda Liuca05d5d2014-08-14 22:36:34 -07003344 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003345 * Returns true if CDMA provisioning needs to run.
3346 */
3347 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003348 final long identity = Binder.clearCallingIdentity();
3349 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003350 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003351 } finally {
3352 Binder.restoreCallingIdentity(identity);
3353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003354 }
3355
3356 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003357 * Sets the voice mail number of a given subId.
3358 */
3359 @Override
3360 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003361 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3362 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003363
3364 final long identity = Binder.clearCallingIdentity();
3365 try {
3366 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3367 new Pair<String, String>(alphaTag, number), new Integer(subId));
3368 return success;
3369 } finally {
3370 Binder.restoreCallingIdentity(identity);
3371 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003372 }
3373
Ta-wei Yen87c49842016-05-13 21:19:52 -07003374 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003375 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3376 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003377 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3378 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003379 if (!TextUtils.equals(callingPackage, systemDialer)) {
3380 throw new SecurityException("caller must be system dialer");
3381 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003382
3383 final long identity = Binder.clearCallingIdentity();
3384 try {
3385 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3386 if (phoneAccountHandle == null) {
3387 return null;
3388 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003389 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003390 } finally {
3391 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003392 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003393 }
3394
3395 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003396 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3397 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003398 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003399 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003400 mApp, subId, callingPackage, callingFeatureId,
3401 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003402 return null;
3403 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003404
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003405 final long identity = Binder.clearCallingIdentity();
3406 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003407 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003408 } finally {
3409 Binder.restoreCallingIdentity(identity);
3410 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003411 }
3412
3413 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003414 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3415 VisualVoicemailSmsFilterSettings settings) {
3416 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003417
3418 final long identity = Binder.clearCallingIdentity();
3419 try {
3420 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003421 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003422 } finally {
3423 Binder.restoreCallingIdentity(identity);
3424 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003425 }
3426
3427 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003428 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3429 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003430
3431 final long identity = Binder.clearCallingIdentity();
3432 try {
3433 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003434 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003435 } finally {
3436 Binder.restoreCallingIdentity(identity);
3437 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003438 }
3439
3440 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003441 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3442 String callingPackage, int subId) {
3443 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003444
3445 final long identity = Binder.clearCallingIdentity();
3446 try {
3447 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003448 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 } finally {
3450 Binder.restoreCallingIdentity(identity);
3451 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003452 }
3453
3454 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003455 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003457
3458 final long identity = Binder.clearCallingIdentity();
3459 try {
3460 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003461 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003462 } finally {
3463 Binder.restoreCallingIdentity(identity);
3464 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003465 }
3466
3467 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003468 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3469 String callingAttributionTag, int subId, String number, int port, String text,
3470 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003471 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003472 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003473 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003474 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003475 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3476 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003477 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003478
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003479 /**
fionaxu0152e512016-11-14 13:36:14 -08003480 * Sets the voice activation state of a given subId.
3481 */
3482 @Override
3483 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003484 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3485 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003486
3487 final long identity = Binder.clearCallingIdentity();
3488 try {
3489 final Phone phone = getPhone(subId);
3490 if (phone != null) {
3491 phone.setVoiceActivationState(activationState);
3492 } else {
3493 loge("setVoiceActivationState fails with invalid subId: " + subId);
3494 }
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003497 }
3498 }
3499
3500 /**
3501 * Sets the data activation state of a given subId.
3502 */
3503 @Override
3504 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3506 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003507
3508 final long identity = Binder.clearCallingIdentity();
3509 try {
3510 final Phone phone = getPhone(subId);
3511 if (phone != null) {
3512 phone.setDataActivationState(activationState);
3513 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003514 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515 }
3516 } finally {
3517 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003518 }
3519 }
3520
3521 /**
3522 * Returns the voice activation state of a given subId.
3523 */
3524 @Override
3525 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003527
fionaxu0152e512016-11-14 13:36:14 -08003528 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 if (phone != null) {
3532 return phone.getVoiceActivationState();
3533 } else {
3534 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3535 }
3536 } finally {
3537 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003538 }
3539 }
3540
3541 /**
3542 * Returns the data activation state of a given subId.
3543 */
3544 @Override
3545 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003547
fionaxu0152e512016-11-14 13:36:14 -08003548 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003549 final long identity = Binder.clearCallingIdentity();
3550 try {
3551 if (phone != null) {
3552 return phone.getDataActivationState();
3553 } else {
3554 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3555 }
3556 } finally {
3557 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003558 }
3559 }
3560
3561 /**
Wink Saville36469e72014-06-11 15:17:00 -07003562 * Returns the unread count of voicemails for a subId
3563 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003564 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003565 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3566 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003567 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003568 mApp, subId, callingPackage, callingFeatureId,
3569 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003570 return 0;
3571 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003572 final long identity = Binder.clearCallingIdentity();
3573 try {
3574 final Phone phone = getPhone(subId);
3575 if (phone != null) {
3576 return phone.getVoiceMessageCount();
3577 } else {
3578 return 0;
3579 }
3580 } finally {
3581 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003582 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003583 }
3584
3585 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003586 * returns true, if the device is in a state where both voice and data
3587 * are supported simultaneously. This can change based on location or network condition.
3588 */
3589 @Override
3590 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003591 final long identity = Binder.clearCallingIdentity();
3592 try {
3593 final Phone phone = getPhone(subId);
3594 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003598 }
3599
3600 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003601 * Send the dialer code if called from the current default dialer or the caller has
3602 * carrier privilege.
3603 * @param inputCode The dialer code to send
3604 */
3605 @Override
3606 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003608 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003609 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3610 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003611 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003612 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003613 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003614 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003615
3616 final long identity = Binder.clearCallingIdentity();
3617 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003618 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003619 } finally {
3620 Binder.restoreCallingIdentity(identity);
3621 }
fionaxu235cc5e2017-03-06 22:25:57 -08003622 }
3623
Pengquan Menga1bb6272018-09-06 09:59:22 -07003624 @Override
3625 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003626 TelephonyPermissions
3627 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3628 mApp, subId, "getNetworkSelectionMode");
3629 final long identity = Binder.clearCallingIdentity();
3630 try {
3631 if (!isActiveSubscription(subId)) {
3632 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3633 }
3634 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3635 } finally {
3636 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003637 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003638 }
3639
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003641 public boolean isInEmergencySmsMode() {
3642 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 for (Phone phone : PhoneFactory.getPhones()) {
3646 if (phone.isInEmergencySmsMode()) {
3647 return true;
3648 }
3649 }
3650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 return false;
3654 }
3655
shilu366312e2019-12-17 09:28:10 -08003656 /**
3657 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3658 * @param subId The subscription to use to check the configuration.
3659 * @param c The callback that will be used to send the result.
3660 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003661 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003662 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3663 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003664 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3665 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003666
Brad Ebinger77b832e2019-10-17 17:03:22 -07003667 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3668 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3669 "IMS not available on device.");
3670 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 final long token = Binder.clearCallingIdentity();
3672 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003673 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003674 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003676 } catch (ImsException e) {
3677 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003678 } finally {
3679 Binder.restoreCallingIdentity(token);
3680 }
3681 }
3682
shilu366312e2019-12-17 09:28:10 -08003683 /**
3684 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3685 * @param subId The subscription to use to check the configuration.
3686 * @param c The callback that will be used to send the result.
3687 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003688 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003689 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003690 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3691 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003692 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3693 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3694 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003695 final long token = Binder.clearCallingIdentity();
3696 try {
3697 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3698 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3699 .removeRegistrationCallbackForSubscription(c, subId);
3700 } catch (ImsException e) {
3701 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3702 + "is inactive, ignoring unregister.");
3703 // If the subscription is no longer active, just return, since the callback
3704 // will already have been removed internally.
3705 } finally {
3706 Binder.restoreCallingIdentity(token);
3707 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 }
3709
Brad Ebinger774ba362019-10-22 17:36:18 -07003710 /**
3711 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3712 */
3713 @Override
3714 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3715 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3716 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3718 "IMS not available on device.");
3719 }
3720 final long token = Binder.clearCallingIdentity();
3721 try {
3722 Phone phone = getPhone(subId);
3723 if (phone == null) {
3724 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3725 + subId + "'");
3726 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3727 }
3728 phone.getImsRegistrationState(regState -> {
3729 try {
3730 consumer.accept((regState == null)
3731 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3732 } catch (RemoteException e) {
3733 // Ignore if the remote process is no longer available to call back.
3734 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3735 }
3736 });
3737 } finally {
3738 Binder.restoreCallingIdentity(token);
3739 }
3740 }
3741
3742 /**
3743 * Get the transport type for the IMS service registration state.
3744 */
3745 @Override
3746 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003747 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3748 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003749 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3750 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3751 "IMS not available on device.");
3752 }
3753 final long token = Binder.clearCallingIdentity();
3754 try {
3755 Phone phone = getPhone(subId);
3756 if (phone == null) {
3757 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3758 + subId + "'");
3759 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3760 }
3761 phone.getImsRegistrationTech(regTech -> {
3762 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3763 int regTechConverted = (regTech == null)
3764 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3765 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3766 regTechConverted);
3767 try {
3768 consumer.accept(regTechConverted);
3769 } catch (RemoteException e) {
3770 // Ignore if the remote process is no longer available to call back.
3771 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3772 }
3773 });
3774 } finally {
3775 Binder.restoreCallingIdentity(token);
3776 }
3777 }
3778
shilu366312e2019-12-17 09:28:10 -08003779 /**
3780 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3781 * @param subId The subscription to use to check the configuration.
3782 * @param c The callback that will be used to send the result.
3783 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003784 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003785 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3786 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003787 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3788 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003789 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3790 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3791 "IMS not available on device.");
3792 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003793 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3794 final long token = Binder.clearCallingIdentity();
3795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003796 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003797 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003798 } catch (ImsException e) {
3799 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003800 } finally {
3801 Binder.restoreCallingIdentity(token);
3802 }
3803 }
3804
shilu366312e2019-12-17 09:28:10 -08003805 /**
3806 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3807 * @param subId The subscription to use to check the configuration.
3808 * @param c The callback that will be used to send the result.
3809 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003811 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003812 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3813 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003814 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3815 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3816 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003817
3818 final long token = Binder.clearCallingIdentity();
3819 try {
3820 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3821 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003822 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003823 } catch (ImsException e) {
3824 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3825 + "is inactive, ignoring unregister.");
3826 // If the subscription is no longer active, just return, since the callback
3827 // will already have been removed internally.
3828 } finally {
3829 Binder.restoreCallingIdentity(token);
3830 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 }
3832
3833 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003834 public boolean isCapable(int subId, int capability, int regTech) {
3835 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003836 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3837 final long token = Binder.clearCallingIdentity();
3838 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003839 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003840 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003841 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003842 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3843 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003844 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003845 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3846 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 } finally {
3848 Binder.restoreCallingIdentity(token);
3849 }
3850 }
3851
3852 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003853 public boolean isAvailable(int subId, int capability, int regTech) {
3854 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003855 final long token = Binder.clearCallingIdentity();
3856 try {
3857 Phone phone = getPhone(subId);
3858 if (phone == null) return false;
3859 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003860 } catch (com.android.ims.ImsException e) {
3861 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3862 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003863 } finally {
3864 Binder.restoreCallingIdentity(token);
3865 }
3866 }
3867
Brad Ebinger77b832e2019-10-17 17:03:22 -07003868 /**
3869 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3870 * subscription.
3871 * @param subId The subscription to use to check the configuration.
3872 * @param callback The callback that will be used to send the result.
3873 * @param capability The MmTelFeature capability that will be used to send the result.
3874 * @param transportType The transport type of the MmTelFeature capability.
3875 */
3876 @Override
3877 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3878 int transportType) {
3879 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3880 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3881 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3882 "IMS not available on device.");
3883 }
3884 final long token = Binder.clearCallingIdentity();
3885 try {
3886 int slotId = getSlotIndex(subId);
3887 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3888 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3889 + subId + "'");
3890 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3891 }
3892 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3893 transportType, aBoolean -> {
3894 try {
3895 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3896 } catch (RemoteException e) {
3897 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3898 + "running. Ignore");
3899 }
3900 });
3901 } finally {
3902 Binder.restoreCallingIdentity(token);
3903 }
3904 }
3905
shilu366312e2019-12-17 09:28:10 -08003906 /**
3907 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3908 * @param subId The subscription to use to check the configuration.
3909 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003910 @Override
3911 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003912 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3913 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003914
Brad Ebinger35c841c2018-10-01 10:40:55 -07003915 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3916 final long token = Binder.clearCallingIdentity();
3917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003918 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003919 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003920 } catch (ImsException e) {
3921 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003922 } finally {
3923 Binder.restoreCallingIdentity(token);
3924 }
3925 }
3926
3927 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003928 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003929 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003930 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003931 final long identity = Binder.clearCallingIdentity();
3932 try {
3933 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003934 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003935 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003936 } catch (ImsException e) {
3937 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003938 } finally {
3939 Binder.restoreCallingIdentity(identity);
3940 }
3941 }
3942
shilu366312e2019-12-17 09:28:10 -08003943 /**
3944 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3945 * @param subId The subscription to use to check the configuration.
3946 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003947 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003948 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003949 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3950 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003951 final long identity = Binder.clearCallingIdentity();
3952 try {
3953 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003954 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3955 } catch (ImsException e) {
3956 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003957 } finally {
3958 Binder.restoreCallingIdentity(identity);
3959 }
3960 }
3961
3962 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003963 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003964 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003965 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003966 final long identity = Binder.clearCallingIdentity();
3967 try {
3968 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003969 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003970 } catch (ImsException e) {
3971 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 } finally {
3973 Binder.restoreCallingIdentity(identity);
3974 }
3975 }
3976
shilu366312e2019-12-17 09:28:10 -08003977 /**
3978 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3979 * @param subId The subscription to use to check the configuration.
3980 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003981 @Override
3982 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003983 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3984 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003985 final long identity = Binder.clearCallingIdentity();
3986 try {
3987 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003988 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003989 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003990 } catch (ImsException e) {
3991 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 } finally {
3993 Binder.restoreCallingIdentity(identity);
3994 }
3995 }
3996
3997 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003998 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003999 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004000 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004001 final long identity = Binder.clearCallingIdentity();
4002 try {
4003 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004004 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004005 } catch (ImsException e) {
4006 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 } finally {
4008 Binder.restoreCallingIdentity(identity);
4009 }
4010 }
4011
shilu366312e2019-12-17 09:28:10 -08004012 /**
4013 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4014 * @param subId The subscription to use to check the configuration.
4015 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004016 @Override
4017 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004018 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4019 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004020 final long identity = Binder.clearCallingIdentity();
4021 try {
4022 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004023 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004024 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004025 } catch (ImsException e) {
4026 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004027 } finally {
4028 Binder.restoreCallingIdentity(identity);
4029 }
4030 }
4031
4032 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08004033 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004034 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08004035 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004036 final long identity = Binder.clearCallingIdentity();
4037 try {
4038 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004039 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004040 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004041 } catch (ImsException e) {
4042 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004043 } finally {
4044 Binder.restoreCallingIdentity(identity);
4045 }
4046 }
4047
4048 @Override
4049 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
4050 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4051 "setVoWiFiNonPersistent");
4052 final long identity = Binder.clearCallingIdentity();
4053 try {
4054 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004055 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07004056 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004057 } catch (ImsException e) {
4058 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004059 } finally {
4060 Binder.restoreCallingIdentity(identity);
4061 }
4062 }
4063
shilu366312e2019-12-17 09:28:10 -08004064 /**
4065 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4066 * @param subId The subscription to use to check the configuration.
4067 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004068 @Override
4069 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004070 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4071 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004072 final long identity = Binder.clearCallingIdentity();
4073 try {
4074 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004075 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004076 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004077 } catch (ImsException e) {
4078 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004079 } finally {
4080 Binder.restoreCallingIdentity(identity);
4081 }
4082 }
4083
4084 @Override
4085 public void setVoWiFiModeSetting(int subId, int mode) {
4086 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4087 "setVoWiFiModeSetting");
4088 final long identity = Binder.clearCallingIdentity();
4089 try {
4090 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004091 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004092 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004093 } catch (ImsException e) {
4094 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004095 } finally {
4096 Binder.restoreCallingIdentity(identity);
4097 }
4098 }
4099
4100 @Override
4101 public int getVoWiFiRoamingModeSetting(int subId) {
4102 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4103 final long identity = Binder.clearCallingIdentity();
4104 try {
4105 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004106 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004107 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004108 } catch (ImsException e) {
4109 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004110 } finally {
4111 Binder.restoreCallingIdentity(identity);
4112 }
4113 }
4114
4115 @Override
4116 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4117 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4118 "setVoWiFiRoamingModeSetting");
4119 final long identity = Binder.clearCallingIdentity();
4120 try {
4121 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004122 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004123 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004124 } catch (ImsException e) {
4125 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004126 } finally {
4127 Binder.restoreCallingIdentity(identity);
4128 }
4129 }
4130
4131 @Override
4132 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4133 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4134 "setRttCapabilityEnabled");
4135 final long identity = Binder.clearCallingIdentity();
4136 try {
4137 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4139 } catch (ImsException e) {
4140 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004141 } finally {
4142 Binder.restoreCallingIdentity(identity);
4143 }
4144 }
4145
shilu366312e2019-12-17 09:28:10 -08004146 /**
4147 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4148 * @param subId The subscription to use to check the configuration.
4149 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004150 @Override
4151 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004152 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4153 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004154 final long identity = Binder.clearCallingIdentity();
4155 try {
4156 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004157 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004158 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (ImsException e) {
4160 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004161 } finally {
4162 Binder.restoreCallingIdentity(identity);
4163 }
4164 }
4165
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 @Override
4167 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4168 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004171 if (!isImsAvailableOnDevice()) {
4172 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4173 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004174 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004175 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004176 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004177 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004178 } catch (ImsException e) {
4179 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004180 } finally {
4181 Binder.restoreCallingIdentity(identity);
4182 }
4183 }
4184
4185 @Override
4186 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4187 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4188 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004189 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4190 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4191 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004192 try {
4193 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004194 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004195 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004196 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004197 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4198 + "is inactive, ignoring unregister.");
4199 // If the subscription is no longer active, just return, since the callback will already
4200 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004201 } finally {
4202 Binder.restoreCallingIdentity(identity);
4203 }
4204 }
4205
allenwtsu99c623b2020-01-03 18:24:23 +08004206
4207 private void checkModifyPhoneStatePermission(int subId, String message) {
4208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4209 message);
4210 }
4211
4212 private boolean isImsProvisioningRequired(int subId, int capability,
4213 boolean isMmtelCapability) {
4214 Phone phone = getPhone(subId);
4215 if (phone == null) {
4216 loge("phone instance null for subid " + subId);
4217 return false;
4218 }
4219 if (isMmtelCapability) {
4220 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4221 return false;
4222 }
4223 } else {
4224 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4225 return false;
4226 }
4227 }
4228 return true;
4229 }
4230
4231 @Override
4232 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4233 boolean isProvisioned) {
4234 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4235
4236 final long identity = Binder.clearCallingIdentity();
4237 try {
4238 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4239 if (!isImsProvisioningRequired(subId, capability, false)) {
4240 return;
4241 }
4242
4243 // this capability requires provisioning, route to the correct API.
4244 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4245 switch (capability) {
4246 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4247 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4248 ims.setEabProvisioned(isProvisioned);
4249 break;
4250 default: {
4251 throw new IllegalArgumentException("Tried to set provisioning for "
4252 + "rcs capability '" + capability + "', which does not require "
4253 + "provisioning.");
4254 }
4255 }
4256 } finally {
4257 Binder.restoreCallingIdentity(identity);
4258 }
4259
4260 }
4261
4262
4263 @Override
4264 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4265 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4266 final long identity = Binder.clearCallingIdentity();
4267 try {
4268 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4269 if (!isImsProvisioningRequired(subId, capability, false)) {
4270 return true;
4271 }
4272
4273 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4274 switch (capability) {
4275 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4276 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4277 return ims.isEabProvisionedOnDevice();
4278
4279 default: {
4280 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4281 + "capability '" + capability + "', which does not require "
4282 + "provisioning.");
4283 }
4284 }
4285
4286 } finally {
4287 Binder.restoreCallingIdentity(identity);
4288 }
4289 }
4290
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004291 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004292 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4293 boolean isProvisioned) {
4294 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4295 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4296 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4297 }
allenwtsu99c623b2020-01-03 18:24:23 +08004298 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004299 final long identity = Binder.clearCallingIdentity();
4300 try {
4301 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004302 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004303 return;
4304 }
4305
4306 // this capability requires provisioning, route to the correct API.
4307 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4308 switch (capability) {
4309 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4310 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4311 ims.setVolteProvisioned(isProvisioned);
4312 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4313 ims.setWfcProvisioned(isProvisioned);
4314 }
4315 break;
4316 }
4317 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4318 // There is currently no difference in VT provisioning type.
4319 ims.setVtProvisioned(isProvisioned);
4320 break;
4321 }
4322 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4323 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4324 // change the capability of the feature instead if needed.
4325 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4326 == isProvisioned) {
4327 // No change in provisioning.
4328 return;
4329 }
4330 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4331 try {
4332 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004333 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004334 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4335 + ", Exception" + e.getMessage());
4336 }
4337 break;
4338 }
4339 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004340 throw new IllegalArgumentException("Tried to set provisioning for "
4341 + "MmTel capability '" + capability + "', which does not require "
4342 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004343 }
4344 }
4345
4346 } finally {
4347 Binder.restoreCallingIdentity(identity);
4348 }
4349 }
4350
4351 @Override
4352 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4353 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4354 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4355 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4356 }
4357 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4358 final long identity = Binder.clearCallingIdentity();
4359 try {
4360 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004361 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004362 return true;
4363 }
4364
4365 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4366 switch (capability) {
4367 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4368 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4369 return ims.isVolteProvisionedOnDevice();
4370 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4371 return ims.isWfcProvisionedOnDevice();
4372 }
4373 // This should never happen, since we are checking tech above to make sure it
4374 // is either LTE or IWLAN.
4375 throw new IllegalArgumentException("Invalid radio technology for voice "
4376 + "capability.");
4377 }
4378 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4379 // There is currently no difference in VT provisioning type.
4380 return ims.isVtProvisionedOnDevice();
4381 }
4382 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4383 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4384 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4385 }
4386 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004387 throw new IllegalArgumentException(
4388 "Tried to get provisioning for MmTel capability '" + capability
4389 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004390 }
4391 }
4392
4393 } finally {
4394 Binder.restoreCallingIdentity(identity);
4395 }
4396 }
4397
4398 @Override
4399 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4400 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4401 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4402 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4403 }
4404 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4405 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4406 return (provisionedBits & capability) > 0;
4407 }
4408
4409 @Override
4410 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4411 boolean isProvisioned) {
4412 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4413 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4414 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4415 }
4416 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4417 "setProvisioningStatusForCapability");
4418 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4419 // If the current provisioning status for capability already matches isProvisioned,
4420 // do nothing.
4421 if (((provisionedBits & capability) > 0) == isProvisioned) {
4422 return;
4423 }
4424 if (isProvisioned) {
4425 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4426 } else {
4427 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4428 }
4429 }
4430
4431 /**
4432 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4433 * technology. The bitfield should mirror the bitfield defined by
4434 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4435 */
4436 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4437 String key = getMmTelProvisioningKey(subId, tech);
4438 // Default is no capabilities are provisioned.
4439 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4440 }
4441
4442 /**
4443 * Sets the MmTel capability provisioning bitfield (defined by
4444 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4445 * technology specified.
4446 *
4447 * Note: This is a synchronous command and should not be called on UI thread.
4448 */
4449 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4450 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4451 String key = getMmTelProvisioningKey(subId, tech);
4452 editor.putInt(key, newField);
4453 editor.commit();
4454 }
4455
4456 private static String getMmTelProvisioningKey(int subId, int tech) {
4457 // resulting key is provision_ims_mmtel_{subId}_{tech}
4458 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4459 }
4460
4461 /**
4462 * Query CarrierConfig to see if the specified capability requires provisioning for the
4463 * carrier associated with the subscription id.
4464 */
4465 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4466 int capability) {
4467 CarrierConfigManager configManager = new CarrierConfigManager(context);
4468 PersistableBundle c = configManager.getConfigForSubId(subId);
4469 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004470 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004471 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4472 false);
4473 boolean requireVoiceVtProvisioning = c.getBoolean(
4474 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4475
4476 // First check to make sure that the capability requires provisioning.
4477 switch (capability) {
4478 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4479 // intentional fallthrough
4480 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4481 if (requireVoiceVtProvisioning) {
4482 // Voice and Video requires provisioning
4483 return true;
4484 }
4485 break;
4486 }
4487 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4488 if (requireUtProvisioning) {
4489 // UT requires provisioning
4490 return true;
4491 }
4492 break;
4493 }
4494 }
4495 return false;
4496 }
4497
allenwtsu99c623b2020-01-03 18:24:23 +08004498 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4499 int capability) {
4500 CarrierConfigManager configManager = new CarrierConfigManager(context);
4501 PersistableBundle c = configManager.getConfigForSubId(subId);
4502
4503 boolean requireRcsProvisioning = c.getBoolean(
4504 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4505
4506 // First check to make sure that the capability requires provisioning.
4507 switch (capability) {
4508 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4509 // intentional fallthrough
4510 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4511 if (requireRcsProvisioning) {
4512 // OPTION or PRESENCE requires provisioning
4513 return true;
4514 }
4515 break;
4516 }
4517 }
4518 return false;
4519 }
4520
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004521 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004522 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004523 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4524 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4525 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004526 enforceReadPrivilegedPermission("getImsProvisioningInt");
4527 final long identity = Binder.clearCallingIdentity();
4528 try {
4529 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004530 int slotId = getSlotIndex(subId);
4531 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4532 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4533 + subId + "' for key:" + key);
4534 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4535 }
4536 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004537 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004538 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4539 + subId + "' for key:" + key);
4540 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004541 } finally {
4542 Binder.restoreCallingIdentity(identity);
4543 }
4544 }
4545
4546 @Override
4547 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4549 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4550 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004551 enforceReadPrivilegedPermission("getImsProvisioningString");
4552 final long identity = Binder.clearCallingIdentity();
4553 try {
4554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004555 int slotId = getSlotIndex(subId);
4556 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4557 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4558 + subId + "' for key:" + key);
4559 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4560 }
4561 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004562 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004563 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4564 + subId + "' for key:" + key);
4565 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004566 } finally {
4567 Binder.restoreCallingIdentity(identity);
4568 }
4569 }
4570
4571 @Override
4572 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004573 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4574 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4575 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004576 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4577 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004578 final long identity = Binder.clearCallingIdentity();
4579 try {
4580 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004581 int slotId = getSlotIndex(subId);
4582 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4583 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4584 + subId + "' for key:" + key);
4585 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4586 }
4587 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004588 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004589 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4590 + "' for key:" + key);
4591 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004592 } finally {
4593 Binder.restoreCallingIdentity(identity);
4594 }
4595 }
4596
4597 @Override
4598 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004599 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4600 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4601 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4603 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004604 final long identity = Binder.clearCallingIdentity();
4605 try {
4606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004607 int slotId = getSlotIndex(subId);
4608 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4609 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4610 + subId + "' for key:" + key);
4611 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4612 }
4613 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004614 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004615 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4616 + "' for key:" + key);
4617 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004618 } finally {
4619 Binder.restoreCallingIdentity(identity);
4620 }
4621 }
4622
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004623 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004624 int slotId = SubscriptionManager.getSlotIndex(subId);
4625 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004626 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4627 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004628 }
4629 return slotId;
4630 }
4631
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004632 private int getSlotIndex(int subId) {
4633 int slotId = SubscriptionManager.getSlotIndex(subId);
4634 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4635 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4636 }
4637 return slotId;
4638 }
4639
Wink Saville36469e72014-06-11 15:17:00 -07004640 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004641 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004642 */
4643 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004644 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4645 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004646 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004647 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004648 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004649 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004650 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004651 mApp, subId, callingPackage, callingFeatureId,
4652 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004653 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4654 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 final long identity = Binder.clearCallingIdentity();
4657 try {
4658 final Phone phone = getPhone(subId);
4659 if (phone != null) {
4660 return phone.getServiceState().getDataNetworkType();
4661 } else {
4662 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4663 }
4664 } finally {
4665 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004666 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004667 }
4668
4669 /**
4670 * Returns the data network type
4671 */
4672 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004673 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4674 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4675 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004676 }
4677
4678 /**
4679 * Returns the data network type for a subId
4680 */
4681 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004682 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4683 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004684 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004685 mApp, subId, callingPackage, callingFeatureId,
4686 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004687 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4688 }
4689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004690 final long identity = Binder.clearCallingIdentity();
4691 try {
4692 final Phone phone = getPhone(subId);
4693 if (phone != null) {
4694 return phone.getServiceState().getDataNetworkType();
4695 } else {
4696 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4697 }
4698 } finally {
4699 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004700 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004701 }
4702
4703 /**
Wink Saville36469e72014-06-11 15:17:00 -07004704 * Returns the Voice network type for a subId
4705 */
4706 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004707 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4708 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004709 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004710 mApp, subId, callingPackage, callingFeatureId,
4711 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004712 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4713 }
4714
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004715 final long identity = Binder.clearCallingIdentity();
4716 try {
4717 final Phone phone = getPhone(subId);
4718 if (phone != null) {
4719 return phone.getServiceState().getVoiceNetworkType();
4720 } else {
4721 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4722 }
4723 } finally {
4724 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004725 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004726 }
4727
4728 /**
4729 * @return true if a ICC card is present
4730 */
4731 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004732 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004733 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4734 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004735 }
4736
4737 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004738 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004739 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004740 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004741 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004742 final long identity = Binder.clearCallingIdentity();
4743 try {
4744 final Phone phone = PhoneFactory.getPhone(slotIndex);
4745 if (phone != null) {
4746 return phone.getIccCard().hasIccCard();
4747 } else {
4748 return false;
4749 }
4750 } finally {
4751 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004752 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004753 }
4754
4755 /**
4756 * Return if the current radio is LTE on CDMA. This
4757 * is a tri-state return value as for a period of time
4758 * the mode may be unknown.
4759 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004760 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004761 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004762 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004763 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004764 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004765 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4766 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4767 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004768 }
4769
Sanket Padawe356d7632015-06-22 14:03:32 -07004770 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004771 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4772 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004773 try {
4774 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4775 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004776 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4777 }
4778
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004779 final long identity = Binder.clearCallingIdentity();
4780 try {
4781 final Phone phone = getPhone(subId);
4782 if (phone == null) {
4783 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4784 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004785 return TelephonyProperties.lte_on_cdma_device()
4786 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004787 }
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004790 }
Wink Saville36469e72014-06-11 15:17:00 -07004791 }
4792
Wink Saville36469e72014-06-11 15:17:00 -07004793 /**
4794 * {@hide}
4795 * Returns Default subId, 0 in the case of single standby.
4796 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004797 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004798 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004799 }
4800
Shishir Agrawala9f32182016-04-12 12:00:16 -07004801 private int getSlotForDefaultSubscription() {
4802 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4803 }
4804
Wink Savilleb564aae2014-10-23 10:18:09 -07004805 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004806 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004807 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004808
Pengquan Menge92a50d2018-09-21 15:54:48 -07004809 private boolean isActiveSubscription(int subId) {
4810 return mSubscriptionController.isActiveSubId(subId);
4811 }
4812
Ihab Awadf2177b72013-11-25 13:33:23 -08004813 /**
4814 * @see android.telephony.TelephonyManager.WifiCallingChoices
4815 */
4816 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004817 final long identity = Binder.clearCallingIdentity();
4818 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004819 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4821 getWhenToMakeWifiCallsDefaultPreference());
4822 } finally {
4823 Binder.restoreCallingIdentity(identity);
4824 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004825 }
4826
4827 /**
4828 * @see android.telephony.TelephonyManager.WifiCallingChoices
4829 */
4830 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004834 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4836 } finally {
4837 Binder.restoreCallingIdentity(identity);
4838 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004839 }
4840
Sailesh Nepald1e68152013-12-12 19:08:02 -08004841 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004842 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004843 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004844 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004845
Jordan Liu4c733742019-02-28 12:03:40 -08004846 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4847 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4848 if (phoneId == -1) {
4849 throw new IllegalArgumentException("Given slot index: " + slotIndex
4850 + " does not correspond to an active phone");
4851 }
4852 return PhoneFactory.getPhone(phoneId);
4853 }
4854
Shishir Agrawal566b7612013-10-28 14:41:00 -07004855 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004856 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4857 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004858 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4859 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004860 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004861 if (DBG) {
4862 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4863 }
4864 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4865 p2);
4866 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004867
Jordan Liu4c733742019-02-28 12:03:40 -08004868
4869 @Override
4870 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4871 int slotIndex, String callingPackage, String aid, int p2) {
4872 enforceModifyPermission();
4873 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4874 if (DBG) {
4875 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4876 }
4877 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4878 callingPackage, aid, p2);
4879 }
4880
4881 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4882 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 final long identity = Binder.clearCallingIdentity();
4884 try {
4885 if (TextUtils.equals(ISDR_AID, aid)) {
4886 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004887 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4888 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 if (bestComponent == null
4890 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4891 loge("The calling package is not allowed to access ISD-R.");
4892 throw new SecurityException(
4893 "The calling package is not allowed to access ISD-R.");
4894 }
Derek Tan740e1672017-06-27 14:56:27 -07004895 }
Derek Tan740e1672017-06-27 14:56:27 -07004896
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004897 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004898 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4899 null /* workSource */);
4900 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004901 return response;
4902 } finally {
4903 Binder.restoreCallingIdentity(identity);
4904 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004905 }
4906
4907 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004908 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4910 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004911 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4912 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4913 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004914
Jordan Liu4c733742019-02-28 12:03:40 -08004915 @Override
4916 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4917 enforceModifyPermission();
4918 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4919 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4920 channel);
4921 }
4922
4923 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 if (channel < 0) {
4927 return false;
4928 }
Jordan Liu4c733742019-02-28 12:03:40 -08004929 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4930 null /* workSource */);
4931 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004932 return success;
4933 } finally {
4934 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004935 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004936 }
4937
4938 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004939 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004940 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004941 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4942 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004943 if (DBG) {
4944 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4945 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4946 + p3 + " data=" + data);
4947 }
4948 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4949 command, p1, p2, p3, data);
4950 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004951
Jordan Liu4c733742019-02-28 12:03:40 -08004952 @Override
4953 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4954 int command, int p1, int p2, int p3, String data) {
4955 enforceModifyPermission();
4956 if (DBG) {
4957 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4958 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4959 + p3 + " data=" + data);
4960 }
4961 return iccTransmitApduLogicalChannelWithPermission(
4962 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4963 data);
4964 }
4965
4966 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4967 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004968 final long identity = Binder.clearCallingIdentity();
4969 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004970 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004971 return "";
4972 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004973
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004974 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004975 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4976 null /* workSource */);
4977 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004979 // Append the returned status code to the end of the response payload.
4980 String s = Integer.toHexString(
4981 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4982 if (response.payload != null) {
4983 s = IccUtils.bytesToHexString(response.payload) + s;
4984 }
4985 return s;
4986 } finally {
4987 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004988 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004989 }
Jake Hambye994d462014-02-03 13:10:13 -08004990
Evan Charltonc66da362014-05-16 14:06:40 -07004991 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004992 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4993 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004994 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4995 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004997 if (DBG) {
4998 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4999 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
5000 }
5001 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
5002 cla, command, p1, p2, p3, data);
5003 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005004
Jordan Liu4c733742019-02-28 12:03:40 -08005005 @Override
5006 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
5007 int command, int p1, int p2, int p3, String data) {
5008 enforceModifyPermission();
5009 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
5010 if (DBG) {
5011 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
5012 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
5013 + " data=" + data);
5014 }
5015
5016 return iccTransmitApduBasicChannelWithPermission(
5017 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
5018 p2, p3, data);
5019 }
5020
5021 // open APDU basic channel assuming the caller has sufficient permissions
5022 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
5023 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005024 final long identity = Binder.clearCallingIdentity();
5025 try {
5026 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
5027 && TextUtils.equals(ISDR_AID, data)) {
5028 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005029 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
5030 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 if (bestComponent == null
5032 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
5033 loge("The calling package is not allowed to select ISD-R.");
5034 throw new SecurityException(
5035 "The calling package is not allowed to select ISD-R.");
5036 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005037 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08005038
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005039 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08005040 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
5041 null /* workSource */);
5042 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005043
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005044 // Append the returned status code to the end of the response payload.
5045 String s = Integer.toHexString(
5046 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5047 if (response.payload != null) {
5048 s = IccUtils.bytesToHexString(response.payload) + s;
5049 }
5050 return s;
5051 } finally {
5052 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07005053 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005054 }
5055
5056 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005057 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005058 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005059 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5060 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005061
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005062 final long identity = Binder.clearCallingIdentity();
5063 try {
5064 if (DBG) {
5065 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
5066 + p1 + " " + p2 + " " + p3 + ":" + filePath);
5067 }
5068
5069 IccIoResult response =
5070 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
5071 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
5072 subId);
5073
5074 if (DBG) {
5075 log("Exchange SIM_IO [R]" + response);
5076 }
5077
5078 byte[] result = null;
5079 int length = 2;
5080 if (response.payload != null) {
5081 length = 2 + response.payload.length;
5082 result = new byte[length];
5083 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
5084 } else {
5085 result = new byte[length];
5086 }
5087
5088 result[length - 1] = (byte) response.sw2;
5089 result[length - 2] = (byte) response.sw1;
5090 return result;
5091 } finally {
5092 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005093 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005094 }
5095
Nathan Haroldb3014052017-01-25 15:57:32 -08005096 /**
5097 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
5098 * on a particular subscription
5099 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005100 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5101 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005102 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005103 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005104 return null;
5105 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005106
5107 final long identity = Binder.clearCallingIdentity();
5108 try {
5109 if (appType != TelephonyManager.APPTYPE_USIM
5110 && appType != TelephonyManager.APPTYPE_SIM) {
5111 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5112 return null;
5113 }
5114 Object response = sendRequest(
5115 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5116 if (response instanceof String[]) {
5117 return (String[]) response;
5118 }
yincheng zhaod698b842019-09-06 17:06:54 -07005119 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005121 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005122 } finally {
5123 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005124 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005125 }
5126
yincheng zhaod698b842019-09-06 17:06:54 -07005127 /**
5128 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5129 * subscription.
5130 *
5131 * @param subId the id of the subscription.
5132 * @param appType the uicc app type, must be USIM or SIM.
5133 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5134 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005135 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005136 * @return number of fplmns that is successfully written to the SIM.
5137 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005138 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5139 String callingFeatureId) {
5140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5141 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005142 if (DBG) logv("no permissions for setForbiddenplmns");
5143 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5144 }
5145 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5146 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5147 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5148 }
5149 if (fplmns == null) {
5150 throw new IllegalArgumentException("Fplmn List provided is null");
5151 }
5152 for (String fplmn : fplmns) {
5153 if (!CellIdentity.isValidPlmn(fplmn)) {
5154 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5155 }
5156 }
5157 final long identity = Binder.clearCallingIdentity();
5158 try {
5159 Object response = sendRequest(
5160 CMD_SET_FORBIDDEN_PLMNS,
5161 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5162 subId);
5163 return (int) response;
5164 } finally {
5165 Binder.restoreCallingIdentity(identity);
5166 }
5167 }
5168
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005169 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005170 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005171 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5172 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005173
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005174 final long identity = Binder.clearCallingIdentity();
5175 try {
5176 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5177 if (response.payload == null) {
5178 return "";
5179 }
Evan Charltonc66da362014-05-16 14:06:40 -07005180
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005181 // Append the returned status code to the end of the response payload.
5182 String s = Integer.toHexString(
5183 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5184 s = IccUtils.bytesToHexString(response.payload) + s;
5185 return s;
5186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Evan Charltonc66da362014-05-16 14:06:40 -07005189 }
5190
Jake Hambye994d462014-02-03 13:10:13 -08005191 /**
5192 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5193 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5194 *
5195 * @param itemID the ID of the item to read
5196 * @return the NV item as a String, or null on error.
5197 */
5198 @Override
5199 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005200 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005201 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5202 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005203
5204 final long identity = Binder.clearCallingIdentity();
5205 try {
5206 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005207 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5209 return value;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
Jake Hambye994d462014-02-03 13:10:13 -08005213 }
5214
5215 /**
5216 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5217 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5218 *
5219 * @param itemID the ID of the item to read
5220 * @param itemValue the value to write, as a String
5221 * @return true on success; false on any failure
5222 */
5223 @Override
5224 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005225 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5227 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228
5229 final long identity = Binder.clearCallingIdentity();
5230 try {
5231 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5232 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005233 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005234 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5235 return success;
5236 } finally {
5237 Binder.restoreCallingIdentity(identity);
5238 }
Jake Hambye994d462014-02-03 13:10:13 -08005239 }
5240
5241 /**
5242 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5243 * Used for device configuration by some CDMA operators.
5244 *
5245 * @param preferredRoamingList byte array containing the new PRL
5246 * @return true on success; false on any failure
5247 */
5248 @Override
5249 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005250 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5251 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252
5253 final long identity = Binder.clearCallingIdentity();
5254 try {
5255 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5256 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5257 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5258 return success;
5259 } finally {
5260 Binder.restoreCallingIdentity(identity);
5261 }
Jake Hambye994d462014-02-03 13:10:13 -08005262 }
5263
5264 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005265 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005266 * Used for device configuration by some CDMA operators.
5267 *
chen xu6dac5ab2018-10-26 17:39:23 -07005268 * @param slotIndex - device slot.
5269 *
Jake Hambye994d462014-02-03 13:10:13 -08005270 * @return true on success; false on any failure
5271 */
5272 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005273 public boolean resetModemConfig(int slotIndex) {
5274 Phone phone = PhoneFactory.getPhone(slotIndex);
5275 if (phone != null) {
5276 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5277 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005278
chen xu6dac5ab2018-10-26 17:39:23 -07005279 final long identity = Binder.clearCallingIdentity();
5280 try {
5281 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5282 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5283 return success;
5284 } finally {
5285 Binder.restoreCallingIdentity(identity);
5286 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 }
chen xu6dac5ab2018-10-26 17:39:23 -07005288 return false;
5289 }
5290
5291 /**
5292 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5293 *
5294 * @param slotIndex - device slot.
5295 *
5296 * @return true on success; false on any failure
5297 */
5298 @Override
5299 public boolean rebootModem(int slotIndex) {
5300 Phone phone = PhoneFactory.getPhone(slotIndex);
5301 if (phone != null) {
5302 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5303 mApp, phone.getSubId(), "rebootModem");
5304
5305 final long identity = Binder.clearCallingIdentity();
5306 try {
5307 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5308 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5309 return success;
5310 } finally {
5311 Binder.restoreCallingIdentity(identity);
5312 }
5313 }
5314 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005315 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005316
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005317 public String[] getPcscfAddress(String apnType, String callingPackage,
5318 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005319 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005320 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5321 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005322 return new String[0];
5323 }
5324
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005325 final long identity = Binder.clearCallingIdentity();
5326 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005327 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005328 } finally {
5329 Binder.restoreCallingIdentity(identity);
5330 }
Wink Saville36469e72014-06-11 15:17:00 -07005331 }
5332
Brad Ebinger51f743a2017-01-23 13:50:20 -08005333 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005334 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5335 * {@link #disableIms(int)}.
5336 * @param slotIndex device slot.
5337 */
5338 public void resetIms(int slotIndex) {
5339 enforceModifyPermission();
5340
5341 final long identity = Binder.clearCallingIdentity();
5342 try {
5343 if (mImsResolver == null) {
5344 // may happen if the does not support IMS.
5345 return;
5346 }
5347 mImsResolver.disableIms(slotIndex);
5348 mImsResolver.enableIms(slotIndex);
5349 } finally {
5350 Binder.restoreCallingIdentity(identity);
5351 }
5352 }
5353
5354 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005355 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5356 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005357 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005358 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005359 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360
5361 final long identity = Binder.clearCallingIdentity();
5362 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005363 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005364 // may happen if the device does not support IMS.
5365 return;
5366 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005367 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005368 } finally {
5369 Binder.restoreCallingIdentity(identity);
5370 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005371 }
5372
5373 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005374 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5375 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005376 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005377 public void disableIms(int slotId) {
5378 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005379
5380 final long identity = Binder.clearCallingIdentity();
5381 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005382 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005383 // may happen if the device does not support IMS.
5384 return;
5385 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005386 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005387 } finally {
5388 Binder.restoreCallingIdentity(identity);
5389 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005390 }
5391
5392 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005393 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5394 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005395 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005396 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005397 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005398 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005399
5400 final long identity = Binder.clearCallingIdentity();
5401 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005402 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005403 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5404 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005405 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005406 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005407 } finally {
5408 Binder.restoreCallingIdentity(identity);
5409 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005410 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005411 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005412 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5413 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005414 @Override
5415 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005416 enforceModifyPermission();
5417
5418 final long identity = Binder.clearCallingIdentity();
5419 try {
5420 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005421 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005422 } finally {
5423 Binder.restoreCallingIdentity(identity);
5424 }
5425 }
5426
5427 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005428 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005429 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005430 */
5431 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5432 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433
5434 final long identity = Binder.clearCallingIdentity();
5435 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005436 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005437 // may happen if the device does not support IMS.
5438 return null;
5439 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 } finally {
5442 Binder.restoreCallingIdentity(identity);
5443 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005444 }
5445
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005446 /**
5447 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005448 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005449 */
5450 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5451 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005452
5453 final long identity = Binder.clearCallingIdentity();
5454 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005456 // may happen if the device does not support IMS.
5457 return null;
5458 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005459 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005460 } finally {
5461 Binder.restoreCallingIdentity(identity);
5462 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005463 }
5464
Brad Ebinger884c07b2018-02-15 16:17:40 -08005465 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005466 * Sets the ImsService Package Name that Telephony will bind to.
5467 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005468 * @param slotIndex the slot ID that the ImsService should bind for.
5469 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005470 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005471 * @param featureTypes An integer array of feature types associated with a packageName.
5472 * @param packageName The name of the package that the current configuration will be replaced
5473 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005474 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005475 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005476 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5477 int[] featureTypes, String packageName) {
5478 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5479 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005480 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5481 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005482 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005483
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005484 final long identity = Binder.clearCallingIdentity();
5485 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005486 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005487 // may happen if the device does not support IMS.
5488 return false;
5489 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005490 Map<Integer, String> featureConfig = new HashMap<>();
5491 for (int featureType : featureTypes) {
5492 featureConfig.put(featureType, packageName);
5493 }
5494 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5495 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005496 } finally {
5497 Binder.restoreCallingIdentity(identity);
5498 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005499 }
5500
5501 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005502 * Clears any carrier ImsService overrides for the slot index specified that were previously
5503 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5504 *
5505 * This should only be used for testing.
5506 *
5507 * @param slotIndex the slot ID that the ImsService should bind for.
5508 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5509 */
5510 @Override
5511 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5512 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5513 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5514 "clearCarrierImsServiceOverride");
5515 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5516 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5517 "clearCarrierImsServiceOverride");
5518
5519 final long identity = Binder.clearCallingIdentity();
5520 try {
5521 if (mImsResolver == null) {
5522 // may happen if the device does not support IMS.
5523 return false;
5524 }
5525 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5526 } finally {
5527 Binder.restoreCallingIdentity(identity);
5528 }
5529 }
5530
5531 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005532 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005533 *
5534 * @param slotId The slot that the ImsService is associated with.
5535 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5536 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005537 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005538 * @return the package name of the ImsService configuration.
5539 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005540 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5541 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005542 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005543 TelephonyPermissions
5544 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5545 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5546 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005547
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 final long identity = Binder.clearCallingIdentity();
5549 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005550 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005551 // may happen if the device does not support IMS.
5552 return "";
5553 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005554 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005555 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5556 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 } finally {
5558 Binder.restoreCallingIdentity(identity);
5559 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005560 }
5561
Brad Ebinger77b832e2019-10-17 17:03:22 -07005562 /**
5563 * Get the MmTelFeature state associated with the requested subscription id.
5564 * @param subId The subscription that the MmTelFeature is associated with.
5565 * @param callback A callback with an integer containing the
5566 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5567 */
5568 @Override
5569 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5570 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5571 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5572 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5573 "IMS not available on device.");
5574 }
5575 final long token = Binder.clearCallingIdentity();
5576 try {
5577 int slotId = getSlotIndex(subId);
5578 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5579 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5580 + subId + "'");
5581 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5582 }
5583 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5584 try {
5585 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5586 } catch (RemoteException e) {
5587 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5588 + "Ignore");
5589 }
5590 });
5591 } finally {
5592 Binder.restoreCallingIdentity(token);
5593 }
5594 }
5595
Daniel Brightbb5840b2021-01-12 15:48:18 -08005596 /**
5597 * Sets the ims registration state on all valid {@link Phone}s.
5598 */
5599 public void setImsRegistrationState(final boolean registered) {
Wink Saville36469e72014-06-11 15:17:00 -07005600 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005601
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
Daniel Brightbb5840b2021-01-12 15:48:18 -08005604 // NOTE: Before S, this method only set the default phone.
5605 for (final Phone phone : PhoneFactory.getPhones()) {
5606 if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) {
5607 phone.setImsRegistrationState(registered);
5608 }
5609 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
Wink Saville36469e72014-06-11 15:17:00 -07005613 }
5614
5615 /**
Stuart Scott54788802015-03-30 13:18:01 -07005616 * Set the network selection mode to automatic.
5617 *
5618 */
5619 @Override
5620 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005621 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5622 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
shilufc958392020-01-20 11:36:01 -08005626 if (!isActiveSubscription(subId)) {
5627 return;
5628 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005629 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
Rambo Wang0f050d82021-02-12 11:43:36 -08005630 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId,
5631 SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005632 } finally {
5633 Binder.restoreCallingIdentity(identity);
5634 }
Stuart Scott54788802015-03-30 13:18:01 -07005635 }
5636
Jack Yud10cdd42020-09-28 20:28:01 -07005637 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005638 * Ask the radio to connect to the input network and change selection mode to manual.
5639 *
5640 * @param subId the id of the subscription.
5641 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5642 * the operator to attach to.
5643 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5644 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5645 * normal network selection next time.
5646 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005647 */
5648 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005649 public boolean setNetworkSelectionModeManual(
5650 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5652 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005653
5654 if (!isActiveSubscription(subId)) {
5655 return false;
5656 }
5657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005658 final long identity = Binder.clearCallingIdentity();
5659 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005660 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005661 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005662 if (DBG) {
5663 log("setNetworkSelectionModeManual: subId: " + subId
5664 + " operator: " + operatorInfo);
5665 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005666 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5667 } finally {
5668 Binder.restoreCallingIdentity(identity);
5669 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005670 }
shilu84f6e8b2019-12-19 13:58:01 -08005671 /**
5672 * Get the manual network selection
5673 *
5674 * @param subId the id of the subscription.
5675 *
5676 * @return the previously saved user selected PLMN
5677 */
5678 @Override
5679 public String getManualNetworkSelectionPlmn(int subId) {
5680 TelephonyPermissions
5681 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5682 mApp, subId, "getManualNetworkSelectionPlmn");
5683
5684 final long identity = Binder.clearCallingIdentity();
5685 try {
5686 if (!isActiveSubscription(subId)) {
5687 return "";
5688 }
5689
5690 final Phone phone = getPhone(subId);
5691 if (phone == null) {
5692 return "";
5693 }
5694 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5695 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5696 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5697 } finally {
5698 Binder.restoreCallingIdentity(identity);
5699 }
5700 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005701
5702 /**
5703 * Scans for available networks.
5704 */
5705 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005706 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5707 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5709 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005710 LocationAccessPolicy.LocationPermissionResult locationResult =
5711 LocationAccessPolicy.checkLocationPermission(mApp,
5712 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5713 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005714 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005715 .setCallingPid(Binder.getCallingPid())
5716 .setCallingUid(Binder.getCallingUid())
5717 .setMethod("getCellNetworkScanResults")
5718 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5719 .build());
5720 switch (locationResult) {
5721 case DENIED_HARD:
5722 throw new SecurityException("Not allowed to access scan results -- location");
5723 case DENIED_SOFT:
5724 return null;
5725 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726
Pengquan Menga1bb6272018-09-06 09:59:22 -07005727 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005728 try {
5729 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005730 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005731 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005732 } finally {
5733 Binder.restoreCallingIdentity(identity);
5734 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005735 }
5736
5737 /**
sqian80370722020-01-29 15:02:51 -08005738 * Get the call forwarding info, given the call forwarding reason.
5739 */
5740 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005741 public void getCallForwarding(int subId, int callForwardingReason,
5742 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005743 enforceReadPrivilegedPermission("getCallForwarding");
5744 long identity = Binder.clearCallingIdentity();
5745 try {
5746 if (DBG) {
5747 log("getCallForwarding: subId " + subId
5748 + " callForwardingReason" + callForwardingReason);
5749 }
Hall Liua1acea22020-09-18 19:04:59 -07005750
5751 Phone phone = getPhone(subId);
5752 if (phone == null) {
5753 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005754 callback.onError(
5755 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005756 } catch (RemoteException e) {
5757 // ignore
5758 }
5759 return;
5760 }
5761
5762 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5763 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5764 @Override
5765 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5766 try {
5767 callback.onCallForwardingInfoAvailable(info);
5768 } catch (RemoteException e) {
5769 // ignore
5770 }
5771 }
5772
5773 @Override
5774 public void onError(int error) {
5775 try {
5776 callback.onError(error);
5777 } catch (RemoteException e) {
5778 // ignore
5779 }
5780 }
5781 });
5782 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005783 } finally {
5784 Binder.restoreCallingIdentity(identity);
5785 }
5786 }
5787
5788 /**
5789 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5790 * reason, the number to forward, and the timeout before the forwarding is attempted.
5791 */
5792 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005793 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5794 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005795 enforceModifyPermission();
5796 long identity = Binder.clearCallingIdentity();
5797 try {
5798 if (DBG) {
5799 log("setCallForwarding: subId " + subId
5800 + " callForwardingInfo" + callForwardingInfo);
5801 }
Hall Liua1acea22020-09-18 19:04:59 -07005802
5803 Phone phone = getPhone(subId);
5804 if (phone == null) {
5805 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005806 callback.accept(
5807 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005808 } catch (RemoteException e) {
5809 // ignore
5810 }
5811 return;
5812 }
5813
5814 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5815 FunctionalUtils.ignoreRemoteException(callback::accept));
5816
5817 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005818 } finally {
5819 Binder.restoreCallingIdentity(identity);
5820 }
5821 }
5822
5823 /**
Hall Liua1acea22020-09-18 19:04:59 -07005824 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005825 */
5826 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005827 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005828 enforceReadPrivilegedPermission("getCallForwarding");
5829 long identity = Binder.clearCallingIdentity();
5830 try {
Hall Liua1acea22020-09-18 19:04:59 -07005831
5832 Phone phone = getPhone(subId);
5833 if (phone == null) {
5834 try {
5835 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5836 } catch (RemoteException e) {
5837 // ignore
5838 }
5839 return;
5840 }
5841
5842 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5843
sqian80370722020-01-29 15:02:51 -08005844 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005845 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
5851 /**
Hall Liua1acea22020-09-18 19:04:59 -07005852 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005853 */
5854 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005855 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005856 enforceModifyPermission();
5857 long identity = Binder.clearCallingIdentity();
5858 try {
Hall Liua1acea22020-09-18 19:04:59 -07005859 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5860
5861 Phone phone = getPhone(subId);
5862 if (phone == null) {
5863 try {
5864 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5865 } catch (RemoteException e) {
5866 // ignore
5867 }
5868 return;
5869 }
5870
5871 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5872 FunctionalUtils.ignoreRemoteException(callback::accept));
5873
5874 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005875 } finally {
5876 Binder.restoreCallingIdentity(identity);
5877 }
5878 }
5879
5880 /**
yinxub1bed742017-04-17 11:45:04 -07005881 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005882 *
yinxub1bed742017-04-17 11:45:04 -07005883 * @param subId id of the subscription
5884 * @param request contains the radio access networks with bands/channels to scan
5885 * @param messenger callback messenger for scan results or errors
5886 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005887 * @return the id of the requested scan which can be used to stop the scan.
5888 */
5889 @Override
5890 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005891 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005892 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5893 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005894 LocationAccessPolicy.LocationPermissionResult locationResult =
5895 LocationAccessPolicy.checkLocationPermission(mApp,
5896 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5897 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005898 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005899 .setCallingPid(Binder.getCallingPid())
5900 .setCallingUid(Binder.getCallingUid())
5901 .setMethod("requestNetworkScan")
5902 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5903 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005904 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005905 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5906 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005907 if (e != null) {
5908 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5909 throw e;
5910 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005911 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005912 return TelephonyScanManager.INVALID_SCAN_ID;
5913 }
5914 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005915 }
Hall Liu912dfd32019-04-25 14:02:26 -07005916 int callingUid = Binder.getCallingUid();
5917 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005918 final long identity = Binder.clearCallingIdentity();
5919 try {
5920 return mNetworkScanRequestTracker.startNetworkScan(
5921 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005922 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005923 } finally {
5924 Binder.restoreCallingIdentity(identity);
5925 }
yinxu504e1392017-04-12 16:03:22 -07005926 }
5927
Hall Liub2ac8ef2019-02-28 15:56:23 -08005928 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005929 NetworkScanRequest request, int subId, String callingPackage) {
5930 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005931 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5932 boolean hasNetworkScanPermission =
5933 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5934 == PERMISSION_GRANTED;
5935
5936 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5937 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5938 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005939 }
5940
5941 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5942 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005943 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5944 return new SecurityException("Specific channels must not be"
5945 + " scanned without location access.");
5946 }
5947 }
5948 }
5949
Hall Liub2ac8ef2019-02-28 15:56:23 -08005950 return null;
5951 }
5952
yinxu504e1392017-04-12 16:03:22 -07005953 /**
5954 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005955 *
5956 * @param subId id of the subscription
5957 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005958 */
5959 @Override
5960 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005961 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5962 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005963
Hall Liu912dfd32019-04-25 14:02:26 -07005964 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005965 final long identity = Binder.clearCallingIdentity();
5966 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005967 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005968 } finally {
5969 Binder.restoreCallingIdentity(identity);
5970 }
yinxu504e1392017-04-12 16:03:22 -07005971 }
5972
5973 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005974 * Get the calculated preferred network type.
5975 * Used for debugging incorrect network type.
5976 *
5977 * @return the preferred network type, defined in RILConstants.java.
5978 */
5979 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005980 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005981 final Phone defaultPhone = getDefaultPhone();
5982 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005983 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005984 return RILConstants.PREFERRED_NETWORK_MODE;
5985 }
5986
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005987 final long identity = Binder.clearCallingIdentity();
5988 try {
5989 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005990 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005991 } finally {
5992 Binder.restoreCallingIdentity(identity);
5993 }
Junda Liu84d15a22014-07-02 11:21:04 -07005994 }
5995
5996 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005997 * Get the preferred network type.
5998 * Used for device configuration by some CDMA operators.
5999 *
6000 * @return the preferred network type, defined in RILConstants.java.
6001 */
6002 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006003 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08006004 TelephonyPermissions
6005 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6006 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006007
6008 final long identity = Binder.clearCallingIdentity();
6009 try {
6010 if (DBG) log("getPreferredNetworkType");
6011 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
6012 int networkType = (result != null ? result[0] : -1);
6013 if (DBG) log("getPreferredNetworkType: " + networkType);
6014 return networkType;
6015 } finally {
6016 Binder.restoreCallingIdentity(identity);
6017 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006018 }
6019
6020 /**
6021 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08006022 *
6023 * @param networkType the preferred network type, defined in RILConstants.java.
6024 * @return true on success; false on any failure.
6025 */
6026 @Override
Stuart Scott54788802015-03-30 13:18:01 -07006027 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006028 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6029 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006030
6031 final long identity = Binder.clearCallingIdentity();
6032 try {
calvinpan089c2a62020-03-12 14:17:55 +08006033 Boolean success = (Boolean) sendRequest(
6034 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08006035
6036 if (success) {
6037 Settings.Global.putInt(mApp.getContentResolver(),
6038 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
6039 }
calvinpan089c2a62020-03-12 14:17:55 +08006040 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
6041 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 } finally {
6043 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07006044 }
Jake Hamby7c27be32014-03-03 13:25:59 -08006045 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006046
6047 /**
calvinpan677fc2b2020-01-14 20:42:55 +08006048 * Get the allowed network types that store in the telephony provider.
6049 *
6050 * @param subId the id of the subscription.
6051 * @return allowedNetworkTypes the allowed network types.
6052 */
6053 @Override
6054 public long getAllowedNetworkTypes(int subId) {
6055 TelephonyPermissions
6056 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6057 mApp, subId, "getAllowedNetworkTypes");
6058
6059 final long identity = Binder.clearCallingIdentity();
6060 try {
6061 return SubscriptionManager.getLongSubscriptionProperty(
6062 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
6063 } finally {
6064 Binder.restoreCallingIdentity(identity);
6065 }
6066 }
6067
6068 /**
6069 * Set the allowed network types.
6070 *
6071 * @param subId the id of the subscription.
6072 * @param allowedNetworkTypes the allowed network types.
6073 * @return true on success; false on any failure.
6074 */
6075 @Override
6076 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
6077 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6078 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08006079
calvinpan089c2a62020-03-12 14:17:55 +08006080 SubscriptionManager.setSubscriptionProperty(subId,
6081 SubscriptionManager.ALLOWED_NETWORK_TYPES,
6082 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08006083
calvinpan089c2a62020-03-12 14:17:55 +08006084 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6085 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6086 RILConstants.PREFERRED_NETWORK_MODE);
6087 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08006088 }
6089
6090 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006091 * Get the allowed network types for certain reason.
6092 *
6093 * @param subId the id of the subscription.
6094 * @param reason the reason the allowed network type change is taking place
6095 * @return the allowed network types.
6096 */
6097 @Override
6098 public long getAllowedNetworkTypesForReason(int subId,
6099 @TelephonyManager.AllowedNetworkTypesReason int reason) {
6100 TelephonyPermissions
6101 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6102 mApp, subId, "getAllowedNetworkTypesForReason");
6103 final long identity = Binder.clearCallingIdentity();
6104 try {
6105 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
6108 }
6109 }
6110
6111 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006112 * Enable/Disable E-UTRA-NR Dual Connectivity
6113 * @param subId subscription id of the sim card
6114 * @param nrDualConnectivityState expected NR dual connectivity state
6115 * This can be passed following states
6116 * <ol>
6117 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6118 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6119 * <li>Disable NR dual connectivity and force secondary cell to be released
6120 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6121 * </ol>
6122 * @return operation result.
6123 */
6124 @Override
6125 public int setNrDualConnectivityState(int subId,
6126 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6127 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6128 mApp, subId, "enableNRDualConnectivity");
6129 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6130 final long identity = Binder.clearCallingIdentity();
6131 try {
6132 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6133 nrDualConnectivityState, subId,
6134 workSource);
6135 if (DBG) log("enableNRDualConnectivity result: " + result);
6136 return result;
6137 } finally {
6138 Binder.restoreCallingIdentity(identity);
6139 }
6140 }
6141
6142 /**
6143 * Is E-UTRA-NR Dual Connectivity enabled
6144 * @return true if dual connectivity is enabled else false
6145 */
6146 @Override
6147 public boolean isNrDualConnectivityEnabled(int subId) {
6148 TelephonyPermissions
6149 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6150 mApp, subId, "isNRDualConnectivityEnabled");
6151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6152 final long identity = Binder.clearCallingIdentity();
6153 try {
6154 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6155 null, subId, workSource);
6156 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6157 return isEnabled;
6158 } finally {
6159 Binder.restoreCallingIdentity(identity);
6160 }
6161 }
6162
6163 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006164 * get carrier bandwidth per primary and secondary carrier
6165 * @param subId subscription id of the sim card
6166 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6167 */
6168 @Override
6169 public CarrierBandwidth getCarrierBandwidth(int subId) {
6170 TelephonyPermissions
6171 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6172 mApp, subId, "isNRDualConnectivityEnabled");
6173 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6174 final long identity = Binder.clearCallingIdentity();
6175 try {
6176 CarrierBandwidth carrierBandwidth =
6177 getPhoneFromSubId(subId).getCarrierBandwidth();
6178 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6179 return carrierBandwidth;
6180 } finally {
6181 Binder.restoreCallingIdentity(identity);
6182 }
6183 }
6184
6185 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006186 * Get the effective allowed network types on the device.
6187 * This API will return an intersection of allowed network types for all reasons,
6188 * including the configuration done through setAllowedNetworkTypes
6189 *
6190 * @param subId the id of the subscription.
6191 * @return the allowed network types
6192 */
6193 @Override
6194 public long getEffectiveAllowedNetworkTypes(int subId) {
6195 TelephonyPermissions
6196 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6197 mApp, subId, "getEffectiveAllowedNetworkTypes");
6198 final long identity = Binder.clearCallingIdentity();
6199 try {
6200 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6201 } finally {
6202 Binder.restoreCallingIdentity(identity);
6203 }
6204 }
6205
6206 /**
6207 * Set the allowed network types of the device and
6208 * provide the reason triggering the allowed network change.
6209 *
6210 * @param subId the id of the subscription.
6211 * @param reason the reason the allowed network type change is taking place
6212 * @param allowedNetworkTypes the allowed network types.
6213 * @return true on success; false on any failure.
6214 */
6215 @Override
6216 public boolean setAllowedNetworkTypesForReason(int subId,
6217 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6218 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6219 mApp, subId, "setAllowedNetworkTypesForReason");
6220 final long identity = Binder.clearCallingIdentity();
6221 try {
6222 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6223 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6224 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6225 RILConstants.PREFERRED_NETWORK_MODE);
6226 return setPreferredNetworkType(subId, preferredNetworkMode);
6227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
6230 }
6231
6232 /**
Miaoa84611c2019-03-15 09:21:10 +08006233 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006234 *
Miaoa84611c2019-03-15 09:21:10 +08006235 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006236 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006237 * @hide
6238 */
6239 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006240 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006241 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006242 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006243 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006244 try {
Miaoa84611c2019-03-15 09:21:10 +08006245 if (phone != null) {
6246 return phone.hasMatchedTetherApnSetting();
6247 } else {
6248 return false;
6249 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006250 } finally {
6251 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006252 }
Junda Liu475951f2014-11-07 16:45:03 -08006253 }
6254
6255 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006256 * Enable or disable always reporting signal strength changes from radio.
6257 *
6258 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6259 */
6260 @Override
6261 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6262 enforceModifyPermission();
6263 enforceSystemCaller();
6264
6265 final long identity = Binder.clearCallingIdentity();
6266 final Phone phone = getPhone(subId);
6267 try {
6268 if (phone != null) {
6269 if (DBG) {
6270 log("setAlwaysReportSignalStrength: subId=" + subId
6271 + " isEnable=" + isEnable);
6272 }
6273 phone.setAlwaysReportSignalStrength(isEnable);
6274 } else {
6275 loge("setAlwaysReportSignalStrength: no phone found for subId="
6276 + subId);
6277 }
6278 } finally {
6279 Binder.restoreCallingIdentity(identity);
6280 }
6281 }
6282
6283 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006284 * Get the user enabled state of Mobile Data.
6285 *
6286 * TODO: remove and use isUserDataEnabled.
6287 * This can't be removed now because some vendor codes
6288 * calls through ITelephony directly while they should
6289 * use TelephonyManager.
6290 *
6291 * @return true on enabled
6292 */
6293 @Override
6294 public boolean getDataEnabled(int subId) {
6295 return isUserDataEnabled(subId);
6296 }
6297
6298 /**
6299 * Get whether mobile data is enabled per user setting.
6300 *
6301 * There are other factors deciding whether mobile data is actually enabled, but they are
6302 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006303 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006304 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006305 *
6306 * @return {@code true} if data is enabled else {@code false}
6307 */
6308 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006309 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006310 try {
6311 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6312 null);
6313 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006314 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6315 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
6320 int phoneId = mSubscriptionController.getPhoneId(subId);
6321 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6322 Phone phone = PhoneFactory.getPhone(phoneId);
6323 if (phone != null) {
6324 boolean retVal = phone.isUserDataEnabled();
6325 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6326 return retVal;
6327 } else {
6328 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6329 return false;
6330 }
6331 } finally {
6332 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006333 }
6334 }
6335
6336 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006337 * Checks if the device is capable of mobile data by considering whether whether the
6338 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6339 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006340 *
Shuo Qian985d1232020-01-08 14:30:06 -08006341 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006342 */
6343 @Override
6344 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006345 try {
6346 try {
6347 mApp.enforceCallingOrSelfPermission(
6348 android.Manifest.permission.ACCESS_NETWORK_STATE,
6349 null);
6350 } catch (Exception e) {
6351 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6352 "isDataEnabled");
6353 }
6354 } catch (Exception e) {
6355 enforceReadPrivilegedPermission("isDataEnabled");
6356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
6360 int phoneId = mSubscriptionController.getPhoneId(subId);
6361 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6362 Phone phone = PhoneFactory.getPhone(phoneId);
6363 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006364 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6366 return retVal;
6367 } else {
6368 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6369 return false;
6370 }
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006373 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006374 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006375
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006376 /**
6377 * Check if data is enabled for a specific reason
6378 * @param subId Subscription index
6379 * @param reason the reason the data enable change is taking place
6380 * @return {@code true} if the overall data is enabled; {@code false} if not.
6381 */
6382 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006383 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006384 @TelephonyManager.DataEnabledReason int reason) {
6385 try {
6386 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6387 null);
6388 } catch (Exception e) {
6389 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006390 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006391 }
6392
6393
6394 final long identity = Binder.clearCallingIdentity();
6395 try {
6396 int phoneId = mSubscriptionController.getPhoneId(subId);
6397 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006398 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006399 + " reason=" + reason);
6400 }
6401 Phone phone = PhoneFactory.getPhone(phoneId);
6402 if (phone != null) {
6403 boolean retVal;
6404 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6405 retVal = phone.isUserDataEnabled();
6406 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006407 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006408 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006409 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006410 return retVal;
6411 } else {
6412 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006413 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006414 + subId + " retVal=false");
6415 }
6416 return false;
6417 }
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
6421 }
6422
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006423 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006424 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006425 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6426 // Skip the check if it's one of these special uids
6427 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6428 }
6429
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006430 //load access rules from carrier configs, and check those as well: b/139133814
6431 SubscriptionController subController = SubscriptionController.getInstance();
6432 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6433 || subController == null) return privilegeFromSim;
6434
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006435 PackageManager pkgMgr = phone.getContext().getPackageManager();
6436 String[] packages = pkgMgr.getPackagesForUid(uid);
6437
6438 final long identity = Binder.clearCallingIdentity();
6439 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006440 int subId = phone.getSubId();
6441 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6442 // A test override is in place for the privileges for this subId, so don't try to
6443 // read the subscription privileges.
6444 return privilegeFromSim;
6445 }
6446 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006447 SubscriptionManager subManager = (SubscriptionManager)
6448 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6449 for (String pkg : packages) {
6450 if (subManager.canManageSubscription(subInfo, pkg)) {
6451 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6452 }
6453 }
6454 return privilegeFromSim;
6455 } finally {
6456 Binder.restoreCallingIdentity(identity);
6457 }
6458 }
6459
6460 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6461 String pkgName) {
6462 //load access rules from carrier configs, and check those as well: b/139133814
6463 SubscriptionController subController = SubscriptionController.getInstance();
6464 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6465 || subController == null) return privilegeFromSim;
6466
6467 final long identity = Binder.clearCallingIdentity();
6468 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006469 int subId = phone.getSubId();
6470 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6471 // A test override is in place for the privileges for this subId, so don't try to
6472 // read the subscription privileges.
6473 return privilegeFromSim;
6474 }
6475 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006476 SubscriptionManager subManager = (SubscriptionManager)
6477 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6478 return subManager.canManageSubscription(subInfo, pkgName)
6479 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
6483 }
6484
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006485 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006486 public int getCarrierPrivilegeStatus(int subId) {
6487 final Phone phone = getPhone(subId);
6488 if (phone == null) {
6489 loge("getCarrierPrivilegeStatus: Invalid subId");
6490 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6491 }
6492 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006493 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006494 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006495 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6496 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006497
6498 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6499 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006500 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006501 }
Junda Liu29340342014-07-10 15:23:27 -07006502
6503 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006504 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006505 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006506 final Phone phone = getPhone(subId);
6507 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006508 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006509 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6510 }
6511 UiccProfile profile =
6512 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6513 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006514 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006515 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6516 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006517 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006518 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006519 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006520 }
6521
6522 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006523 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6524 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006525 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006526 }
6527
6528 int phoneId = SubscriptionManager.getPhoneId(subId);
6529 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006530 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006531 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006532 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6533 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006534 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6535 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6536 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006537 }
6538
6539 @Override
6540 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006541 if (TextUtils.isEmpty(pkgName))
6542 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006543 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6544 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6545 UiccCard card = UiccController.getInstance().getUiccCard(i);
6546 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006547 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006548 continue;
6549 }
6550
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006551 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6552 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6553 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006554 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6555 break;
6556 }
6557 }
6558
6559 return result;
Junda Liu29340342014-07-10 15:23:27 -07006560 }
Derek Tan89e89d42014-07-08 17:00:10 -07006561
6562 @Override
Junda Liue64de782015-04-16 17:19:16 -07006563 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6564 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6565 loge("phoneId " + phoneId + " is not valid.");
6566 return null;
6567 }
6568 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006569 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006570 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006571 return null ;
6572 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006573 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006574 }
6575
Amith Yamasani6e118872016-02-19 12:53:51 -08006576 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006577 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006578 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006579 List<String> privilegedPackages = new ArrayList<>();
6580 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006581 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6582 // has UICC in that slot.
6583 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006584 if (card.hasCarrierPrivilegeRules()) {
6585 if (packages == null) {
6586 // Only check packages in user 0 for now
6587 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006588 PackageManager.MATCH_DISABLED_COMPONENTS
6589 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006590 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006591 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006592 }
6593 for (int p = packages.size() - 1; p >= 0; p--) {
6594 PackageInfo pkgInfo = packages.get(p);
6595 if (pkgInfo != null && pkgInfo.packageName != null
6596 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006597 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006598 privilegedPackages.add(pkgInfo.packageName);
6599 }
6600 }
6601 }
6602 }
6603 return privilegedPackages;
6604 }
6605
chen xuf7e9fe82019-05-09 19:31:02 -07006606 @Override
6607 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006608 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6609
6610 final long identity = Binder.clearCallingIdentity();
6611
chen xuf7e9fe82019-05-09 19:31:02 -07006612 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006613 try {
6614 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6615 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6616 }
6617 } finally {
6618 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006619 }
6620 return privilegedPackages;
6621 }
6622
Wink Savilleb564aae2014-10-23 10:18:09 -07006623 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006624 final Phone phone = getPhone(subId);
6625 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006626 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006627 return null;
6628 }
6629 String iccId = card.getIccId();
6630 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006631 return null;
6632 }
6633 return iccId;
6634 }
6635
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006636 @Override
Shuo Qian8aa11322020-12-15 22:15:33 -08006637 public void setCallComposerStatus(int subId, int status) {
6638 enforceModifyPermission();
6639
6640 final long identity = Binder.clearCallingIdentity();
6641 try {
6642 Phone phone = getPhone(subId);
6643 if (phone != null) {
6644 Phone defaultPhone = phone.getImsPhone();
6645 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6646 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6647 imsPhone.setCallComposerStatus(status);
Shuo Qiand8782462020-12-22 19:10:14 -08006648 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
6649 .updateImsServiceConfig();
Shuo Qian8aa11322020-12-15 22:15:33 -08006650 }
6651 }
Shuo Qiand8782462020-12-22 19:10:14 -08006652 } catch (ImsException e) {
6653 throw new ServiceSpecificException(e.getCode());
6654 } finally {
Shuo Qian8aa11322020-12-15 22:15:33 -08006655 Binder.restoreCallingIdentity(identity);
6656 }
6657 }
6658
6659 @Override
6660 public int getCallComposerStatus(int subId) {
6661 enforceReadPrivilegedPermission("getCallComposerStatus");
6662
6663 final long identity = Binder.clearCallingIdentity();
6664 try {
6665 Phone phone = getPhone(subId);
6666 if (phone != null) {
6667 Phone defaultPhone = phone.getImsPhone();
6668 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
6669 ImsPhone imsPhone = (ImsPhone) defaultPhone;
6670 return imsPhone.getCallComposerStatus();
6671 }
6672 }
6673 } finally {
6674 Binder.restoreCallingIdentity(identity);
6675 }
6676 return TelephonyManager.CALL_COMPOSER_STATUS_OFF;
6677 }
6678
6679 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006680 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6681 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006682 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006683 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006684
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006685 final long identity = Binder.clearCallingIdentity();
6686 try {
6687 final String iccId = getIccId(subId);
6688 final Phone phone = getPhone(subId);
6689 if (phone == null) {
6690 return false;
6691 }
6692 final String subscriberId = phone.getSubscriberId();
6693
6694 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006695 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 + subscriberId + " to " + number);
6697 }
6698
6699 if (TextUtils.isEmpty(iccId)) {
6700 return false;
6701 }
6702
6703 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6704
6705 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6706 if (alphaTag == null) {
6707 editor.remove(alphaTagPrefKey);
6708 } else {
6709 editor.putString(alphaTagPrefKey, alphaTag);
6710 }
6711
6712 // Record both the line number and IMSI for this ICCID, since we need to
6713 // track all merged IMSIs based on line number
6714 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6715 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6716 if (number == null) {
6717 editor.remove(numberPrefKey);
6718 editor.remove(subscriberPrefKey);
6719 } else {
6720 editor.putString(numberPrefKey, number);
6721 editor.putString(subscriberPrefKey, subscriberId);
6722 }
6723
6724 editor.commit();
6725 return true;
6726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006728 }
Derek Tan7226c842014-07-02 17:42:23 -07006729 }
6730
6731 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006732 public String getLine1NumberForDisplay(int subId, String callingPackage,
6733 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006734 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006736 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006737 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006738 return null;
6739 }
Derek Tan97ebb422014-09-05 16:55:38 -07006740
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 final long identity = Binder.clearCallingIdentity();
6742 try {
6743 String iccId = getIccId(subId);
6744 if (iccId != null) {
6745 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6746 if (DBG_MERGE) {
6747 log("getLine1NumberForDisplay returning "
6748 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6749 }
6750 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006751 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6753 return null;
6754 } finally {
6755 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006756 }
Derek Tan7226c842014-07-02 17:42:23 -07006757 }
6758
6759 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006760 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6761 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006762 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006763 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006764 return null;
6765 }
Derek Tan97ebb422014-09-05 16:55:38 -07006766
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006767 final long identity = Binder.clearCallingIdentity();
6768 try {
6769 String iccId = getIccId(subId);
6770 if (iccId != null) {
6771 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6772 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6773 }
6774 return null;
6775 } finally {
6776 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006777 }
Derek Tan7226c842014-07-02 17:42:23 -07006778 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006779
6780 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006781 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6782 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006783 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6784 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006786 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006787 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006788 return null;
6789 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006790
Jordan Liub49b04b2019-05-06 14:45:15 -07006791 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6792 // the process, where TelephonyManager was instantiated.
6793 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006794 final long identity = Binder.clearCallingIdentity();
6795 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006796 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006797 final TelephonyManager tele = TelephonyManager.from(context);
6798 final SubscriptionManager sub = SubscriptionManager.from(context);
6799
6800 // Figure out what subscribers are currently active
6801 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006802
Jordan Liub49b04b2019-05-06 14:45:15 -07006803 // Only consider subs which match the current subId
6804 // This logic can be simplified. See b/131189269 for progress.
6805 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006806 activeSubscriberIds.add(tele.getSubscriberId(subId));
6807 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006808
6809 // First pass, find a number override for an active subscriber
6810 String mergeNumber = null;
6811 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6812 for (String key : prefs.keySet()) {
6813 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6814 final String subscriberId = (String) prefs.get(key);
6815 if (activeSubscriberIds.contains(subscriberId)) {
6816 final String iccId = key.substring(
6817 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6818 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6819 mergeNumber = (String) prefs.get(numberKey);
6820 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006821 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006822 + " for active subscriber " + subscriberId);
6823 }
6824 if (!TextUtils.isEmpty(mergeNumber)) {
6825 break;
6826 }
6827 }
6828 }
6829 }
6830
6831 // Shortcut when no active merged subscribers
6832 if (TextUtils.isEmpty(mergeNumber)) {
6833 return null;
6834 }
6835
6836 // Second pass, find all subscribers under that line override
6837 final ArraySet<String> result = new ArraySet<>();
6838 for (String key : prefs.keySet()) {
6839 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6840 final String number = (String) prefs.get(key);
6841 if (mergeNumber.equals(number)) {
6842 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6843 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6844 final String subscriberId = (String) prefs.get(subscriberKey);
6845 if (!TextUtils.isEmpty(subscriberId)) {
6846 result.add(subscriberId);
6847 }
6848 }
6849 }
6850 }
6851
6852 final String[] resultArray = result.toArray(new String[result.size()]);
6853 Arrays.sort(resultArray);
6854 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006855 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6857 }
6858 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006861 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006862 }
6863
6864 @Override
zoey chen38003472019-12-13 17:16:31 +08006865 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6866 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006867
6868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 final TelephonyManager telephonyManager = mApp.getSystemService(
6871 TelephonyManager.class);
6872 String subscriberId = telephonyManager.getSubscriberId(subId);
6873 if (subscriberId == null) {
6874 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006875 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006876 + subId);
6877 }
6878 return null;
6879 }
6880
6881 final SubscriptionInfo info = SubscriptionController.getInstance()
6882 .getSubscriptionInfo(subId);
6883 final ParcelUuid groupUuid = info.getGroupUuid();
6884 // If it doesn't belong to any group, return just subscriberId of itself.
6885 if (groupUuid == null) {
6886 return new String[]{subscriberId};
6887 }
6888
6889 // Get all subscriberIds from the group.
6890 final List<String> mergedSubscriberIds = new ArrayList<>();
6891 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006892 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006893 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006894 for (SubscriptionInfo subInfo : groupInfos) {
6895 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6896 if (subscriberId != null) {
6897 mergedSubscriberIds.add(subscriberId);
6898 }
6899 }
6900
6901 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6902 } finally {
6903 Binder.restoreCallingIdentity(identity);
6904
6905 }
6906 }
6907
6908 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006909 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006910 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006911 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006912
6913 final long identity = Binder.clearCallingIdentity();
6914 try {
6915 final Phone phone = getPhone(subId);
6916 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6917 } finally {
6918 Binder.restoreCallingIdentity(identity);
6919 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006920 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006921
6922 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006923 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006924 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6925 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006926 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6927 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006928
6929 final long identity = Binder.clearCallingIdentity();
6930 try {
6931 final Phone phone = getPhone(subId);
6932 if (phone == null) {
6933 return false;
6934 }
6935 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6936 cdmaNonRoamingList);
6937 } finally {
6938 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006939 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006940 }
6941
6942 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006943 @Deprecated
6944 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6945 enforceModifyPermission();
6946
6947 int returnValue = 0;
6948 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006949 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006950 if(result.exception == null) {
6951 if (result.result != null) {
6952 byte[] responseData = (byte[])(result.result);
6953 if(responseData.length > oemResp.length) {
6954 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6955 responseData.length + "bytes. Buffer Size is " +
6956 oemResp.length + "bytes.");
6957 }
6958 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6959 returnValue = responseData.length;
6960 }
6961 } else {
6962 CommandException ex = (CommandException) result.exception;
6963 returnValue = ex.getCommandError().ordinal();
6964 if(returnValue > 0) returnValue *= -1;
6965 }
6966 } catch (RuntimeException e) {
6967 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6968 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6969 if(returnValue > 0) returnValue *= -1;
6970 }
6971
6972 return returnValue;
6973 }
6974
6975 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006976 public void setRadioCapability(RadioAccessFamily[] rafs) {
6977 try {
6978 ProxyController.getInstance().setRadioCapability(rafs);
6979 } catch (RuntimeException e) {
6980 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6981 }
6982 }
6983
6984 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006985 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006986 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006987 try {
6988 TelephonyPermissions
6989 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6990 mApp, phone.getSubId(), "getRadioAccessFamily");
6991 } catch (SecurityException e) {
6992 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6993 throw e;
6994 }
chen xub97461a2018-10-26 14:17:57 -07006995 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006996 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006997 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006999 final long identity = Binder.clearCallingIdentity();
7000 try {
chen xub97461a2018-10-26 14:17:57 -07007001 TelephonyPermissions
7002 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
7003 mApp, phone.getSubId(), "getRadioAccessFamily");
7004 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005 } finally {
7006 Binder.restoreCallingIdentity(identity);
7007 }
chen xub97461a2018-10-26 14:17:57 -07007008 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07007009 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007010
7011 @Override
7012 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007013 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07007014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015
7016 final long identity = Binder.clearCallingIdentity();
7017 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007018 ImsManager.getInstance(defaultPhone.getContext(),
7019 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007020 } finally {
7021 Binder.restoreCallingIdentity(identity);
7022 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007023 }
7024
7025 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007026 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007027 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007028 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
7029 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00007030 return false;
7031 }
Svet Ganovb320e182015-04-16 12:30:10 -07007032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033 final long identity = Binder.clearCallingIdentity();
7034 try {
7035 // Check the user preference and the system-level IMS setting. Even if the user has
7036 // enabled video calling, if IMS is disabled we aren't able to support video calling.
7037 // In the long run, we may instead need to check if there exists a connection service
7038 // which can support video calling.
7039 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007040 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 return imsManager.isVtEnabledByPlatform()
7042 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
7043 && imsManager.isVtEnabledByUser();
7044 } finally {
7045 Binder.restoreCallingIdentity(identity);
7046 }
Andrew Leedf14ead2014-10-17 14:22:52 -07007047 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06007048
Andrew Leea1239f22015-03-02 17:44:07 -08007049 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007050 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
7051 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007052 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007053 mApp, subId, callingPackage, callingFeatureId,
7054 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055 return false;
7056 }
7057
7058 final long identity = Binder.clearCallingIdentity();
7059 try {
7060 CarrierConfigManager configManager =
7061 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007062 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007063 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
Andrew Leea1239f22015-03-02 17:44:07 -08007067 }
7068
7069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007070 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007071 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007072 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073 return false;
7074 }
7075
7076 final long identity = Binder.clearCallingIdentity();
7077 try {
7078 CarrierConfigManager configManager =
7079 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007080 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007081 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
7082 } finally {
7083 Binder.restoreCallingIdentity(identity);
7084 }
Andrew Leea1239f22015-03-02 17:44:07 -08007085 }
7086
Andrew Lee9431b832015-03-09 18:46:45 -07007087 @Override
7088 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07007089 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08007090 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07007091 }
7092
7093 @Override
7094 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007095 final long identity = Binder.clearCallingIdentity();
7096 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007097 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007098 } finally {
7099 Binder.restoreCallingIdentity(identity);
7100 }
Andrew Lee9431b832015-03-09 18:46:45 -07007101 }
7102
Hall Liuf6668912018-10-31 17:05:23 -07007103 /**
7104 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
7105 * support for the feature and device firmware support.
7106 *
7107 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
7108 */
7109 @Override
7110 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007112 final Phone phone = getPhone(subscriptionId);
7113 if (phone == null) {
7114 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
7115 return false;
7116 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007117 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007118 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007119 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
7120 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007121 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 return isCarrierSupported && isDeviceSupported;
7123 } finally {
7124 Binder.restoreCallingIdentity(identity);
7125 }
Hall Liu98187582018-01-22 19:15:32 -08007126 }
7127
Hall Liuf6668912018-10-31 17:05:23 -07007128 /**
Hall Liu6a06be62019-07-23 18:39:00 -07007129 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
7130 * RTT setting, will return true if the device and carrier both support RTT.
7131 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07007132 */
7133 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007134 final long identity = Binder.clearCallingIdentity();
7135 try {
Hall Liu63767ec2019-12-11 23:58:20 +00007136 boolean isRttSupported = isRttSupported(subscriptionId);
7137 boolean isUserRttSettingOn = Settings.Secure.getInt(
7138 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
7139 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
7140 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
7141 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
Hall Liu3ad5f012018-04-06 16:23:39 -07007145 }
7146
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007147 @Deprecated
7148 @Override
7149 public String getDeviceId(String callingPackage) {
7150 return getDeviceIdWithFeature(callingPackage, null);
7151 }
7152
Sanket Padawe7310cc72015-01-14 09:53:20 -08007153 /**
7154 * Returns the unique device ID of phone, for example, the IMEI for
7155 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7156 *
7157 * <p>Requires Permission:
7158 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7159 */
7160 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007161 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007162 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007163 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007164 return null;
7165 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007166 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007167 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007168 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007169 return null;
7170 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007171
7172 final long identity = Binder.clearCallingIdentity();
7173 try {
7174 return phone.getDeviceId();
7175 } finally {
7176 Binder.restoreCallingIdentity(identity);
7177 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007178 }
7179
Ping Sunc67b7c22016-03-02 19:16:45 +08007180 /**
7181 * {@hide}
7182 * Returns the IMS Registration Status on a particular subid
7183 *
7184 * @param subId
7185 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007186 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007187 Phone phone = getPhone(subId);
7188 if (phone != null) {
7189 return phone.isImsRegistered();
7190 } else {
7191 return false;
7192 }
7193 }
7194
Santos Cordon7a1885b2015-02-03 11:15:19 -08007195 @Override
7196 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 final long identity = Binder.clearCallingIdentity();
7198 try {
7199 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7200 } finally {
7201 Binder.restoreCallingIdentity(identity);
7202 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007203 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007204
Tyler Gunnf70ed162019-04-03 15:28:53 -07007205 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007206 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007207 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007208 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007209 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007210 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7211 }
7212 final long identity = Binder.clearCallingIdentity();
7213 try {
7214 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7215 } finally {
7216 Binder.restoreCallingIdentity(identity);
7217 }
7218 }
7219
7220 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007221 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007222 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7223 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007224 final long identity = Binder.clearCallingIdentity();
7225 try {
7226 Phone phone = getPhone(subscriptionId);
7227 if (phone == null) {
7228 return null;
7229 }
7230 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7231 } finally {
7232 Binder.restoreCallingIdentity(identity);
7233 }
7234 }
7235
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007236 /**
7237 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007238 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007239 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240 final long identity = Binder.clearCallingIdentity();
7241 try {
7242 Phone phone = getPhone(subId);
7243 if (phone != null) {
7244 return phone.isWifiCallingEnabled();
7245 } else {
7246 return false;
7247 }
7248 } finally {
7249 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007250 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007251 }
7252
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007253 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007254 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007255 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007256 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 final long identity = Binder.clearCallingIdentity();
7258 try {
7259 Phone phone = getPhone(subId);
7260 if (phone != null) {
7261 return phone.isVideoEnabled();
7262 } else {
7263 return false;
7264 }
7265 } finally {
7266 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007267 }
7268 }
7269
7270 /**
7271 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7272 * defined in {@link ImsRegistrationImplBase}.
7273 */
7274 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007275 final long identity = Binder.clearCallingIdentity();
7276 try {
7277 Phone phone = getPhone(subId);
7278 if (phone != null) {
7279 return phone.getImsRegistrationTech();
7280 } else {
7281 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7282 }
7283 } finally {
7284 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007285 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007286 }
7287
Stuart Scott8eef64f2015-04-08 15:13:54 -07007288 @Override
7289 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007290 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007291 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7292 return;
7293 }
7294
Svet Ganovcc087f82015-05-12 20:35:54 -07007295 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007296
Svet Ganovcc087f82015-05-12 20:35:54 -07007297 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007298 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7299 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007300 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007301 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007302 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007303 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007304 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7305 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007306 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007307 // There has been issues when Sms raw table somehow stores orphan
7308 // fragments. They lead to garbled message when new fragments come
7309 // in and combined with those stale ones. In case this happens again,
7310 // user can reset all network settings which will clean up this table.
7311 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007312 // Clean up IMS settings as well here.
7313 int slotId = getSlotIndex(subId);
7314 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7315 ImsManager.getInstance(mApp, slotId).factoryReset();
7316 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007317
7318 // Erase modem config if erase modem on network setting is enabled.
7319 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7320 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7321 if (configValue != null && Boolean.parseBoolean(configValue)) {
7322 sendEraseModemConfig(getDefaultPhone());
7323 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007324 } finally {
7325 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007326 }
7327 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007328
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007329 private void cleanUpSmsRawTable(Context context) {
7330 ContentResolver resolver = context.getContentResolver();
7331 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7332 resolver.delete(uri, null, null);
7333 }
7334
Narayan Kamath1c496c22015-04-16 14:40:19 +01007335 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007336 public String getSimLocaleForSubscriber(int subId) {
7337 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7338 final Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007341 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007342 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007343 final long identity = Binder.clearCallingIdentity();
7344 try {
chen xu5d3637b2019-01-21 23:31:38 -08007345 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007346 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007347 if (info == null) {
7348 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7349 return null;
7350 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 // Try and fetch the locale from the carrier properties or from the SIM language
7352 // preferences (EF-PL and EF-LI)...
7353 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007354 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007355 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7356 if (localeFromDefaultSim != null) {
7357 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7358 if (DBG) log("Using locale from subId: " + subId + " locale: "
7359 + localeFromDefaultSim);
7360 return localeFromDefaultSim.toLanguageTag();
7361 } else {
7362 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007363 }
7364 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 // The SIM language preferences only store a language (e.g. fr = French), not an
7367 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7368 // the SIM and carrier preferences does not include a country we add the country
7369 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007370 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007372 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 return mccLocale.toLanguageTag();
7374 }
7375
7376 if (DBG) log("No locale found - returning null");
7377 return null;
7378 } finally {
7379 Binder.restoreCallingIdentity(identity);
7380 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007381 }
7382
7383 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007384 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007385 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007386 }
7387
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007388 /**
7389 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7390 */
7391 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007392 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007393 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007394 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007395
Chenjie Yu1ba97252018-01-11 18:16:20 -08007396 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007397 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007398
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007399 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007400 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7401 * representing the state of the modem.
7402 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007403 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7404 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007405 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007406 */
7407 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007408 public void requestModemActivityInfo(ResultReceiver result) {
7409 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007410 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007411
7412 final long identity = Binder.clearCallingIdentity();
7413 try {
sqian1a1be542020-03-05 11:37:28 -08007414 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007415 } finally {
7416 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007417 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007418 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007419
Siddharth Rayb8114062018-06-17 15:02:38 -07007420 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7421 // less than total activity duration.
7422 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7423 if (info == null) {
7424 return false;
7425 }
7426 int activityDurationMs =
7427 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7428 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007429 int[] txTimeMs = info.getTransmitTimeMillis();
7430 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7431 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007432 }
7433 return (info.isValid()
7434 && (info.getSleepTimeMillis() <= activityDurationMs)
7435 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007436 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007437 && (totalTxTimeMs <= activityDurationMs));
7438 }
7439
Jack Yu85bd38a2015-11-09 11:34:32 -08007440 /**
7441 * {@hide}
7442 * Returns the service state information on specified subscription.
7443 */
7444 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007445 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7446 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007447 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007448 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007449 return null;
7450 }
7451
Hall Liuf19c44f2018-11-27 14:38:17 -08007452 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7453 LocationAccessPolicy.checkLocationPermission(mApp,
7454 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7455 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007456 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007457 .setCallingPid(Binder.getCallingPid())
7458 .setCallingUid(Binder.getCallingUid())
7459 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007460 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007461 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7462 .build());
7463
7464 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7465 LocationAccessPolicy.checkLocationPermission(mApp,
7466 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7467 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007468 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007469 .setCallingPid(Binder.getCallingPid())
7470 .setCallingUid(Binder.getCallingUid())
7471 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007472 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007473 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7474 .build());
7475 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7476 boolean hasFinePermission =
7477 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7478 boolean hasCoarsePermission =
7479 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7480
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007481 final long identity = Binder.clearCallingIdentity();
7482 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007483 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7484 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7485 Rlog.d(LOG_TAG,
7486 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7487 return null;
7488 }
7489
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007490 final Phone phone = getPhone(subId);
7491 if (phone == null) {
7492 return null;
7493 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007494
Hall Liuf19c44f2018-11-27 14:38:17 -08007495 ServiceState ss = phone.getServiceState();
7496
7497 // Scrub out the location info in ServiceState depending on what level of access
7498 // the caller has.
7499 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007500 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7501 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007502 } finally {
7503 Binder.restoreCallingIdentity(identity);
7504 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007505 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007506
7507 /**
7508 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7509 *
7510 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7511 * voicemail ringtone.
7512 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7513 * PhoneAccount.
7514 */
7515 @Override
7516 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007517 final long identity = Binder.clearCallingIdentity();
7518 try {
7519 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7520 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007521 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007522 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007523
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007524 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7525 } finally {
7526 Binder.restoreCallingIdentity(identity);
7527 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007528 }
7529
7530 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007531 * Sets the per-account voicemail ringtone.
7532 *
7533 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7534 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7535 *
7536 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7537 * voicemail ringtone.
7538 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7539 * PhoneAccount.
7540 */
7541 @Override
7542 public void setVoicemailRingtoneUri(String callingPackage,
7543 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007544 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007545 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007546 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7547 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007548 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7549 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7550 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007551 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007552
7553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7556 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007557 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007558 }
7559 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7560 } finally {
7561 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007562 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007563 }
7564
7565 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007566 * Returns whether vibration is set for voicemail notification in Phone settings.
7567 *
7568 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7569 * voicemail vibration setting.
7570 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7571 */
7572 @Override
7573 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007574 final long identity = Binder.clearCallingIdentity();
7575 try {
7576 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7577 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007578 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007579 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007581 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7582 } finally {
7583 Binder.restoreCallingIdentity(identity);
7584 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007585 }
7586
Youhan Wange64578a2016-05-02 15:32:42 -07007587 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007588 * Sets the per-account voicemail vibration.
7589 *
7590 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7591 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7592 *
7593 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7594 * voicemail vibration setting.
7595 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7596 * specific PhoneAccount.
7597 */
7598 @Override
7599 public void setVoicemailVibrationEnabled(String callingPackage,
7600 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007601 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007602 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007603 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7604 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007605 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7606 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7607 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007608 }
7609
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7613 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007614 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007615 }
7616 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7617 } finally {
7618 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007619 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007620 }
7621
7622 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007623 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7624 *
7625 * @throws SecurityException if the caller does not have the required permission
7626 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007627 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007628 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007629 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007630 }
7631
7632 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007633 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7634 * permission.
7635 *
7636 * @throws SecurityException if the caller does not have the required permission
7637 */
7638 private void enforceSendSmsPermission() {
7639 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7640 }
7641
7642 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007643 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007644 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007645 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007646 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007647 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007648 final long identity = Binder.clearCallingIdentity();
7649 try {
7650 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007651 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 if (componentName == null) {
7653 throw new SecurityException(
7654 "Caller not current active visual voicemail package[null]");
7655 }
7656 String vvmPackage = componentName.getPackageName();
7657 if (!callingPackage.equals(vvmPackage)) {
7658 throw new SecurityException("Caller not current active visual voicemail package["
7659 + vvmPackage + "]");
7660 }
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007663 }
7664 }
7665
7666 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007667 * Return the application ID for the app type.
7668 *
7669 * @param subId the subscription ID that this request applies to.
7670 * @param appType the uicc app type.
7671 * @return Application ID for specificied app type, or null if no uicc.
7672 */
7673 @Override
7674 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007675 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007676 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677
7678 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007679 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007680 if (phone == null) {
7681 return null;
7682 }
7683 String aid = null;
7684 try {
7685 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7686 .getApplicationByType(appType).getAid();
7687 } catch (Exception e) {
7688 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7689 }
7690 return aid;
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007693 }
Youhan Wange64578a2016-05-02 15:32:42 -07007694 }
7695
Youhan Wang4001d252016-05-11 10:29:41 -07007696 /**
7697 * Return the Electronic Serial Number.
7698 *
7699 * @param subId the subscription ID that this request applies to.
7700 * @return ESN or null if error.
7701 */
7702 @Override
7703 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007704 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007705 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007706
7707 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007708 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007709 if (phone == null) {
7710 return null;
7711 }
7712 String esn = null;
7713 try {
7714 esn = phone.getEsn();
7715 } catch (Exception e) {
7716 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7717 }
7718 return esn;
7719 } finally {
7720 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007721 }
Youhan Wang4001d252016-05-11 10:29:41 -07007722 }
7723
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007724 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007725 * Return the Preferred Roaming List Version.
7726 *
7727 * @param subId the subscription ID that this request applies to.
7728 * @return PRLVersion or null if error.
7729 */
7730 @Override
7731 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007732 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007733 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007734
7735 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007736 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737 if (phone == null) {
7738 return null;
7739 }
7740 String cdmaPrlVersion = null;
7741 try {
7742 cdmaPrlVersion = phone.getCdmaPrlVersion();
7743 } catch (Exception e) {
7744 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7745 }
7746 return cdmaPrlVersion;
7747 } finally {
7748 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007749 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007750 }
7751
7752 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007753 * Get snapshot of Telephony histograms
7754 * @return List of Telephony histograms
7755 * @hide
7756 */
7757 @Override
7758 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007759 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7760 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007761
7762 final long identity = Binder.clearCallingIdentity();
7763 try {
7764 return RIL.getTelephonyRILTimingHistograms();
7765 } finally {
7766 Binder.restoreCallingIdentity(identity);
7767 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007768 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007769
7770 /**
7771 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007772 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7773 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007774 * Require system privileges. In the future we may add this to carrier APIs.
7775 *
Michele Berionne482f8202018-11-27 18:57:59 -08007776 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007777 */
7778 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007779 @TelephonyManager.SetCarrierRestrictionResult
7780 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007781 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007782 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007783
Michele Berionne482f8202018-11-27 18:57:59 -08007784 if (carrierRestrictionRules == null) {
7785 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007786 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788 final long identity = Binder.clearCallingIdentity();
7789 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007790 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007791 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007792 } finally {
7793 Binder.restoreCallingIdentity(identity);
7794 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007795 }
7796
7797 /**
7798 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007799 * Get the allowed carrier list and the excluded carrier list, including the priority between
7800 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007801 * Require system privileges. In the future we may add this to carrier APIs.
7802 *
Michele Berionne482f8202018-11-27 18:57:59 -08007803 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007804 */
7805 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007806 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007807 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007808 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007809
7810 final long identity = Binder.clearCallingIdentity();
7811 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007812 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7813 if (response instanceof CarrierRestrictionRules) {
7814 return (CarrierRestrictionRules) response;
7815 }
7816 // Response is an Exception of some kind,
7817 // which is signalled to the user as a NULL retval
7818 return null;
7819 } catch (Exception e) {
7820 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7821 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007822 } finally {
7823 Binder.restoreCallingIdentity(identity);
7824 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007825 }
7826
fionaxu59545b42016-05-25 15:53:37 -07007827 /**
fionaxu59545b42016-05-25 15:53:37 -07007828 * Action set from carrier signalling broadcast receivers to enable/disable radio
7829 * @param subId the subscription ID that this action applies to.
7830 * @param enabled control enable or disable radio.
7831 * {@hide}
7832 */
7833 @Override
7834 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7835 enforceModifyPermission();
7836 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007837
7838 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007839 if (phone == null) {
7840 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7841 return;
7842 }
7843 try {
7844 phone.carrierActionSetRadioEnabled(enabled);
7845 } catch (Exception e) {
7846 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007847 } finally {
7848 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007849 }
7850 }
7851
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007852 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007853 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7854 * network status based on which carrier apps could apply actions accordingly,
7855 * enable/disable default url handler for example.
7856 *
7857 * @param subId the subscription ID that this action applies to.
7858 * @param report control start/stop reporting the default network status.
7859 * {@hide}
7860 */
7861 @Override
7862 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7863 enforceModifyPermission();
7864 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007865
7866 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007867 if (phone == null) {
7868 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7869 return;
7870 }
7871 try {
7872 phone.carrierActionReportDefaultNetworkStatus(report);
7873 } catch (Exception e) {
7874 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007875 } finally {
7876 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007877 }
7878 }
7879
7880 /**
fionaxud9622282017-07-17 17:51:30 -07007881 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7882 * @param subId the subscription ID that this action applies to.
7883 * {@hide}
7884 */
7885 @Override
7886 public void carrierActionResetAll(int subId) {
7887 enforceModifyPermission();
7888 final Phone phone = getPhone(subId);
7889 if (phone == null) {
7890 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7891 return;
7892 }
7893 try {
7894 phone.carrierActionResetAll();
7895 } catch (Exception e) {
7896 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7897 }
7898 }
7899
7900 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007901 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7902 * bug report is being generated.
7903 */
7904 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007905 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007906 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7907 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007908 writer.println("Permission Denial: can't dump Phone from pid="
7909 + Binder.getCallingPid()
7910 + ", uid=" + Binder.getCallingUid()
7911 + "without permission "
7912 + android.Manifest.permission.DUMP);
7913 return;
7914 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007915 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007916 }
Jack Yueb89b242016-06-22 13:27:47 -07007917
Brad Ebingerdac2f002018-04-03 15:17:52 -07007918 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007919 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7920 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7921 @NonNull String[] args) {
7922 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7923 this, in.getFileDescriptor(), out.getFileDescriptor(),
7924 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007925 }
7926
Jack Yueb89b242016-06-22 13:27:47 -07007927 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007928 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007929 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007930 * @param reason the reason the data enable change is taking place
7931 * @param enabled True if enabling the data, otherwise disabling.
7932 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007933 */
7934 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007935 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007936 boolean enabled) {
7937 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7938 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7939 try {
7940 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007941 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007942 } catch (SecurityException se) {
7943 enforceModifyPermission();
7944 }
7945 } else {
7946 enforceModifyPermission();
7947 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007948
7949 final long identity = Binder.clearCallingIdentity();
7950 try {
7951 Phone phone = getPhone(subId);
7952 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007953 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7954 phone.carrierActionSetMeteredApnsEnabled(enabled);
7955 } else {
7956 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7957 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007958 }
7959 } finally {
7960 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007961 }
7962 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007963
7964 /**
7965 * Get Client request stats
7966 * @return List of Client Request Stats
7967 * @hide
7968 */
7969 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007970 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7971 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007972 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007973 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007974 return null;
7975 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007976 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007977
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 if (phone != null) {
7981 return phone.getClientRequestStats();
7982 }
7983
7984 return null;
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
7987 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007988 }
7989
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007990 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007991 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007992 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007993 }
Jack Yueb4124c2017-02-16 15:32:43 -08007994
7995 /**
Grace Chen70990072017-03-24 17:21:30 -07007996 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007997 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007998 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007999 * @param state State of SIM (power down, power up, pass through)
8000 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8001 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8002 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08008003 *
8004 **/
8005 @Override
Grace Chen70990072017-03-24 17:21:30 -07008006 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08008007 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07008008 Phone phone = PhoneFactory.getPhone(slotIndex);
8009
vagdeviaf9a5b92018-08-15 16:01:53 -07008010 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8011
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008012 final long identity = Binder.clearCallingIdentity();
8013 try {
8014 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08008015 phone.setSimPowerState(state, null, workSource);
8016 }
8017 } finally {
8018 Binder.restoreCallingIdentity(identity);
8019 }
8020 }
8021
8022 /**
8023 * Set SIM card power state.
8024 *
8025 * @param slotIndex SIM slot id.
8026 * @param state State of SIM (power down, power up, pass through)
8027 * @param callback callback to trigger after success or failure
8028 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
8029 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
8030 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
8031 *
8032 **/
8033 @Override
8034 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
8035 IIntegerConsumer callback) {
8036 enforceModifyPermission();
8037 Phone phone = PhoneFactory.getPhone(slotIndex);
8038
8039 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8040
8041 final long identity = Binder.clearCallingIdentity();
8042 try {
8043 if (phone != null) {
8044 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
8045 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008046 }
8047 } finally {
8048 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08008049 }
8050 }
Shuo Qiandd210312017-04-12 22:11:33 +00008051
Tyler Gunn65d45c22017-06-05 11:22:26 -07008052 private boolean isUssdApiAllowed(int subId) {
8053 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008054 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07008055 if (configManager == null) {
8056 return false;
8057 }
8058 PersistableBundle pb = configManager.getConfigForSubId(subId);
8059 if (pb == null) {
8060 return false;
8061 }
8062 return pb.getBoolean(
8063 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
8064 }
8065
Shuo Qiandd210312017-04-12 22:11:33 +00008066 /**
8067 * Check if phone is in emergency callback mode
8068 * @return true if phone is in emergency callback mode
8069 * @param subId sub id
8070 */
goneil9c5f4872017-12-05 14:07:56 -08008071 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00008072 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008073 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00008074 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
8078 if (phone != null) {
8079 return phone.isInEcm();
8080 } else {
8081 return false;
8082 }
8083 } finally {
8084 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00008085 }
8086 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008087
8088 /**
8089 * Get the current signal strength information for the given subscription.
8090 * Because this information is not updated when the device is in a low power state
8091 * it should not be relied-upon to be current.
8092 * @param subId Subscription index
8093 * @return the most recent cached signal strength info from the modem
8094 */
8095 @Override
8096 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008097 final long identity = Binder.clearCallingIdentity();
8098 try {
8099 Phone p = getPhone(subId);
8100 if (p == null) {
8101 return null;
8102 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008104 return p.getSignalStrength();
8105 } finally {
8106 Binder.restoreCallingIdentity(identity);
8107 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08008108 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008109
Pengquan Meng77b7f132018-08-22 14:49:57 -07008110 /**
Chen Xuf792fd62018-10-17 17:54:36 +00008111 * Get the current modem radio state for the given slot.
8112 * @param slotIndex slot index.
8113 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008114 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00008115 * @return the current radio power state from the modem
8116 */
8117 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008118 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00008119 Phone phone = PhoneFactory.getPhone(slotIndex);
8120 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008121 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
8122 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00008123 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8124 }
8125
8126 final long identity = Binder.clearCallingIdentity();
8127 try {
8128 return phone.getRadioPowerState();
8129 } finally {
8130 Binder.restoreCallingIdentity(identity);
8131 }
8132 }
8133 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
8134 }
8135
8136 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07008137 * Checks if data roaming is enabled on the subscription with id {@code subId}.
8138 *
8139 * <p>Requires one of the following permissions:
8140 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
8141 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
8142 * privileges.
8143 *
8144 * @param subId subscription id
8145 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
8146 * {@code false}.
8147 */
8148 @Override
8149 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07008150 try {
8151 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8152 null);
8153 } catch (Exception e) {
8154 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8155 mApp, subId, "isDataRoamingEnabled");
8156 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008157
Pengquan Menga1bb6272018-09-06 09:59:22 -07008158 boolean isEnabled = false;
8159 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008160 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008161 Phone phone = getPhone(subId);
8162 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008163 } finally {
8164 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008165 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008166 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008167 }
8168
8169
8170 /**
8171 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8172 *
8173 * <p> Requires permission:
8174 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8175 * privileges.
8176 *
8177 * @param subId subscription id
8178 * @param isEnabled {@code true} means enable, {@code false} means disable.
8179 */
8180 @Override
8181 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8183 mApp, subId, "setDataRoamingEnabled");
8184
Pengquan Menga1bb6272018-09-06 09:59:22 -07008185 final long identity = Binder.clearCallingIdentity();
8186 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008187 Phone phone = getPhone(subId);
8188 if (phone != null) {
8189 phone.setDataRoamingEnabled(isEnabled);
8190 }
8191 } finally {
8192 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008193 }
8194 }
8195
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008196 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008197 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008198 TelephonyPermissions
8199 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008200 mApp, subId, "isManualNetworkSelectionAllowed");
8201
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008202 boolean isAllowed = true;
8203 final long identity = Binder.clearCallingIdentity();
8204 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008205 Phone phone = getPhone(subId);
8206 if (phone != null) {
8207 isAllowed = phone.isCspPlmnEnabled();
8208 }
8209 } finally {
8210 Binder.restoreCallingIdentity(identity);
8211 }
8212 return isAllowed;
8213 }
8214
8215 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008216 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008217 // Verify that tha callingPackage belongs to the calling UID
8218 mApp.getSystemService(AppOpsManager.class)
8219 .checkPackage(Binder.getCallingUid(), callingPackage);
8220
Jordan Liu1e142fc2019-04-22 15:10:43 -07008221 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008222 try {
8223 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008224 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008225 } catch (SecurityException e) {
8226 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8227 // has carrier privileges on an active UICC
8228 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8229 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008230 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008231 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008232 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008233
8234 final long identity = Binder.clearCallingIdentity();
8235 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008236 UiccController uiccController = UiccController.getInstance();
8237 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008238 if (hasReadPermission) {
8239 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008240 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008241
8242 // Remove private info if the caller doesn't have access
8243 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8244 for (UiccCardInfo cardInfo : cardInfos) {
8245 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8246 // is available
8247 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8248 if (card == null || card.getUiccProfile() == null) {
8249 // assume no access if the card or profile is unavailable
8250 filteredInfos.add(cardInfo.getUnprivileged());
8251 continue;
8252 }
8253 UiccProfile profile = card.getUiccProfile();
8254 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8255 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8256 filteredInfos.add(cardInfo);
8257 } else {
8258 filteredInfos.add(cardInfo.getUnprivileged());
8259 }
8260 }
8261 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008262 } finally {
8263 Binder.restoreCallingIdentity(identity);
8264 }
8265 }
8266
8267 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008268 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008269 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008271 final long identity = Binder.clearCallingIdentity();
8272 try {
8273 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8274 if (slots == null) {
8275 Rlog.i(LOG_TAG, "slots is null.");
8276 return null;
8277 }
8278
8279 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8280 for (int i = 0; i < slots.length; i++) {
8281 UiccSlot slot = slots[i];
8282 if (slot == null) {
8283 continue;
8284 }
8285
Jordan Liu7be7e652019-05-06 18:55:02 +00008286 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008287 UiccCard card = slot.getUiccCard();
8288 if (card != null) {
8289 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008290 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008291 cardId = slot.getEid();
8292 if (TextUtils.isEmpty(cardId)) {
8293 cardId = slot.getIccId();
8294 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008295 }
8296
Jordan Liu857451f2019-05-09 16:35:35 -07008297 if (cardId != null) {
8298 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8299 // if cardId is an EID, it's all digits so this is fine
8300 cardId = IccUtils.stripTrailingFs(cardId);
8301 }
8302
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008303 int cardState = 0;
8304 switch (slot.getCardState()) {
8305 case CARDSTATE_ABSENT:
8306 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8307 break;
8308 case CARDSTATE_PRESENT:
8309 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8310 break;
8311 case CARDSTATE_ERROR:
8312 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8313 break;
8314 case CARDSTATE_RESTRICTED:
8315 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8316 break;
8317 default:
8318 break;
8319
8320 }
8321
8322 infos[i] = new UiccSlotInfo(
8323 slot.isActive(),
8324 slot.isEuicc(),
8325 cardId,
8326 cardState,
8327 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008328 slot.isExtendedApduSupported(),
8329 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008330 }
8331 return infos;
8332 } finally {
8333 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008334 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008335 }
8336
8337 @Override
8338 public boolean switchSlots(int[] physicalSlots) {
8339 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008340
8341 final long identity = Binder.clearCallingIdentity();
8342 try {
8343 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008347 }
Jack Yu4c988042018-02-27 15:30:01 -08008348
8349 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008350 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008351 final long identity = Binder.clearCallingIdentity();
8352 try {
8353 return UiccController.getInstance().getCardIdForDefaultEuicc();
8354 } finally {
8355 Binder.restoreCallingIdentity(identity);
8356 }
8357 }
8358
Pengquan Meng85728fb2018-03-12 16:31:21 -07008359 /**
goneil47ffb6e2018-04-06 15:40:58 -07008360 * A test API to reload the UICC profile.
8361 *
8362 * <p>Requires that the calling app has permission
8363 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8364 * @hide
8365 */
8366 @Override
8367 public void refreshUiccProfile(int subId) {
8368 enforceModifyPermission();
8369
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = getPhone(subId);
8373 if (phone == null) {
8374 return;
8375 }
8376 UiccCard uiccCard = phone.getUiccCard();
8377 if (uiccCard == null) {
8378 return;
8379 }
8380 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8381 if (uiccProfile == null) {
8382 return;
8383 }
8384 uiccProfile.refresh();
8385 } finally {
8386 Binder.restoreCallingIdentity(identity);
8387 }
8388 }
8389
8390 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008391 * Returns false if the mobile data is disabled by default, otherwise return true.
8392 */
8393 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008394 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008395 }
8396
8397 /**
8398 * Returns true if the data roaming is enabled by default, i.e the system property
8399 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8400 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8401 */
8402 private boolean getDefaultDataRoamingEnabled(int subId) {
8403 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008404 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008405 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008406 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8407 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8408 return isDataRoamingEnabled;
8409 }
8410
8411 /**
8412 * Returns the default network type for the given {@code subId}, if the default network type is
8413 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8414 */
8415 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008416 List<Integer> list = TelephonyProperties.default_network();
8417 int phoneId = mSubscriptionController.getPhoneId(subId);
8418 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8419 return list.get(phoneId);
8420 }
8421 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008422 }
fionaxua13278b2018-03-21 00:08:13 -07008423
8424 @Override
8425 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008426 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008427 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008428
8429 final long identity = Binder.clearCallingIdentity();
8430 try {
8431 final Phone phone = getPhone(subId);
8432 if (phone == null) {
8433 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8434 return;
8435 }
chen xueaba88a2019-03-15 13:15:10 -07008436 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8437 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008438 if (carrierPrivilegeRules == null) {
8439 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8440 } else {
8441 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8442 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008443 } finally {
8444 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008445 }
fionaxua13278b2018-03-21 00:08:13 -07008446 }
8447
8448 @Override
8449 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008450 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008451
8452 final long identity = Binder.clearCallingIdentity();
8453 try {
8454 final Phone phone = getPhone(subId);
8455 if (phone == null) {
8456 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8457 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8458 }
8459 return phone.getCarrierIdListVersion();
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008462 }
fionaxua13278b2018-03-21 00:08:13 -07008463 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008464
8465 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008466 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8467 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008468 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008469 mApp, subId, callingPackage, callingFeatureId,
8470 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008471 return -1;
8472 }
8473
8474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8477 } finally {
8478 Binder.restoreCallingIdentity(identity);
8479 }
8480 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008481
8482 @Override
8483 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008484 TelephonyPermissions
8485 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008486 mApp, subId, "getCdmaRoamingMode");
8487
8488 final long identity = Binder.clearCallingIdentity();
8489 try {
8490 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 }
8495
8496 @Override
8497 public boolean setCdmaRoamingMode(int subId, int mode) {
8498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8499 mApp, subId, "setCdmaRoamingMode");
8500
8501 final long identity = Binder.clearCallingIdentity();
8502 try {
8503 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8504 } finally {
8505 Binder.restoreCallingIdentity(identity);
8506 }
8507 }
8508
8509 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008510 public int getCdmaSubscriptionMode(int subId) {
8511 TelephonyPermissions
8512 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8513 mApp, subId, "getCdmaSubscriptionMode");
8514
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8518 } finally {
8519 Binder.restoreCallingIdentity(identity);
8520 }
8521 }
8522
8523 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008524 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8525 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8526 mApp, subId, "setCdmaSubscriptionMode");
8527
8528 final long identity = Binder.clearCallingIdentity();
8529 try {
8530 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8531 } finally {
8532 Binder.restoreCallingIdentity(identity);
8533 }
8534 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008535
sqianc5eccab2018-10-19 18:46:41 -07008536 @Override
sqian8c685422019-02-22 15:55:18 -08008537 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008538 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008539 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008540 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8541 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008542 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8543 }
8544 final long identity = Binder.clearCallingIdentity();
8545 try {
sqian854d44b2018-12-12 16:48:18 -08008546 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8547 for (Phone phone: PhoneFactory.getPhones()) {
8548 if (phone.getEmergencyNumberTracker() != null
8549 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8550 emergencyNumberListInternal.put(
8551 phone.getSubId(),
8552 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8553 }
sqian11b7a0e2018-12-05 18:48:28 -08008554 }
sqian854d44b2018-12-12 16:48:18 -08008555 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
sqianc5eccab2018-10-19 18:46:41 -07008559 }
8560
8561 @Override
sqian8c685422019-02-22 15:55:18 -08008562 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008563 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008564 if (!exactMatch) {
8565 TelephonyPermissions
8566 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008567 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008568 }
8569 final long identity = Binder.clearCallingIdentity();
8570 try {
sqian854d44b2018-12-12 16:48:18 -08008571 for (Phone phone: PhoneFactory.getPhones()) {
8572 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008573 && phone.getEmergencyNumberTracker()
8574 .isEmergencyNumber(number, exactMatch)) {
8575 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008576 }
sqian11b7a0e2018-12-05 18:48:28 -08008577 }
8578 return false;
8579 } finally {
8580 Binder.restoreCallingIdentity(identity);
8581 }
8582 }
8583
sqianf4ca7ed2019-01-15 18:32:07 -08008584 /**
8585 * Update emergency number list for test mode.
8586 */
8587 @Override
8588 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8589 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8590 "updateEmergencyNumberListTestMode");
8591
8592 final long identity = Binder.clearCallingIdentity();
8593 try {
8594 for (Phone phone: PhoneFactory.getPhones()) {
8595 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8596 if (tracker != null) {
8597 tracker.executeEmergencyNumberTestModeCommand(action, num);
8598 }
8599 }
8600 } finally {
8601 Binder.restoreCallingIdentity(identity);
8602 }
8603 }
8604
8605 /**
8606 * Get the full emergency number list for test mode.
8607 */
8608 @Override
8609 public List<String> getEmergencyNumberListTestMode() {
8610 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8611 "getEmergencyNumberListTestMode");
8612
8613 final long identity = Binder.clearCallingIdentity();
8614 try {
8615 Set<String> emergencyNumbers = new HashSet<>();
8616 for (Phone phone: PhoneFactory.getPhones()) {
8617 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8618 if (tracker != null) {
8619 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8620 emergencyNumbers.add(num.getNumber());
8621 }
8622 }
8623 }
8624 return new ArrayList<>(emergencyNumbers);
8625 } finally {
8626 Binder.restoreCallingIdentity(identity);
8627 }
8628 }
8629
chen xud6b45bd2018-10-30 22:27:10 -07008630 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008631 public int getEmergencyNumberDbVersion(int subId) {
8632 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8633
8634 final long identity = Binder.clearCallingIdentity();
8635 try {
8636 final Phone phone = getPhone(subId);
8637 if (phone == null) {
8638 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8639 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8640 }
8641 return phone.getEmergencyNumberDbVersion();
8642 } finally {
8643 Binder.restoreCallingIdentity(identity);
8644 }
8645 }
8646
8647 @Override
8648 public void notifyOtaEmergencyNumberDbInstalled() {
8649 enforceModifyPermission();
8650
8651 final long identity = Binder.clearCallingIdentity();
8652 try {
8653 for (Phone phone: PhoneFactory.getPhones()) {
8654 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8655 if (tracker != null) {
8656 tracker.updateOtaEmergencyNumberDatabase();
8657 }
8658 }
8659 } finally {
8660 Binder.restoreCallingIdentity(identity);
8661 }
8662 }
8663
8664 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008665 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008666 enforceActiveEmergencySessionPermission();
8667
8668 final long identity = Binder.clearCallingIdentity();
8669 try {
8670 for (Phone phone: PhoneFactory.getPhones()) {
8671 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8672 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008673 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8674 }
8675 }
8676 } finally {
8677 Binder.restoreCallingIdentity(identity);
8678 }
8679 }
8680
8681 @Override
8682 public void resetOtaEmergencyNumberDbFilePath() {
8683 enforceActiveEmergencySessionPermission();
8684
8685 final long identity = Binder.clearCallingIdentity();
8686 try {
8687 for (Phone phone: PhoneFactory.getPhones()) {
8688 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8689 if (tracker != null) {
8690 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008691 }
8692 }
8693 } finally {
8694 Binder.restoreCallingIdentity(identity);
8695 }
8696 }
8697
8698 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008699 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8700 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8701 Phone phone = getPhone(subId);
8702 if (phone == null) {
8703 return null;
8704 }
8705 final long identity = Binder.clearCallingIdentity();
8706 try {
8707 UiccProfile profile = UiccController.getInstance()
8708 .getUiccProfileForPhone(phone.getPhoneId());
8709 if (profile != null) {
8710 return profile.getCertsFromCarrierPrivilegeAccessRules();
8711 }
8712 } finally {
8713 Binder.restoreCallingIdentity(identity);
8714 }
8715 return null;
8716 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008717
8718 /**
8719 * Enable or disable a modem stack.
8720 */
8721 @Override
8722 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8723 enforceModifyPermission();
8724
8725 final long identity = Binder.clearCallingIdentity();
8726 try {
8727 Phone phone = PhoneFactory.getPhone(slotIndex);
8728 if (phone == null) {
8729 return false;
8730 } else {
8731 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8732 }
8733 } finally {
8734 Binder.restoreCallingIdentity(identity);
8735 }
8736 }
Michelecea4cf22018-12-21 15:00:11 -08008737
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008738 /**
8739 * Whether a modem stack is enabled or not.
8740 */
8741 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008742 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8743 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008744 Phone phone = PhoneFactory.getPhone(slotIndex);
8745 if (phone == null) return false;
8746
8747 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008748 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8749 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008750 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8751 }
8752
8753 final long identity = Binder.clearCallingIdentity();
8754 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008755 try {
8756 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8757 } catch (NoSuchElementException ex) {
8758 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8759 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008760 } finally {
8761 Binder.restoreCallingIdentity(identity);
8762 }
8763 }
8764
Michelecea4cf22018-12-21 15:00:11 -08008765 @Override
Michele0ea7d782019-03-19 14:58:42 -07008766 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008767 enforceModifyPermission();
8768
8769 final long identity = Binder.clearCallingIdentity();
8770 try {
8771 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008772 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008773 .commit();
8774 } finally {
8775 Binder.restoreCallingIdentity(identity);
8776 }
8777 }
8778
8779 @Override
Michele0ea7d782019-03-19 14:58:42 -07008780 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008781 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008782 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008783 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8784 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008785 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008786 }
Michelecea4cf22018-12-21 15:00:11 -08008787
8788 final long identity = Binder.clearCallingIdentity();
8789 try {
Michele0ea7d782019-03-19 14:58:42 -07008790 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008791 } finally {
8792 Binder.restoreCallingIdentity(identity);
8793 }
8794 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008795
Michele0ea7d782019-03-19 14:58:42 -07008796 @TelephonyManager.IsMultiSimSupportedResult
8797 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008798 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8799 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8800 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008801 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8802 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008803 }
8804 // Check if the hardware supports multisim functionality. If usage of multisim is not
8805 // supported by the modem, indicate that it is restricted.
8806 PhoneCapability staticCapability =
8807 mPhoneConfigurationManager.getStaticPhoneCapability();
8808 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008809 loge("isMultiSimSupportedInternal: no static configuration available");
8810 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008811 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008812 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008813 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8814 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008815 }
8816 // Check if support of multiple SIMs is restricted by carrier
8817 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008818 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008819 }
8820
Michele0ea7d782019-03-19 14:58:42 -07008821 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008822 }
8823
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008824 /**
8825 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008826 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8827 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8828 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008829 * @param numOfSims number of active sims we want to switch to
8830 */
8831 @Override
8832 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008833 if (numOfSims == 1) {
8834 enforceModifyPermission();
8835 } else {
8836 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8837 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8838 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008839 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008840
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008841 try {
Michele30b57b22019-03-01 12:01:14 -08008842 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008843 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008844 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8845 return;
8846 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008847 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8848 } finally {
8849 Binder.restoreCallingIdentity(identity);
8850 }
8851 }
8852
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008853 @Override
8854 public boolean isApplicationOnUicc(int subId, int appType) {
8855 enforceReadPrivilegedPermission("isApplicationOnUicc");
8856 Phone phone = getPhone(subId);
8857 if (phone == null) {
8858 return false;
8859 }
8860 final long identity = Binder.clearCallingIdentity();
8861 try {
8862 UiccCard uiccCard = phone.getUiccCard();
8863 if (uiccCard == null) {
8864 return false;
8865 }
8866 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8867 if (uiccProfile == null) {
8868 return false;
8869 }
8870 if (TelephonyManager.APPTYPE_SIM <= appType
8871 && appType <= TelephonyManager.APPTYPE_ISIM) {
8872 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8873 }
8874 return false;
8875 } finally {
8876 Binder.restoreCallingIdentity(identity);
8877 }
8878 }
8879
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008880 /**
chen xub4baa772019-04-03 10:23:41 -07008881 * Get whether making changes to modem configurations will trigger reboot.
8882 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008883 */
8884 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008885 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8886 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008887 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008888 mApp, subId, callingPackage, callingFeatureId,
8889 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008890 return false;
8891 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008892 final long identity = Binder.clearCallingIdentity();
8893 try {
8894 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8895 } finally {
8896 Binder.restoreCallingIdentity(identity);
8897 }
8898 }
8899
Nathan Harold29f5f052019-02-15 13:41:57 -08008900 private void updateModemStateMetrics() {
8901 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8902 // TODO: check the state for each modem if the api is ready.
8903 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8904 }
8905
Pengquan Meng3889a572019-01-23 11:16:29 -08008906 @Override
8907 public int[] getSlotsMapping() {
8908 enforceReadPrivilegedPermission("getSlotsMapping");
8909
8910 final long identity = Binder.clearCallingIdentity();
8911 try {
8912 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8913 // All logical slots should have a mapping to a physical slot.
8914 int[] logicalSlotsMapping = new int[phoneCount];
8915 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8916 for (int i = 0; i < slotInfos.length; i++) {
8917 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8918 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8919 }
8920 }
8921 return logicalSlotsMapping;
8922 } finally {
8923 Binder.restoreCallingIdentity(identity);
8924 }
8925 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008926
8927 /**
8928 * Get the IRadio HAL Version
8929 */
8930 @Override
8931 public int getRadioHalVersion() {
8932 Phone phone = getDefaultPhone();
8933 if (phone == null) return -1;
8934 HalVersion hv = phone.getHalVersion();
8935 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8936 return hv.major * 100 + hv.minor;
8937 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008938
8939 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008940 * Get the current calling package name.
8941 * @return the current calling package name
8942 */
8943 @Override
8944 public String getCurrentPackageName() {
8945 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8946 }
8947
8948 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008949 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8950 * corresponding network requests on a subId.
8951 *
8952 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008953 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008954 * 2) APN is un-metered for this subscription, or
8955 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008956 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008957 *
8958 * @return whether data is allowed for a apn type.
8959 *
8960 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008961 */
8962 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008963 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008964 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8965 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008966
8967 // Now that all security checks passes, perform the operation as ourselves.
8968 final long identity = Binder.clearCallingIdentity();
8969 try {
8970 Phone phone = getPhone(subId);
8971 if (phone == null) return false;
8972
Jack Yu41407ee2019-05-13 16:54:09 -07008973 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008974 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8975 } finally {
8976 Binder.restoreCallingIdentity(identity);
8977 }
8978 }
8979
8980 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008981 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008982 enforceReadPrivilegedPermission("isApnMetered");
8983
8984 // Now that all security checks passes, perform the operation as ourselves.
8985 final long identity = Binder.clearCallingIdentity();
8986 try {
8987 Phone phone = getPhone(subId);
8988 if (phone == null) return true; // By default return true.
8989
Jack Yu41407ee2019-05-13 16:54:09 -07008990 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008991 } finally {
8992 Binder.restoreCallingIdentity(identity);
8993 }
8994 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008995
8996 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008997 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8998 int subscriptionId, IBooleanConsumer resultCallback) {
8999 enforceModifyPermission();
9000 long token = Binder.clearCallingIdentity();
9001 try {
9002 Phone phone = getPhone(subscriptionId);
9003 if (phone == null) {
9004 try {
9005 if (resultCallback != null) {
9006 resultCallback.accept(false);
9007 }
9008 } catch (RemoteException e) {
9009 // ignore
9010 }
9011 return;
9012 }
9013 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
9014 Pair.create(specifiers, (x) -> {
9015 try {
9016 if (resultCallback != null) {
9017 resultCallback.accept(x);
9018 }
9019 } catch (RemoteException e) {
9020 // ignore
9021 }
9022 });
9023 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
9024 } finally {
9025 Binder.restoreCallingIdentity(token);
9026 }
9027 }
9028
9029 @Override
Sarah Chincc055732020-11-18 13:39:35 -08009030 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
9031 TelephonyPermissions
9032 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
9033 mApp, subId, "getSystemSelectionChannels");
9034 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9035 final long identity = Binder.clearCallingIdentity();
9036 try {
9037 List<RadioAccessSpecifier> specifiers =
9038 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
9039 null, subId, workSource);
9040 if (DBG) log("getSystemSelectionChannels: " + specifiers);
9041 return specifiers;
9042 } finally {
9043 Binder.restoreCallingIdentity(identity);
9044 }
9045 }
9046
9047 @Override
changbetty363e8ac2019-12-06 18:16:37 +08009048 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08009049 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08009050 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
9051 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
9052 if (iccRecords == null) {
9053 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
9054 return false;
9055 }
9056 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
9057 }
9058
9059 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009060 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
9061 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08009062 if (callingPackage == null) {
9063 callingPackage = getCurrentPackageName();
9064 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07009065 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
9066 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07009067 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
9068 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07009069 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
9070 }
9071 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
9072 Intent intent = new Intent();
9073 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
9074 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
9075 // Bring up choose default SMS subscription dialog right now
9076 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
9077 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
9078 mApp.startActivity(intent);
9079 }
chen xud5ca2d52019-05-28 15:20:57 -07009080
9081 @Override
9082 public String getMmsUAProfUrl(int subId) {
9083 //TODO investigate if this API should require proper permission check in R b/133791609
9084 final long identity = Binder.clearCallingIdentity();
9085 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009086 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
9087 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
9088 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
9089 return carrierUAProfUrl;
9090 }
chen xud5ca2d52019-05-28 15:20:57 -07009091 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9092 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
9093 } finally {
9094 Binder.restoreCallingIdentity(identity);
9095 }
9096 }
9097
9098 @Override
9099 public String getMmsUserAgent(int subId) {
9100 //TODO investigate if this API should require proper permission check in R b/133791609
9101 final long identity = Binder.clearCallingIdentity();
9102 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08009103 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
9104 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
9105 if (!TextUtils.isEmpty(carrierUserAgent)) {
9106 return carrierUserAgent;
9107 }
chen xud5ca2d52019-05-28 15:20:57 -07009108 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
9109 .getString(com.android.internal.R.string.config_mms_user_agent);
9110 } finally {
9111 Binder.restoreCallingIdentity(identity);
9112 }
9113 }
Jack Yub07d4972019-05-28 16:12:25 -07009114
9115 @Override
Hall Liuc041a552020-09-25 10:42:19 -07009116 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
9117 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
9118
9119 final long identity = Binder.clearCallingIdentity();
9120 try {
9121 Phone phone = getPhone(subscriptionId);
9122 if (phone == null) return false;
9123
9124 switch (policy) {
9125 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9126 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
9127 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9128 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
9129 default:
9130 throw new IllegalArgumentException(policy + " is not a valid policy");
9131 }
9132 } finally {
9133 Binder.restoreCallingIdentity(identity);
9134 }
9135 }
9136
9137 @Override
9138 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
9139 boolean enabled) {
9140 enforceModifyPermission();
9141
9142 final long identity = Binder.clearCallingIdentity();
9143 try {
9144 Phone phone = getPhone(subscriptionId);
9145 if (phone == null) return;
9146
9147 switch (policy) {
9148 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
9149 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
9150 break;
9151 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9152 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9153 break;
9154 default:
9155 throw new IllegalArgumentException(policy + " is not a valid policy");
9156 }
9157 } finally {
9158 Binder.restoreCallingIdentity(identity);
9159 }
9160 }
9161
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009162 /**
Hall Liub48cf452020-09-25 11:13:49 -07009163 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009164 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9165 * otherwise.
9166 */
9167 @Override
9168 public void setCepEnabled(boolean isCepEnabled) {
9169 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9170
9171 final long identity = Binder.clearCallingIdentity();
9172 try {
9173 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9174 for (Phone phone : PhoneFactory.getPhones()) {
9175 Phone defaultPhone = phone.getImsPhone();
9176 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9177 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9178 ImsPhoneCallTracker imsPhoneCallTracker =
9179 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9180 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9181 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9182 + imsPhone.getMsisdn());
9183 }
9184 }
9185 } finally {
9186 Binder.restoreCallingIdentity(identity);
9187 }
9188 }
allenwtsu46dcc572020-01-08 18:24:03 +08009189
9190 /**
9191 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9192 *
9193 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9194 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9195 * before being read.
9196 */
9197 @Override
9198 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9199 isCompressed) {
9200 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9201 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009202 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9203 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9204 }
9205 if (!isImsAvailableOnDevice()) {
9206 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9207 "IMS not available on device.");
9208 }
9209
9210 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009211 try {
Hui Wang068ab862020-10-31 05:12:53 +00009212 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9213 } finally {
9214 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009215 }
9216 }
zoey chenf95ca592019-12-30 16:11:23 +08009217
9218 @Override
9219 public boolean isIccLockEnabled(int subId) {
9220 enforceReadPrivilegedPermission("isIccLockEnabled");
9221
9222 // Now that all security checks passes, perform the operation as ourselves.
9223 final long identity = Binder.clearCallingIdentity();
9224 try {
9225 Phone phone = getPhone(subId);
9226 if (phone != null && phone.getIccCard() != null) {
9227 return phone.getIccCard().getIccLockEnabled();
9228 } else {
9229 return false;
9230 }
9231 } finally {
9232 Binder.restoreCallingIdentity(identity);
9233 }
9234 }
9235
9236 /**
zoey chene02881a2019-12-30 16:11:23 +08009237 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009238 *
zoey chene02881a2019-12-30 16:11:23 +08009239 * @return an integer representing the status of IccLock enabled or disabled in the following
9240 * three cases:
9241 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9242 * successfully.
9243 * - Positive number and zero for remaining password attempts.
9244 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009245 *
9246 */
9247 @Override
9248 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9249 enforceModifyPermission();
9250
9251 Phone phone = getPhone(subId);
9252 if (phone == null) {
9253 return 0;
9254 }
9255 // Now that all security checks passes, perform the operation as ourselves.
9256 final long identity = Binder.clearCallingIdentity();
9257 try {
9258 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9259 new Pair<Boolean, String>(enabled, password), phone, null);
9260 return attemptsRemaining;
9261
9262 } catch (Exception e) {
9263 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9264 } finally {
9265 Binder.restoreCallingIdentity(identity);
9266 }
9267 return 0;
9268 }
9269
9270 /**
9271 * Change the ICC password used in ICC pin lock.
9272 *
zoey chene02881a2019-12-30 16:11:23 +08009273 * @return an integer representing the status of IccLock changed in the following three cases:
9274 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9275 * - Positive number and zero for remaining password attempts.
9276 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009277 *
9278 */
9279 @Override
9280 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9281 enforceModifyPermission();
9282
9283 Phone phone = getPhone(subId);
9284 if (phone == null) {
9285 return 0;
9286 }
9287 // Now that all security checks passes, perform the operation as ourselves.
9288 final long identity = Binder.clearCallingIdentity();
9289 try {
9290 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9291 new Pair<String, String>(oldPassword, newPassword), phone, null);
9292 return attemptsRemaining;
9293
9294 } catch (Exception e) {
9295 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9296 } finally {
9297 Binder.restoreCallingIdentity(identity);
9298 }
9299 return 0;
9300 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009301
Peter Wangdafb9ac2020-01-15 14:13:38 -08009302 /**
9303 * Request for receiving user activity notification
9304 */
9305 @Override
9306 public void requestUserActivityNotification() {
9307 if (!mNotifyUserActivity.get()
9308 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9309 mNotifyUserActivity.set(true);
9310 }
9311 }
9312
9313 /**
9314 * Called when userActivity is signalled in the power manager.
9315 * This is safe to call from any thread, with any window manager locks held or not.
9316 */
9317 @Override
9318 public void userActivity() {
9319 // ***************************************
9320 // * Inherited from PhoneWindowManager *
9321 // ***************************************
9322 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9323 // WITH ITS LOCKS HELD.
9324 //
9325 // This code must be VERY careful about the locks
9326 // it acquires.
9327 // In fact, the current code acquires way too many,
9328 // and probably has lurking deadlocks.
9329
9330 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9331 throw new SecurityException("Only the OS may call notifyUserActivity()");
9332 }
9333
9334 if (mNotifyUserActivity.getAndSet(false)) {
9335 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9336 USER_ACTIVITY_NOTIFICATION_DELAY);
9337 }
9338 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009339
Malcolm Chen884180b2020-04-13 11:59:40 -07009340 @Override
9341 public boolean canConnectTo5GInDsdsMode() {
9342 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9343 }
Jack Yud10cdd42020-09-28 20:28:01 -07009344
9345 @Override
9346 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9347 String callingFeatureId) {
9348 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9349 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9350 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9351 }
9352
9353 Phone phone = getPhone(subId);
9354 if (phone == null) {
9355 throw new RuntimeException("phone is not available");
9356 }
9357 // Now that all security checks passes, perform the operation as ourselves.
9358 final long identity = Binder.clearCallingIdentity();
9359 try {
9360 return phone.getEquivalentHomePlmns();
9361 } finally {
9362 Binder.restoreCallingIdentity(identity);
9363 }
9364 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009365
Hui Wang0866fcc2020-10-12 12:14:23 -07009366 @Override
Daniel Bright74f1ca82020-11-13 11:49:37 -08009367 public boolean isRadioInterfaceCapabilitySupported(
9368 @NonNull @TelephonyManager.RadioInterfaceCapability String capability) {
9369 RadioInterfaceCapabilities radioInterfaceCapabilities =
9370 mPhoneConfigurationManager.getRadioInterfaceCapabilities();
9371 if (radioInterfaceCapabilities == null) {
9372 throw new RuntimeException("radio interface capabilities are not available");
9373 } else {
9374 return radioInterfaceCapabilities.isSupported(capability);
9375 }
9376 }
9377
9378 @Override
Hui Wang0866fcc2020-10-12 12:14:23 -07009379 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9380 UaSecurityProtocolIdentifier securityProtocol,
9381 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9382 throws RemoteException {
9383 enforceModifyPermission();
9384 if (DBG) {
9385 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9386 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9387 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9388 }
9389
9390 if (!SubscriptionManager.isValidSubscriptionId(subId)
9391 || appType < TelephonyManager.APPTYPE_UNKNOWN
9392 || appType > TelephonyManager.APPTYPE_ISIM
9393 || nafUrl == null || securityProtocol == null || callback == null) {
9394 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9395 if (callback != null) {
9396 try {
9397 callback.onAuthenticationFailure(
9398 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9399 } catch (RemoteException exception) {
9400 log("Fail to notify onAuthenticationFailure due to " + exception);
9401 }
9402 return;
9403 }
9404 }
9405
9406 final long token = Binder.clearCallingIdentity();
9407 try {
9408 getGbaManager(subId).bootstrapAuthenticationRequest(
9409 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9410 forceBootStrapping, callback));
9411 } finally {
9412 Binder.restoreCallingIdentity(token);
9413 }
9414 }
9415
Jack Nudelman24d51a52020-11-24 12:08:04 -08009416 /**
9417 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9418 * requested radio power state will actually be set. See {@link
9419 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9420 *
9421 * @param subId the subscription ID of the phone requesting to set the radio power state.
9422 * @param enable {@code true} if trying to turn radio on.
9423 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9424 * false}.
9425 */
9426 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9427 Phone phone = getPhone(subId);
9428 if (phone != null) {
9429 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9430 return true;
9431 }
9432 return false;
9433 }
9434
9435 private int handleDataThrottlingRequest(int subId,
9436 DataThrottlingRequest dataThrottlingRequest) {
9437 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9438 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9439 if (!setRadioPowerForThermal(subId, true)) {
9440 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9441 }
9442
9443 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9444
9445 int thermalMitigationResult =
9446 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9447 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9448 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9449 }
9450 return thermalMitigationResult;
9451 }
9452
9453 /**
9454 * Thermal mitigation request to control functionalities at modem.
9455 *
9456 * @param subId the id of the subscription.
9457 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9458 *
9459 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9460 */
9461 @Override
9462 @ThermalMitigationResult
9463 public int sendThermalMitigationRequest(
9464 int subId,
9465 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9466 enforceModifyPermission();
9467
9468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9469 final long identity = Binder.clearCallingIdentity();
9470
9471 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9472 try {
9473 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9474 switch (thermalMitigationAction) {
9475 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9476 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009477 handleDataThrottlingRequest(subId,
9478 thermalMitigationRequest.getDataThrottlingRequest());
Jack Nudelman24d51a52020-11-24 12:08:04 -08009479 break;
9480 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9481 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9482 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9483 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9484 }
9485
9486 // Ensure that radio is on. If not able to power on due to phone being
9487 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9488 if (!setRadioPowerForThermal(subId, true)) {
9489 thermalMitigationResult =
9490 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9491 break;
9492 }
9493
9494 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9495 false);
9496 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9497 break;
9498 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9499 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9500 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9501 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9502 }
9503
9504 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9505 if (registry != null) {
9506 TelephonyConnectionService service =
9507 registry.getTelephonyConnectionService();
9508 Phone phone = getPhone(subId);
9509 if (phone == null) {
9510 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009511 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009512 break;
9513 }
9514
9515 if (PhoneConstantConversions.convertCallState(phone.getState())
Daniel Bright74f1ca82020-11-13 11:49:37 -08009516 != TelephonyManager.CALL_STATE_IDLE
9517 || phone.isInEmergencySmsMode() || phone.isInEcm()
9518 || (service != null && service.isEmergencyCallPending())) {
Jack Nudelman24d51a52020-11-24 12:08:04 -08009519 String errorMessage = "Phone state is not valid. call state = "
9520 + PhoneConstantConversions.convertCallState(phone.getState())
9521 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9522 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9523 errorMessage += service == null
9524 ? " TelephonyConnectionService is null"
9525 : " isEmergencyCallPending = "
9526 + service.isEmergencyCallPending();
9527 Log.e(LOG_TAG, errorMessage);
9528 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009529 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009530 break;
9531 }
9532 } else {
9533 thermalMitigationResult =
9534 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9535 break;
9536 }
9537
9538 // Turn radio off. If not able to power off due to phone being unavailable,
9539 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9540 if (!setRadioPowerForThermal(subId, false)) {
9541 thermalMitigationResult =
9542 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9543 break;
9544 }
9545 thermalMitigationResult =
Daniel Bright74f1ca82020-11-13 11:49:37 -08009546 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
Jack Nudelman24d51a52020-11-24 12:08:04 -08009547 break;
9548 default:
9549 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9550 + "not exist. Requested action: " + thermalMitigationAction);
9551 }
9552 } catch (IllegalArgumentException e) {
9553 throw e;
9554 } catch (Exception e) {
9555 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9556 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9557 } finally {
9558 Binder.restoreCallingIdentity(identity);
9559 }
9560
9561 if (DBG) {
9562 log("thermalMitigationRequest returning with thermalMitigationResult: "
9563 + thermalMitigationResult);
9564 }
9565
9566 return thermalMitigationResult;
9567 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009568
9569 /**
9570 * Set the GbaService Package Name that Telephony will bind to.
9571 *
9572 * @param subId The sim that the GbaService is associated with.
9573 * @param packageName The name of the package to be replaced with.
9574 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9575 */
9576 @Override
9577 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9578 enforceModifyPermission();
9579
9580 final long identity = Binder.clearCallingIdentity();
9581 try {
9582 return getGbaManager(subId).overrideServicePackage(packageName);
9583 } finally {
9584 Binder.restoreCallingIdentity(identity);
9585 }
9586 }
9587
9588 /**
9589 * Return the package name of the currently bound GbaService.
9590 *
9591 * @param subId The sim that the GbaService is associated with.
9592 * @return the package name of the GbaService configuration, null if GBA is not supported.
9593 */
9594 @Override
9595 public String getBoundGbaService(int subId) {
9596 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9597
9598 final long identity = Binder.clearCallingIdentity();
9599 try {
9600 return getGbaManager(subId).getServicePackage();
9601 } finally {
9602 Binder.restoreCallingIdentity(identity);
9603 }
9604 }
9605
9606 /**
9607 * Set the release time for telephony to unbind GbaService.
9608 *
9609 * @param subId The sim that the GbaService is associated with.
9610 * @param interval The release time to unbind GbaService by millisecond.
9611 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9612 */
9613 @Override
9614 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9615 enforceModifyPermission();
9616
9617 final long identity = Binder.clearCallingIdentity();
9618 try {
9619 return getGbaManager(subId).overrideReleaseTime(interval);
9620 } finally {
9621 Binder.restoreCallingIdentity(identity);
9622 }
9623 }
9624
9625 /**
9626 * Return the release time for telephony to unbind GbaService.
9627 *
9628 * @param subId The sim that the GbaService is associated with.
9629 * @return The release time to unbind GbaService by millisecond.
9630 */
9631 @Override
9632 public int getGbaReleaseTime(int subId) {
9633 enforceReadPrivilegedPermission("getGbaReleaseTime");
9634
9635 final long identity = Binder.clearCallingIdentity();
9636 try {
9637 return getGbaManager(subId).getReleaseTime();
9638 } finally {
9639 Binder.restoreCallingIdentity(identity);
9640 }
9641 }
9642
9643 private GbaManager getGbaManager(int subId) {
9644 GbaManager instance = GbaManager.getInstance(subId);
9645 if (instance == null) {
9646 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9647 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9648 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9649 }
9650 return instance;
9651 }
Hui Wang068ab862020-10-31 05:12:53 +00009652
9653 /**
9654 * indicate whether the device and the carrier can support
9655 * RCS VoLTE single registration.
9656 */
9657 @Override
9658 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9659 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9660
9661 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9662 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9663 }
9664
9665 final long identity = Binder.clearCallingIdentity();
9666 try {
9667 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9668 if (rpm != null) {
9669 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9670 }
9671 return false;
9672 } finally {
9673 Binder.restoreCallingIdentity(identity);
9674 }
9675 }
9676
9677 /**
9678 * Register RCS provisioning callback.
9679 */
9680 @Override
9681 public void registerRcsProvisioningChangedCallback(int subId,
9682 IRcsConfigCallback callback) {
9683 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9684
9685 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9686 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9687 }
9688 if (!isImsAvailableOnDevice()) {
9689 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9690 "IMS not available on device.");
9691 }
9692
9693 final long identity = Binder.clearCallingIdentity();
9694 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009695 if (!RcsProvisioningMonitor.getInstance()
9696 .registerRcsProvisioningChangedCallback(subId, callback)) {
9697 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9698 "Service not available for the subscription.");
9699 }
Hui Wang068ab862020-10-31 05:12:53 +00009700 } finally {
9701 Binder.restoreCallingIdentity(identity);
9702 }
9703 }
9704
9705 /**
9706 * Unregister RCS provisioning callback.
9707 */
9708 @Override
9709 public void unregisterRcsProvisioningChangedCallback(int subId,
9710 IRcsConfigCallback callback) {
9711 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9712
9713 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9714 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9715 }
9716 if (!isImsAvailableOnDevice()) {
9717 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9718 "IMS not available on device.");
9719 }
9720
9721 final long identity = Binder.clearCallingIdentity();
9722 try {
Hui Wang713d45f2021-01-11 20:04:53 -08009723 RcsProvisioningMonitor.getInstance()
9724 .unregisterRcsProvisioningChangedCallback(subId, callback);
Hui Wang068ab862020-10-31 05:12:53 +00009725 } finally {
9726 Binder.restoreCallingIdentity(identity);
9727 }
9728 }
9729
9730 /**
9731 * trigger RCS reconfiguration.
9732 */
9733 public void triggerRcsReconfiguration(int subId) {
9734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9735 mApp, subId, "triggerRcsReconfiguration");
9736
9737 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9738 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9739 }
9740 if (!isImsAvailableOnDevice()) {
9741 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9742 "IMS not available on device.");
9743 }
9744
9745 final long identity = Binder.clearCallingIdentity();
9746 try {
9747 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9748 } finally {
9749 Binder.restoreCallingIdentity(identity);
9750 }
9751 }
9752
9753 /**
9754 * Provide the client configuration parameters of the RCS application.
9755 */
9756 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9757 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9758 mApp, subId, "setRcsClientConfiguration");
9759
9760 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9761 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9762 }
9763 if (!isImsAvailableOnDevice()) {
9764 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9765 "IMS not available on device.");
9766 }
9767
9768 final long identity = Binder.clearCallingIdentity();
9769
9770 try {
9771 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9772 if (configBinder == null) {
9773 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9774 } else {
9775 configBinder.setRcsClientConfiguration(rcc);
9776 }
9777 } catch (RemoteException e) {
9778 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9779 } finally {
9780 Binder.restoreCallingIdentity(identity);
9781 }
9782 }
9783
9784 /**
9785 * Overrides the config of RCS VoLTE single registration enabled for the device.
9786 */
9787 @Override
9788 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9789 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9790 "setDeviceSingleRegistrationEnabledOverride");
9791 enforceModifyPermission();
9792
9793 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9794 : Boolean.parseBoolean(enabledStr);
9795 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
Brad Ebinger49a72b42021-01-29 00:55:24 +00009796 mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled);
Hui Wang068ab862020-10-31 05:12:53 +00009797 }
9798
9799 /**
Tyler Gunn92479152021-01-20 16:30:10 -08009800 * Sends a device to device communication message. Only usable via shell.
9801 * @param message message to send.
9802 * @param value message value.
9803 */
9804 @Override
9805 public void sendDeviceToDeviceMessage(int message, int value) {
9806 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9807 "setCarrierSingleRegistrationEnabledOverride");
9808 enforceModifyPermission();
9809
9810 final long identity = Binder.clearCallingIdentity();
9811 try {
9812 TelephonyConnectionService service =
9813 TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService();
9814 if (service == null) {
9815 Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call.");
9816 return;
9817 }
9818 service.sendTestDeviceToDeviceMessage(message, value);
9819 } finally {
9820 Binder.restoreCallingIdentity(identity);
9821 }
9822 }
9823
9824
9825 /**
Hui Wang068ab862020-10-31 05:12:53 +00009826 * Gets the config of RCS VoLTE single registration enabled for the device.
9827 */
9828 @Override
9829 public boolean getDeviceSingleRegistrationEnabled() {
9830 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9831 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9832 }
9833
9834 /**
9835 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9836 */
9837 @Override
9838 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9839 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9840 "setCarrierSingleRegistrationEnabledOverride");
9841 enforceModifyPermission();
9842
9843 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9844 : Boolean.parseBoolean(enabledStr);
9845 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9846 subId, enabled);
9847 }
9848
9849 /**
9850 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9851 */
9852 @Override
9853 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9854 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9855 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9856 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009857
9858 /**
9859 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9860 * their mobile plan.
9861 */
9862 @Override
9863 public String getMobileProvisioningUrl() {
9864 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9865 final long identity = Binder.clearCallingIdentity();
9866 try {
9867 return getDefaultPhone().getMobileProvisioningUrl();
9868 } finally {
9869 Binder.restoreCallingIdentity(identity);
9870 }
9871 }
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009872
James.cf Linbcdf8b32021-01-14 16:44:13 +08009873 /**
calvinpane4a8a1d2021-01-25 13:51:18 +08009874 * Get the EAB contact from the EAB database.
9875 */
9876 @Override
9877 public String getContactFromEab(String contact) {
9878 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab");
9879 enforceModifyPermission();
9880 final long identity = Binder.clearCallingIdentity();
9881 try {
9882 return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact);
9883 } finally {
9884 Binder.restoreCallingIdentity(identity);
9885 }
9886 }
9887
9888 /**
James.cf Linbcdf8b32021-01-14 16:44:13 +08009889 * Remove the EAB contacts from the EAB database.
9890 */
9891 @Override
9892 public int removeContactFromEab(int subId, String contacts) {
9893 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab");
9894 enforceModifyPermission();
9895 final long identity = Binder.clearCallingIdentity();
9896 try {
9897 return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext());
9898 } finally {
9899 Binder.restoreCallingIdentity(identity);
9900 }
9901 }
9902
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009903 @Override
James.cf Lin4b784aa2021-01-31 03:25:15 +08009904 public boolean getDeviceUceEnabled() {
9905 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled");
9906 final long identity = Binder.clearCallingIdentity();
9907 try {
9908 return mApp.getDeviceUceEnabled();
9909 } finally {
9910 Binder.restoreCallingIdentity(identity);
9911 }
9912 }
9913
9914 @Override
9915 public void setDeviceUceEnabled(boolean isEnabled) {
9916 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled");
9917 final long identity = Binder.clearCallingIdentity();
9918 try {
9919 mApp.setDeviceUceEnabled(isEnabled);
9920 } finally {
9921 Binder.restoreCallingIdentity(identity);
9922 }
9923 }
9924
9925 @Override
Rambo Wanga5cc9b72021-01-07 10:51:54 -08009926 public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9927 String callingPackage) {
9928 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9929 mApp, subId, "setSignalStrengthUpdateRequest");
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 validateSignalStrengthUpdateRequest(request, callingUid);
9937
9938 final long identity = Binder.clearCallingIdentity();
9939 try {
9940 Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST,
9941 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9942
9943 if (result instanceof IllegalStateException) {
9944 throw (IllegalStateException) result;
9945 }
9946 } finally {
9947 Binder.restoreCallingIdentity(identity);
9948 }
9949 }
9950
9951 @Override
9952 public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request,
9953 String callingPackage) {
9954 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9955 mApp, subId, "clearSignalStrengthUpdateRequest");
9956
9957 final int callingUid = Binder.getCallingUid();
9958 // Verify that tha callingPackage belongs to the calling UID
9959 mApp.getSystemService(AppOpsManager.class)
9960 .checkPackage(callingUid, callingPackage);
9961
9962 final long identity = Binder.clearCallingIdentity();
9963 try {
9964 Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST,
9965 new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId);
9966
9967 if (result instanceof IllegalStateException) {
9968 throw (IllegalStateException) result;
9969 }
9970 } finally {
9971 Binder.restoreCallingIdentity(identity);
9972 }
9973 }
9974
9975 private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request,
9976 int callingUid) {
9977 if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) {
9978 // phone/system process do not have further restriction on request
9979 return;
9980 }
9981
9982 // Applications has restrictions on how to use the request:
9983 // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle
9984 if (request.isSystemThresholdReportingRequestedWhileIdle()) {
9985 // This is not system caller which has been checked above
9986 throw new IllegalArgumentException(
9987 "Only system can set isSystemThresholdReportingRequestedWhileIdle");
9988 }
9989
9990 for (SignalThresholdInfo info : request.getSignalThresholdInfos()) {
9991 // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled.
9992 if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED
9993 || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED
9994 || info.isEnabled()) {
9995 throw new IllegalArgumentException(
9996 "Only system can set hide fields in SignalThresholdInfo");
9997 }
9998
9999 // Thresholds length for each RAN need in range. This has been validated in
10000 // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method
10001 // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds
10002 final int[] thresholds = info.getThresholds();
10003 Objects.requireNonNull(thresholds);
10004 if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed()
10005 || thresholds.length
10006 > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) {
10007 throw new IllegalArgumentException(
10008 "thresholds length is out of range: " + thresholds.length);
10009 }
10010 }
10011 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -070010012}