blob: e24d2f8e70cd191d7d47808c1bd12723fb81ca9f [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070055import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070056import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070057import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070058import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080059import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070060import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090061import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080062import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080063import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070064import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070065import android.telephony.Annotation.ApnType;
Jack Nudelman24d51a52020-11-24 12:08:04 -080066import android.telephony.Annotation.ThermalMitigationResult;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Sooraj Sasindran1f812e02020-10-30 13:17:53 -070068import android.telephony.CarrierBandwidth;
Junda Liu12f7d802015-05-01 12:06:44 -070069import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080070import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070071import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080072import android.telephony.CellIdentityCdma;
73import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070074import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070075import android.telephony.CellInfoGsm;
76import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070077import android.telephony.ClientRequestStats;
Jack Nudelman24d51a52020-11-24 12:08:04 -080078import android.telephony.DataThrottlingRequest;
Hui Wang0866fcc2020-10-12 12:14:23 -070079import android.telephony.IBootstrapAuthenticationCallback;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070080import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070081import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080082import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070083import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080084import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070085import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080086import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080087import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070088import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080089import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070090import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080091import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080092import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080093import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080094import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070095import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070096import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080097import android.telephony.TelephonyScanManager;
Jack Nudelman24d51a52020-11-24 12:08:04 -080098import android.telephony.ThermalMitigationRequest;
Jordan Liu5aa07002018-12-18 15:44:48 -080099import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000100import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700101import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700102import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800103import android.telephony.data.ApnSetting;
104import android.telephony.emergency.EmergencyNumber;
Hui Wang0866fcc2020-10-12 12:14:23 -0700105import android.telephony.gba.GbaAuthRequest;
106import android.telephony.gba.UaSecurityProtocolIdentifier;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700107import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800108import android.telephony.ims.ProvisioningManager;
Hui Wang068ab862020-10-31 05:12:53 +0000109import android.telephony.ims.RcsClientConfiguration;
Brad Ebinger774ba362019-10-22 17:36:18 -0700110import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800112import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700113import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800114import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700115import android.telephony.ims.aidl.IImsRegistrationCallback;
Hui Wang068ab862020-10-31 05:12:53 +0000116import android.telephony.ims.aidl.IRcsConfigCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700117import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800118import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800119import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800120import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800121import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700122import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800123import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700124import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700125import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800126import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800127
Andrew Lee312e8172014-10-23 17:01:36 -0700128import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800129import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800130import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700132import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700133import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800134import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700135import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700136import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800137import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.DefaultPhoneNotifier;
Hui Wang0866fcc2020-10-12 12:14:23 -0700139import com.android.internal.telephony.GbaManager;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800140import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800141import com.android.internal.telephony.IBooleanConsumer;
Hall Liua1acea22020-09-18 19:04:59 -0700142import com.android.internal.telephony.ICallForwardingInfoCallback;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700143import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800144import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800146import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700147import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700148import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700149import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700150import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700151import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800152import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700153import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700154import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700155import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700156import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700157import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700158import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700159import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700160import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800161import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800162import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800163import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700164import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800165import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700166import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800167import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700168import com.android.internal.telephony.imsphone.ImsPhone;
169import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800170import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900171import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700172import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800173import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700174import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800175import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700176import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800177import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700178import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800179import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000180import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800181import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700182import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Hall Liua1acea22020-09-18 19:04:59 -0700183import com.android.internal.util.FunctionalUtils;
Jake Hambye994d462014-02-03 13:10:13 -0800184import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700185import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700186import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800187import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700188import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700189import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800190import com.android.services.telephony.TelecomAccountRegistry;
191import com.android.services.telephony.TelephonyConnectionService;
Peter Wang050bb052020-01-13 23:33:09 -0800192import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800193
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700194import java.io.FileDescriptor;
195import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800197import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800198import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800199import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800200import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100201import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700203import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800204import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800205import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800206import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700207
208/**
209 * Implementation of the ITelephony interface.
210 */
Santos Cordon117fee72014-05-16 17:56:12 -0700211public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700212 private static final String LOG_TAG = "PhoneInterfaceManager";
213 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
214 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800215 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700216
217 // Message codes used with mMainThreadHandler
218 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700219 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
220 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700221 private static final int CMD_OPEN_CHANNEL = 9;
222 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
223 private static final int CMD_CLOSE_CHANNEL = 11;
224 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800225 private static final int CMD_NV_READ_ITEM = 13;
226 private static final int EVENT_NV_READ_ITEM_DONE = 14;
227 private static final int CMD_NV_WRITE_ITEM = 15;
228 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
229 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
230 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700231 private static final int CMD_RESET_MODEM_CONFIG = 19;
232 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800233 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
234 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
235 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
236 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800237 private static final int CMD_SEND_ENVELOPE = 25;
238 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000239 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
240 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700241 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
242 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
243 private static final int CMD_EXCHANGE_SIM_IO = 31;
244 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800245 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
246 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700247 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
248 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700249 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
250 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700251 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
252 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
253 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
254 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700255 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
256 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
257 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
258 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700259 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800260 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
261 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000262 private static final int CMD_SWITCH_SLOTS = 50;
263 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700264 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
265 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
266 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
267 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
268 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
269 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
270 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
271 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700272 private static final int CMD_GET_ALL_CELL_INFO = 60;
273 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
274 private static final int CMD_GET_CELL_LOCATION = 62;
275 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700276 private static final int CMD_MODEM_REBOOT = 64;
277 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700278 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
279 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800280 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
281 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700282 private static final int CMD_GET_MODEM_STATUS = 70;
283 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700284 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
285 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700286 private static final int CMD_ERASE_MODEM_CONFIG = 74;
287 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800288 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
289 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
290 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
291 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800292 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
293 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800294 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
sqian80370722020-01-29 15:02:51 -0800295 private static final int CMD_GET_CALL_FORWARDING = 83;
296 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
297 private static final int CMD_SET_CALL_FORWARDING = 85;
298 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
299 private static final int CMD_GET_CALL_WAITING = 87;
300 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
301 private static final int CMD_SET_CALL_WAITING = 89;
302 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700303 private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91;
304 private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92;
305 private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93;
306 private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94;
Sarah Chin49f22af2020-10-28 13:46:24 -0700307 private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95;
308 private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96;
Sarah Chincc055732020-11-18 13:39:35 -0800309 private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97;
310 private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98;
Jack Nudelman24d51a52020-11-24 12:08:04 -0800311 private static final int CMD_SET_DATA_THROTTLING = 99;
312 private static final int EVENT_SET_DATA_THROTTLING_DONE = 100;
Jordan Liud5366d92020-11-24 14:50:34 -0800313 private static final int CMD_SET_SIM_POWER = 101;
314 private static final int EVENT_SET_SIM_POWER_DONE = 102;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700315
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800316 // Parameters of select command.
317 private static final int SELECT_COMMAND = 0xA4;
318 private static final int SELECT_P1 = 0x04;
319 private static final int SELECT_P2 = 0;
320 private static final int SELECT_P3 = 0x10;
321
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700322 /** The singleton instance. */
323 private static PhoneInterfaceManager sInstance;
324
Wink Saville3ab207e2014-11-20 13:07:20 -0800325 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800326 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800327 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700328 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800329 private AppOpsManager mAppOps;
330 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800331 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800332 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700333 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700334
Peter Wangdafb9ac2020-01-15 14:13:38 -0800335 /** User Activity */
336 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800337 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
338
Jeff Davidson0103e8c2020-03-28 12:24:40 -0700339 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
340
Derek Tan97ebb422014-09-05 16:55:38 -0700341 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
342 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800343 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800344 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700345
Michelecea4cf22018-12-21 15:00:11 -0800346 // String to store multi SIM allowed
347 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
348
Derek Tan740e1672017-06-27 14:56:27 -0700349 // The AID of ISD-R.
350 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
351
yinxub1bed742017-04-17 11:45:04 -0700352 private NetworkScanRequestTracker mNetworkScanRequestTracker;
353
David Kelly5e06a7f2018-03-12 14:10:59 +0000354 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
355 private static final int MANUFACTURER_CODE_LENGTH = 8;
356
Jack Nudelman24d51a52020-11-24 12:08:04 -0800357 private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1;
358
Derek Tan89e89d42014-07-08 17:00:10 -0700359 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700360 * Experiment flag to enable erase modem config on reset network, default value is false
361 */
362 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
363 "reset_network_erase_modem_config_enabled";
364
365 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700366 * A request object to use for transmitting data to an ICC.
367 */
368 private static final class IccAPDUArgument {
369 public int channel, cla, command, p1, p2, p3;
370 public String data;
371
372 public IccAPDUArgument(int channel, int cla, int command,
373 int p1, int p2, int p3, String data) {
374 this.channel = channel;
375 this.cla = cla;
376 this.command = command;
377 this.p1 = p1;
378 this.p2 = p2;
379 this.p3 = p3;
380 this.data = data;
381 }
382 }
383
384 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700385 * A request object to use for transmitting data to an ICC.
386 */
387 private static final class ManualNetworkSelectionArgument {
388 public OperatorInfo operatorInfo;
389 public boolean persistSelection;
390
391 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
392 this.operatorInfo = operatorInfo;
393 this.persistSelection = persistSelection;
394 }
395 }
396
397 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700398 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
399 * request after sending. The main thread will notify the request when it is complete.
400 */
401 private static final class MainThreadRequest {
402 /** The argument to use for the request */
403 public Object argument;
404 /** The result of the request that is run on the main thread */
405 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800406 // The subscriber id that this request applies to. Defaults to
407 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
408 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409
Nathan Harold92bed182018-10-12 18:16:49 -0700410 // In cases where subId is unavailable, the caller needs to specify the phone.
411 public Phone phone;
412
vagdeviaf9a5b92018-08-15 16:01:53 -0700413 public WorkSource workSource;
414
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700415 public MainThreadRequest(Object argument) {
416 this.argument = argument;
417 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800418
Nathan Harold92bed182018-10-12 18:16:49 -0700419 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
420 this.argument = argument;
421 if (phone != null) {
422 this.phone = phone;
423 }
424 this.workSource = workSource;
425 }
426
vagdeviaf9a5b92018-08-15 16:01:53 -0700427 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800428 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800429 if (subId != null) {
430 this.subId = subId;
431 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700432 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800433 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700434 }
435
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800436 private static final class IncomingThirdPartyCallArgs {
437 public final ComponentName component;
438 public final String callId;
439 public final String callerDisplayName;
440
441 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
442 String callerDisplayName) {
443 this.component = component;
444 this.callId = callId;
445 this.callerDisplayName = callerDisplayName;
446 }
447 }
448
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700449 /**
450 * A handler that processes messages on the main thread in the phone process. Since many
451 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
452 * inbound binder threads to the main thread in the phone process. The Binder thread
453 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
454 * on, which will be notified when the operation completes and will contain the result of the
455 * request.
456 *
457 * <p>If a MainThreadRequest object is provided in the msg.obj field,
458 * note that request.result must be set to something non-null for the calling thread to
459 * unblock.
460 */
461 private final class MainThreadHandler extends Handler {
462 @Override
463 public void handleMessage(Message msg) {
464 MainThreadRequest request;
465 Message onCompleted;
466 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800467 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700468 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800469 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700470
471 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700472 case CMD_HANDLE_USSD_REQUEST: {
473 request = (MainThreadRequest) msg.obj;
474 final Phone phone = getPhoneFromRequest(request);
475 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
476 String ussdRequest = ussdObject.first;
477 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700478
Pengquan Menga1bb6272018-09-06 09:59:22 -0700479 if (!isUssdApiAllowed(request.subId)) {
480 // Carrier does not support use of this API, return failure.
481 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
482 UssdResponse response = new UssdResponse(ussdRequest, null);
483 Bundle returnData = new Bundle();
484 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
485 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700486
Pengquan Menga1bb6272018-09-06 09:59:22 -0700487 request.result = true;
488 notifyRequester(request);
489 return;
490 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700491
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 try {
493 request.result = phone != null
494 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
495 } catch (CallStateException cse) {
496 request.result = false;
497 }
498 // Wake up the requesting thread
499 notifyRequester(request);
500 break;
pkanwar32d516d2016-10-14 19:37:38 -0700501 }
502
Yorke Lee716f67e2015-06-17 15:39:16 -0700503 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700504 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700505 final Phone phone = getPhoneFromRequest(request);
506 request.result = phone != null ?
507 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
508 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700509 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700510 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700511 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700512 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700513
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700514 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700516 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800517 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700518 if (uiccCard == null) {
519 loge("iccTransmitApduLogicalChannel: No UICC");
520 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700522 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
524 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700525 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 iccArgument.channel, iccArgument.cla, iccArgument.command,
527 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700528 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700529 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700530 break;
531
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700533 ar = (AsyncResult) msg.obj;
534 request = (MainThreadRequest) ar.userObj;
535 if (ar.exception == null && ar.result != null) {
536 request.result = ar.result;
537 } else {
538 request.result = new IccIoResult(0x6F, 0, (byte[])null);
539 if (ar.result == null) {
540 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800541 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700542 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800543 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700544 } else {
545 loge("iccTransmitApduLogicalChannel: Unknown exception");
546 }
547 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700548 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700549 break;
550
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700551 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
552 request = (MainThreadRequest) msg.obj;
553 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800554 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700555 if (uiccCard == null) {
556 loge("iccTransmitApduBasicChannel: No UICC");
557 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700558 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 } else {
560 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
561 request);
562 uiccCard.iccTransmitApduBasicChannel(
563 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
564 iccArgument.p3, iccArgument.data, onCompleted);
565 }
566 break;
567
568 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
569 ar = (AsyncResult) msg.obj;
570 request = (MainThreadRequest) ar.userObj;
571 if (ar.exception == null && ar.result != null) {
572 request.result = ar.result;
573 } else {
574 request.result = new IccIoResult(0x6F, 0, (byte[])null);
575 if (ar.result == null) {
576 loge("iccTransmitApduBasicChannel: Empty response");
577 } else if (ar.exception instanceof CommandException) {
578 loge("iccTransmitApduBasicChannel: CommandException: " +
579 ar.exception);
580 } else {
581 loge("iccTransmitApduBasicChannel: Unknown exception");
582 }
583 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700584 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700585 break;
586
587 case CMD_EXCHANGE_SIM_IO:
588 request = (MainThreadRequest) msg.obj;
589 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700591 if (uiccCard == null) {
592 loge("iccExchangeSimIO: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
597 request);
598 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
599 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
600 iccArgument.data, onCompleted);
601 }
602 break;
603
604 case EVENT_EXCHANGE_SIM_IO_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
609 } else {
610 request.result = new IccIoResult(0x6f, 0, (byte[])null);
611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700613 break;
614
Derek Tan4d5e5c12014-02-04 11:54:58 -0800615 case CMD_SEND_ENVELOPE:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("sendEnvelopeWithStatus: No UICC");
620 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700621 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 } else {
623 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
624 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
625 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800626 break;
627
628 case EVENT_SEND_ENVELOPE_DONE:
629 ar = (AsyncResult) msg.obj;
630 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700631 if (ar.exception == null && ar.result != null) {
632 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800633 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700634 request.result = new IccIoResult(0x6F, 0, (byte[])null);
635 if (ar.result == null) {
636 loge("sendEnvelopeWithStatus: Empty response");
637 } else if (ar.exception instanceof CommandException) {
638 loge("sendEnvelopeWithStatus: CommandException: " +
639 ar.exception);
640 } else {
641 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
642 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800643 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700644 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800645 break;
646
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 case CMD_OPEN_CHANNEL:
648 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800649 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800650 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700651 if (uiccCard == null) {
652 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800653 request.result = new IccOpenLogicalChannelResponse(-1,
654 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700655 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700656 } else {
657 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800658 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
659 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700660 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700661 break;
662
663 case EVENT_OPEN_CHANNEL_DONE:
664 ar = (AsyncResult) msg.obj;
665 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 int[] result = (int[]) ar.result;
669 int channelId = result[0];
670 byte[] selectResponse = null;
671 if (result.length > 1) {
672 selectResponse = new byte[result.length - 1];
673 for (int i = 1; i < result.length; ++i) {
674 selectResponse[i - 1] = (byte) result[i];
675 }
676 }
677 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700678 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700679 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700680 if (ar.result == null) {
681 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700683 if (ar.exception != null) {
684 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
685 }
686
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700687 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700688 if (ar.exception instanceof CommandException) {
689 CommandException.Error error =
690 ((CommandException) (ar.exception)).getCommandError();
691 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700692 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700693 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700694 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700695 }
696 }
697 openChannelResp = new IccOpenLogicalChannelResponse(
698 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700699 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700700 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700701 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 break;
703
704 case CMD_CLOSE_CHANNEL:
705 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800706 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700707 if (uiccCard == null) {
708 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900709 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700710 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700711 } else {
712 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
713 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
714 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 break;
716
717 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800718 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
719 break;
720
721 case CMD_NV_READ_ITEM:
722 request = (MainThreadRequest) msg.obj;
723 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700729 ar = (AsyncResult) msg.obj;
730 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800731 if (ar.exception == null && ar.result != null) {
732 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700733 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800734 request.result = "";
735 if (ar.result == null) {
736 loge("nvReadItem: Empty response");
737 } else if (ar.exception instanceof CommandException) {
738 loge("nvReadItem: CommandException: " +
739 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700740 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800741 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700742 }
743 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700744 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700745 break;
746
Jake Hambye994d462014-02-03 13:10:13 -0800747 case CMD_NV_WRITE_ITEM:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
750 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800751 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700752 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
755 case EVENT_NV_WRITE_ITEM_DONE:
756 handleNullReturnEvent(msg, "nvWriteItem");
757 break;
758
759 case CMD_NV_WRITE_CDMA_PRL:
760 request = (MainThreadRequest) msg.obj;
761 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800762 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800763 break;
764
765 case EVENT_NV_WRITE_CDMA_PRL_DONE:
766 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
767 break;
768
chen xu6dac5ab2018-10-26 17:39:23 -0700769 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800770 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700771 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800772 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800773 break;
774
chen xu6dac5ab2018-10-26 17:39:23 -0700775 case EVENT_RESET_MODEM_CONFIG_DONE:
776 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800777 break;
778
Sooraj Sasindranb4a99602020-08-11 10:40:43 -0700779 case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: {
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE,
782 request);
783 Phone phone = getPhoneFromRequest(request);
784 if (phone != null) {
785 phone.isNrDualConnectivityEnabled(onCompleted, request.workSource);
786 } else {
787 loge("isNRDualConnectivityEnabled: No phone object");
788 request.result = false;
789 notifyRequester(request);
790 }
791 break;
792 }
793
794 case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE:
795 ar = (AsyncResult) msg.obj;
796 request = (MainThreadRequest) ar.userObj;
797 if (ar.exception == null && ar.result != null) {
798 request.result = ar.result;
799 } else {
800 // request.result must be set to something non-null
801 // for the calling thread to unblock
802 if (request.result != null) {
803 request.result = ar.result;
804 } else {
805 request.result = false;
806 }
807 if (ar.result == null) {
808 loge("isNRDualConnectivityEnabled: Empty response");
809 } else if (ar.exception instanceof CommandException) {
810 loge("isNRDualConnectivityEnabled: CommandException: "
811 + ar.exception);
812 } else {
813 loge("isNRDualConnectivityEnabled: Unknown exception");
814 }
815 }
816 notifyRequester(request);
817 break;
818
819 case CMD_ENABLE_NR_DUAL_CONNECTIVITY: {
820 request = (MainThreadRequest) msg.obj;
821 onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request);
822 Phone phone = getPhoneFromRequest(request);
823 if (phone != null) {
824 phone.setNrDualConnectivityState((int) request.argument, onCompleted,
825 request.workSource);
826 } else {
827 loge("enableNrDualConnectivity: No phone object");
828 request.result =
829 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
830 notifyRequester(request);
831 }
832 break;
833 }
834
835 case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: {
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 if (ar.exception == null) {
839 request.result =
840 TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS;
841 } else {
842 request.result =
843 TelephonyManager
844 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR;
845 if (ar.exception instanceof CommandException) {
846 CommandException.Error error =
847 ((CommandException) (ar.exception)).getCommandError();
848 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
849 request.result =
850 TelephonyManager
851 .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE;
852 }
853 loge("enableNrDualConnectivity" + ": CommandException: "
854 + ar.exception);
855 } else {
856 loge("enableNrDualConnectivity" + ": Unknown exception");
857 }
858 }
859 notifyRequester(request);
860 break;
861 }
862
Jake Hamby7c27be32014-03-03 13:25:59 -0800863 case CMD_GET_PREFERRED_NETWORK_TYPE:
864 request = (MainThreadRequest) msg.obj;
865 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700866 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800867 break;
868
869 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
870 ar = (AsyncResult) msg.obj;
871 request = (MainThreadRequest) ar.userObj;
872 if (ar.exception == null && ar.result != null) {
873 request.result = ar.result; // Integer
874 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530875 // request.result must be set to something non-null
876 // for the calling thread to unblock
877 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800878 if (ar.result == null) {
879 loge("getPreferredNetworkType: Empty response");
880 } else if (ar.exception instanceof CommandException) {
881 loge("getPreferredNetworkType: CommandException: " +
882 ar.exception);
883 } else {
884 loge("getPreferredNetworkType: Unknown exception");
885 }
886 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700887 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800888 break;
889
890 case CMD_SET_PREFERRED_NETWORK_TYPE:
891 request = (MainThreadRequest) msg.obj;
892 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
893 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700894 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800895 break;
896
897 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
898 handleNullReturnEvent(msg, "setPreferredNetworkType");
899 break;
900
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000901 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
902 request = (MainThreadRequest)msg.obj;
903 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800904 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000905 break;
906
907 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
908 ar = (AsyncResult)msg.obj;
909 request = (MainThreadRequest)ar.userObj;
910 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700911 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000912 break;
913
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800914 case CMD_SET_VOICEMAIL_NUMBER:
915 request = (MainThreadRequest) msg.obj;
916 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
917 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800918 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
919 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800920 break;
921
922 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
923 handleNullReturnEvent(msg, "setVoicemailNumber");
924 break;
925
Stuart Scott54788802015-03-30 13:18:01 -0700926 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
927 request = (MainThreadRequest) msg.obj;
928 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
929 request);
930 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
931 break;
932
933 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
934 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
935 break;
936
Shishir Agrawal302c8692015-06-19 13:49:39 -0700937 case CMD_PERFORM_NETWORK_SCAN:
938 request = (MainThreadRequest) msg.obj;
939 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
940 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
941 break;
942
Hall Liua1acea22020-09-18 19:04:59 -0700943 case CMD_GET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -0800944 request = (MainThreadRequest) msg.obj;
945 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -0700946 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args =
947 (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
948 request.argument;
949 int callForwardingReason = args.first;
950 request.phone.getCallForwardingOption(callForwardingReason, onCompleted);
sqian80370722020-01-29 15:02:51 -0800951 break;
Hall Liua1acea22020-09-18 19:04:59 -0700952 }
953 case EVENT_GET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -0800954 ar = (AsyncResult) msg.obj;
955 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -0700956 TelephonyManager.CallForwardingInfoCallback callback =
957 ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>)
958 request.argument).second;
sqian80370722020-01-29 15:02:51 -0800959 if (ar.exception == null && ar.result != null) {
Hall Liua1acea22020-09-18 19:04:59 -0700960 CallForwardingInfo callForwardingInfo = null;
sqian80370722020-01-29 15:02:51 -0800961 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
962 for (CallForwardInfo callForwardInfo : callForwardInfos) {
963 // Service Class is a bit mask per 3gpp 27.007. Search for
964 // any service for voice call.
965 if ((callForwardInfo.serviceClass
966 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
Hall Liua1acea22020-09-18 19:04:59 -0700967 callForwardingInfo = new CallForwardingInfo(true,
968 callForwardInfo.reason,
969 callForwardInfo.number,
970 callForwardInfo.timeSeconds);
sqian80370722020-01-29 15:02:51 -0800971 break;
972 }
973 }
974 // Didn't find a call forward info for voice call.
975 if (callForwardingInfo == null) {
Hall Liua1acea22020-09-18 19:04:59 -0700976 callForwardingInfo = new CallForwardingInfo(false /* enabled */,
977 0 /* reason */, null /* number */, 0 /* timeout */);
sqian80370722020-01-29 15:02:51 -0800978 }
Hall Liua1acea22020-09-18 19:04:59 -0700979 callback.onCallForwardingInfoAvailable(callForwardingInfo);
sqian80370722020-01-29 15:02:51 -0800980 } else {
981 if (ar.result == null) {
982 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
986 }
Hall Liuae527aa2020-09-29 17:10:18 -0700987 int errorCode = TelephonyManager
988 .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN;
sqian80370722020-01-29 15:02:51 -0800989 if (ar.exception instanceof CommandException) {
990 CommandException.Error error =
991 ((CommandException) (ar.exception)).getCommandError();
992 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -0700993 errorCode = TelephonyManager
994 .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE;
sqian80370722020-01-29 15:02:51 -0800995 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -0700996 errorCode = TelephonyManager
997 .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED;
sqian80370722020-01-29 15:02:51 -0800998 }
999 }
Hall Liua1acea22020-09-18 19:04:59 -07001000 callback.onError(errorCode);
sqian80370722020-01-29 15:02:51 -08001001 }
sqian80370722020-01-29 15:02:51 -08001002 break;
Hall Liua1acea22020-09-18 19:04:59 -07001003 }
sqian80370722020-01-29 15:02:51 -08001004
Hall Liua1acea22020-09-18 19:04:59 -07001005 case CMD_SET_CALL_FORWARDING: {
sqian80370722020-01-29 15:02:51 -08001006 request = (MainThreadRequest) msg.obj;
1007 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001008 request = (MainThreadRequest) msg.obj;
sqian80370722020-01-29 15:02:51 -08001009 CallForwardingInfo callForwardingInfoToSet =
Hall Liua1acea22020-09-18 19:04:59 -07001010 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1011 request.argument).first;
1012 request.phone.setCallForwardingOption(
1013 callForwardingInfoToSet.isEnabled()
1014 ? CommandsInterface.CF_ACTION_ENABLE
1015 : CommandsInterface.CF_ACTION_DISABLE,
sqian80370722020-01-29 15:02:51 -08001016 callForwardingInfoToSet.getReason(),
1017 callForwardingInfoToSet.getNumber(),
1018 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
1019 break;
Hall Liua1acea22020-09-18 19:04:59 -07001020 }
sqian80370722020-01-29 15:02:51 -08001021
Hall Liua1acea22020-09-18 19:04:59 -07001022 case EVENT_SET_CALL_FORWARDING_DONE: {
sqian80370722020-01-29 15:02:51 -08001023 ar = (AsyncResult) msg.obj;
1024 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001025 Consumer<Integer> callback =
1026 ((Pair<CallForwardingInfo, Consumer<Integer>>)
1027 request.argument).second;
1028 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001029 loge("setCallForwarding exception: " + ar.exception);
Hall Liuae527aa2020-09-29 17:10:18 -07001030 int errorCode = TelephonyManager.CallForwardingInfoCallback
1031 .RESULT_ERROR_UNKNOWN;
Hall Liua1acea22020-09-18 19:04:59 -07001032 if (ar.exception instanceof CommandException) {
1033 CommandException.Error error =
1034 ((CommandException) (ar.exception)).getCommandError();
1035 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
Hall Liuae527aa2020-09-29 17:10:18 -07001036 errorCode = TelephonyManager.CallForwardingInfoCallback
1037 .RESULT_ERROR_FDN_CHECK_FAILURE;
Hall Liua1acea22020-09-18 19:04:59 -07001038 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
Hall Liuae527aa2020-09-29 17:10:18 -07001039 errorCode = TelephonyManager.CallForwardingInfoCallback
1040 .RESULT_ERROR_NOT_SUPPORTED;
Hall Liua1acea22020-09-18 19:04:59 -07001041 }
1042 }
1043 callback.accept(errorCode);
1044 } else {
Hall Liuae527aa2020-09-29 17:10:18 -07001045 callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS);
sqian80370722020-01-29 15:02:51 -08001046 }
sqian80370722020-01-29 15:02:51 -08001047 break;
Hall Liua1acea22020-09-18 19:04:59 -07001048 }
sqian80370722020-01-29 15:02:51 -08001049
Hall Liua1acea22020-09-18 19:04:59 -07001050 case CMD_GET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001051 request = (MainThreadRequest) msg.obj;
1052 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
1053 getPhoneFromRequest(request).getCallWaiting(onCompleted);
1054 break;
Hall Liua1acea22020-09-18 19:04:59 -07001055 }
sqian80370722020-01-29 15:02:51 -08001056
Hall Liua1acea22020-09-18 19:04:59 -07001057 case EVENT_GET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001058 ar = (AsyncResult) msg.obj;
1059 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001060 Consumer<Integer> callback = (Consumer<Integer>) request.argument;
sqian80370722020-01-29 15:02:51 -08001061 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
1062 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001063 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -08001064 // Service Class is a bit mask per 3gpp 27.007.
1065 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001066 if (callForwardResults.length > 1
1067 && ((callForwardResults[1]
Hall Liua1acea22020-09-18 19:04:59 -07001068 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -08001069 callForwardingStatus = callForwardResults[0] == 0
Hall Liua1acea22020-09-18 19:04:59 -07001070 ? TelephonyManager.CALL_WAITING_STATUS_DISABLED
1071 : TelephonyManager.CALL_WAITING_STATUS_ENABLED;
sqian80370722020-01-29 15:02:51 -08001072 } else {
Hall Liua1acea22020-09-18 19:04:59 -07001073 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED;
sqian80370722020-01-29 15:02:51 -08001074 }
1075 } else {
1076 if (ar.result == null) {
1077 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
1078 }
1079 if (ar.exception != null) {
1080 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
1081 }
1082 if (ar.exception instanceof CommandException) {
1083 CommandException.Error error =
1084 ((CommandException) (ar.exception)).getCommandError();
1085 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1086 callForwardingStatus =
1087 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
1088 }
1089 }
1090 }
Hall Liua1acea22020-09-18 19:04:59 -07001091 callback.accept(callForwardingStatus);
sqian80370722020-01-29 15:02:51 -08001092 break;
Hall Liua1acea22020-09-18 19:04:59 -07001093 }
sqian80370722020-01-29 15:02:51 -08001094
Hall Liua1acea22020-09-18 19:04:59 -07001095 case CMD_SET_CALL_WAITING: {
sqian80370722020-01-29 15:02:51 -08001096 request = (MainThreadRequest) msg.obj;
1097 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
Hall Liua1acea22020-09-18 19:04:59 -07001098 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1099 getPhoneFromRequest(request).setCallWaiting(enable, onCompleted);
sqian80370722020-01-29 15:02:51 -08001100 break;
Hall Liua1acea22020-09-18 19:04:59 -07001101 }
sqian80370722020-01-29 15:02:51 -08001102
Hall Liua1acea22020-09-18 19:04:59 -07001103 case EVENT_SET_CALL_WAITING_DONE: {
sqian80370722020-01-29 15:02:51 -08001104 ar = (AsyncResult) msg.obj;
1105 request = (MainThreadRequest) ar.userObj;
Hall Liua1acea22020-09-18 19:04:59 -07001106 boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first;
1107 Consumer<Integer> callback =
1108 ((Pair<Boolean, Consumer<Integer>>) request.argument).second;
1109 if (ar.exception != null) {
sqian80370722020-01-29 15:02:51 -08001110 loge("setCallWaiting exception: " + ar.exception);
Hall Liua1acea22020-09-18 19:04:59 -07001111 if (ar.exception instanceof CommandException) {
1112 CommandException.Error error =
1113 ((CommandException) (ar.exception)).getCommandError();
1114 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1115 callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED);
1116 } else {
1117 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1118 }
1119 } else {
1120 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
1121 }
1122 } else {
1123 callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED
1124 : TelephonyManager.CALL_WAITING_STATUS_DISABLED);
sqian80370722020-01-29 15:02:51 -08001125 }
sqian80370722020-01-29 15:02:51 -08001126 break;
Hall Liua1acea22020-09-18 19:04:59 -07001127 }
sqian80370722020-01-29 15:02:51 -08001128
Shishir Agrawal302c8692015-06-19 13:49:39 -07001129 case EVENT_PERFORM_NETWORK_SCAN_DONE:
1130 ar = (AsyncResult) msg.obj;
1131 request = (MainThreadRequest) ar.userObj;
1132 CellNetworkScanResult cellScanResult;
1133 if (ar.exception == null && ar.result != null) {
1134 cellScanResult = new CellNetworkScanResult(
1135 CellNetworkScanResult.STATUS_SUCCESS,
1136 (List<OperatorInfo>) ar.result);
1137 } else {
1138 if (ar.result == null) {
1139 loge("getCellNetworkScanResults: Empty response");
1140 }
1141 if (ar.exception != null) {
1142 loge("getCellNetworkScanResults: Exception: " + ar.exception);
1143 }
1144 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
1145 if (ar.exception instanceof CommandException) {
1146 CommandException.Error error =
1147 ((CommandException) (ar.exception)).getCommandError();
1148 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1149 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
1150 } else if (error == CommandException.Error.GENERIC_FAILURE) {
1151 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
1152 }
1153 }
1154 cellScanResult = new CellNetworkScanResult(errorCode, null);
1155 }
1156 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001157 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001158 break;
1159
1160 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1161 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001162 ManualNetworkSelectionArgument selArg =
1163 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001164 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1165 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001166 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1167 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001168 break;
1169
1170 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001171 ar = (AsyncResult) msg.obj;
1172 request = (MainThreadRequest) ar.userObj;
1173 if (ar.exception == null) {
1174 request.result = true;
1175 } else {
1176 request.result = false;
1177 loge("setNetworkSelectionModeManual " + ar.exception);
1178 }
1179 notifyRequester(request);
1180 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001181 break;
1182
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001183 case CMD_GET_MODEM_ACTIVITY_INFO:
1184 request = (MainThreadRequest) msg.obj;
1185 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001186 if (defaultPhone != null) {
1187 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001188 } else {
1189 ResultReceiver result = (ResultReceiver) request.argument;
1190 Bundle bundle = new Bundle();
1191 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1192 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1193 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001194 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001195 break;
1196
1197 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001200 ResultReceiver result = (ResultReceiver) request.argument;
1201
1202 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001203 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001204 // Update the last modem activity info and the result of the request.
1205 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1206 if (isModemActivityInfoValid(info)) {
1207 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1208 int[] txTimeMs = info.getTransmitTimeMillis();
1209 int[] lastModemTxTimeMs = mLastModemActivityInfo
1210 .getTransmitTimeMillis();
1211 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1212 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1213 }
1214 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1215 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1216 + mLastModemActivityInfo.getSleepTimeMillis());
1217 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1218 + mLastModemActivityInfo.getIdleTimeMillis());
1219 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1220 mLastModemActivityInfo.setReceiveTimeMillis(
1221 info.getReceiveTimeMillis()
1222 + mLastModemActivityInfo.getReceiveTimeMillis());
1223 }
1224 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1225 mLastModemActivityInfo.getSleepTimeMillis(),
1226 mLastModemActivityInfo.getIdleTimeMillis(),
1227 mLastModemActivityInfo.getTransmitTimeMillis(),
1228 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001229 } else {
1230 if (ar.result == null) {
1231 loge("queryModemActivityInfo: Empty response");
1232 } else if (ar.exception instanceof CommandException) {
1233 loge("queryModemActivityInfo: CommandException: " +
1234 ar.exception);
1235 } else {
1236 loge("queryModemActivityInfo: Unknown exception");
1237 }
1238 }
sqian1a1be542020-03-05 11:37:28 -08001239 Bundle bundle = new Bundle();
1240 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1241 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001242 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001243 break;
1244
Meng Wang1a7c35a2016-05-05 20:56:15 -07001245 case CMD_SET_ALLOWED_CARRIERS:
1246 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001247 CarrierRestrictionRules argument =
1248 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001249 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001250 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001251 break;
1252
1253 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1254 ar = (AsyncResult) msg.obj;
1255 request = (MainThreadRequest) ar.userObj;
1256 if (ar.exception == null && ar.result != null) {
1257 request.result = ar.result;
1258 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001259 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1260 if (ar.exception instanceof CommandException) {
1261 loge("setAllowedCarriers: CommandException: " + ar.exception);
1262 CommandException.Error error =
1263 ((CommandException) (ar.exception)).getCommandError();
1264 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1265 request.result =
1266 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1267 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001268 } else {
1269 loge("setAllowedCarriers: Unknown exception");
1270 }
1271 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001272 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001273 break;
1274
1275 case CMD_GET_ALLOWED_CARRIERS:
1276 request = (MainThreadRequest) msg.obj;
1277 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001278 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001279 break;
1280
1281 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 if (ar.exception == null && ar.result != null) {
1285 request.result = ar.result;
1286 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001287 request.result = new IllegalStateException(
1288 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001289 if (ar.result == null) {
1290 loge("getAllowedCarriers: Empty response");
1291 } else if (ar.exception instanceof CommandException) {
1292 loge("getAllowedCarriers: CommandException: " +
1293 ar.exception);
1294 } else {
1295 loge("getAllowedCarriers: Unknown exception");
1296 }
1297 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001298 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001299 break;
1300
Nathan Haroldb3014052017-01-25 15:57:32 -08001301 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1302 ar = (AsyncResult) msg.obj;
1303 request = (MainThreadRequest) ar.userObj;
1304 if (ar.exception == null && ar.result != null) {
1305 request.result = ar.result;
1306 } else {
1307 request.result = new IllegalArgumentException(
1308 "Failed to retrieve Forbidden Plmns");
1309 if (ar.result == null) {
1310 loge("getForbiddenPlmns: Empty response");
1311 } else {
1312 loge("getForbiddenPlmns: Unknown exception");
1313 }
1314 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001315 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001316 break;
1317
1318 case CMD_GET_FORBIDDEN_PLMNS:
1319 request = (MainThreadRequest) msg.obj;
1320 uiccCard = getUiccCardFromRequest(request);
1321 if (uiccCard == null) {
1322 loge("getForbiddenPlmns() UiccCard is null");
1323 request.result = new IllegalArgumentException(
1324 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001325 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001326 break;
1327 }
1328 Integer appType = (Integer) request.argument;
1329 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1330 if (uiccApp == null) {
1331 loge("getForbiddenPlmns() no app with specified type -- "
1332 + appType);
1333 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001334 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001335 break;
1336 } else {
1337 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1338 + " specified type -- " + appType);
1339 }
1340 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1341 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1342 onCompleted);
1343 break;
1344
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001345 case CMD_SWITCH_SLOTS:
1346 request = (MainThreadRequest) msg.obj;
1347 int[] physicalSlots = (int[]) request.argument;
1348 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1349 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1350 break;
1351
1352 case EVENT_SWITCH_SLOTS_DONE:
1353 ar = (AsyncResult) msg.obj;
1354 request = (MainThreadRequest) ar.userObj;
1355 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001356 notifyRequester(request);
1357 break;
1358 case CMD_GET_NETWORK_SELECTION_MODE:
1359 request = (MainThreadRequest) msg.obj;
1360 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1361 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1362 break;
1363
1364 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 if (ar.exception != null) {
1368 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1369 } else {
1370 int mode = ((int[]) ar.result)[0];
1371 if (mode == 0) {
1372 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1373 } else {
1374 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1375 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001376 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001377 notifyRequester(request);
1378 break;
1379 case CMD_GET_CDMA_ROAMING_MODE:
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1382 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1383 break;
1384 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1385 ar = (AsyncResult) msg.obj;
1386 request = (MainThreadRequest) ar.userObj;
1387 if (ar.exception != null) {
1388 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1389 } else {
1390 request.result = ((int[]) ar.result)[0];
1391 }
1392 notifyRequester(request);
1393 break;
1394 case CMD_SET_CDMA_ROAMING_MODE:
1395 request = (MainThreadRequest) msg.obj;
1396 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1397 int mode = (int) request.argument;
1398 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1399 break;
1400 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1401 ar = (AsyncResult) msg.obj;
1402 request = (MainThreadRequest) ar.userObj;
1403 request.result = ar.exception == null;
1404 notifyRequester(request);
1405 break;
Sarah Chin49f22af2020-10-28 13:46:24 -07001406 case CMD_GET_CDMA_SUBSCRIPTION_MODE:
1407 request = (MainThreadRequest) msg.obj;
1408 onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1409 getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted);
1410 break;
1411 case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE:
1412 ar = (AsyncResult) msg.obj;
1413 request = (MainThreadRequest) ar.userObj;
1414 if (ar.exception != null) {
1415 request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM;
1416 } else {
1417 request.result = ((int[]) ar.result)[0];
1418 }
1419 notifyRequester(request);
1420 break;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001421 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1422 request = (MainThreadRequest) msg.obj;
1423 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1424 int subscriptionMode = (int) request.argument;
Sarah Chin49f22af2020-10-28 13:46:24 -07001425 getPhoneFromRequest(request).setCdmaSubscriptionMode(
1426 subscriptionMode, onCompleted);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001427 break;
1428 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1429 ar = (AsyncResult) msg.obj;
1430 request = (MainThreadRequest) ar.userObj;
1431 request.result = ar.exception == null;
1432 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001433 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001434 case CMD_GET_ALL_CELL_INFO:
1435 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001436 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001437 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001438 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001439 case EVENT_GET_ALL_CELL_INFO_DONE:
1440 ar = (AsyncResult) msg.obj;
1441 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001442 // If a timeout occurs, the response will be null
1443 request.result = (ar.exception == null && ar.result != null)
1444 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001445 synchronized (request) {
1446 request.notifyAll();
1447 }
1448 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001449 case CMD_REQUEST_CELL_INFO_UPDATE:
1450 request = (MainThreadRequest) msg.obj;
1451 request.phone.requestCellInfoUpdate(request.workSource,
1452 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1453 break;
1454 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1455 ar = (AsyncResult) msg.obj;
1456 request = (MainThreadRequest) ar.userObj;
1457 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1458 try {
1459 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001460 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001461 cb.onError(
1462 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1463 ar.exception.getClass().getName(),
1464 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001465 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001466 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001467 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001468 } else {
1469 // use the result as returned
1470 cb.onCellInfo((List<CellInfo>) ar.result);
1471 }
1472 } catch (RemoteException re) {
1473 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1474 }
1475 break;
Sarah Chincc055732020-11-18 13:39:35 -08001476 case CMD_GET_CELL_LOCATION: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001477 request = (MainThreadRequest) msg.obj;
1478 WorkSource ws = (WorkSource) request.argument;
1479 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001480 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001481 break;
Sarah Chincc055732020-11-18 13:39:35 -08001482 }
1483 case EVENT_GET_CELL_LOCATION_DONE: {
Nathan Harold3ff88932018-08-14 10:19:49 -07001484 ar = (AsyncResult) msg.obj;
1485 request = (MainThreadRequest) ar.userObj;
1486 if (ar.exception == null) {
1487 request.result = ar.result;
1488 } else {
Sarah Chincc055732020-11-18 13:39:35 -08001489 Phone phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001490 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001491 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001492 }
1493
1494 synchronized (request) {
1495 request.notifyAll();
1496 }
1497 break;
Sarah Chincc055732020-11-18 13:39:35 -08001498 }
chen xu6dac5ab2018-10-26 17:39:23 -07001499 case CMD_MODEM_REBOOT:
1500 request = (MainThreadRequest) msg.obj;
1501 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001502 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001503 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001504 case EVENT_CMD_MODEM_REBOOT_DONE:
1505 handleNullReturnEvent(msg, "rebootModem");
1506 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001507 case CMD_REQUEST_ENABLE_MODEM:
1508 request = (MainThreadRequest) msg.obj;
1509 boolean enable = (boolean) request.argument;
1510 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001511 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001512 PhoneConfigurationManager.getInstance()
1513 .enablePhone(request.phone, enable, onCompleted);
1514 break;
1515 case EVENT_ENABLE_MODEM_DONE:
1516 ar = (AsyncResult) msg.obj;
1517 request = (MainThreadRequest) ar.userObj;
1518 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001519 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001520 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001521 if ((boolean) request.result) {
1522 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1523 updateModemStateMetrics();
1524 } else {
1525 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1526 + ar.exception);
1527 }
1528 notifyRequester(request);
1529 break;
1530 case CMD_GET_MODEM_STATUS:
1531 request = (MainThreadRequest) msg.obj;
1532 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1533 PhoneConfigurationManager.getInstance()
1534 .getPhoneStatusFromModem(request.phone, onCompleted);
1535 break;
1536 case EVENT_GET_MODEM_STATUS_DONE:
1537 ar = (AsyncResult) msg.obj;
1538 request = (MainThreadRequest) ar.userObj;
1539 int id = request.phone.getPhoneId();
1540 if (ar.exception == null && ar.result != null) {
1541 request.result = ar.result;
1542 //update the cache as modem status has changed
1543 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1544 (boolean) request.result);
1545 } else {
1546 // Return true if modem status cannot be retrieved. For most cases,
1547 // modem status is on. And for older version modems, GET_MODEM_STATUS
1548 // and disable modem are not supported. Modem is always on.
1549 // TODO: this should be fixed in R to support a third
1550 // status UNKNOWN b/131631629
1551 request.result = true;
1552 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1553 + ar.exception);
1554 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001555 notifyRequester(request);
1556 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001557 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1558 request = (MainThreadRequest) msg.obj;
1559 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1560 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1561 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1562 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1563 break;
1564 }
1565 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1566 ar = (AsyncResult) msg.obj;
1567 request = (MainThreadRequest) ar.userObj;
1568 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1569 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1570 args.second.accept(ar.exception == null);
1571 notifyRequester(request);
1572 break;
1573 }
Sarah Chincc055732020-11-18 13:39:35 -08001574 case CMD_GET_SYSTEM_SELECTION_CHANNELS: {
1575 request = (MainThreadRequest) msg.obj;
1576 onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1577 Phone phone = getPhoneFromRequest(request);
1578 if (phone != null) {
1579 phone.getSystemSelectionChannels(onCompleted);
1580 } else {
1581 loge("getSystemSelectionChannels: No phone object");
1582 request.result = new ArrayList<RadioAccessSpecifier>();
1583 notifyRequester(request);
1584 }
1585 break;
1586 }
1587 case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE:
1588 ar = (AsyncResult) msg.obj;
1589 request = (MainThreadRequest) ar.userObj;
1590 if (ar.exception == null && ar.result != null) {
1591 request.result = ar.result;
1592 } else {
1593 request.result = new IllegalArgumentException(
1594 "Failed to retrieve system selection channels");
1595 if (ar.result == null) {
1596 loge("getSystemSelectionChannels: Empty response");
1597 } else {
1598 loge("getSystemSelectionChannels: Unknown exception");
1599 }
1600 }
1601 notifyRequester(request);
1602 break;
yincheng zhaod698b842019-09-06 17:06:54 -07001603 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1604 ar = (AsyncResult) msg.obj;
1605 request = (MainThreadRequest) ar.userObj;
1606 if (ar.exception == null && ar.result != null) {
1607 request.result = ar.result;
1608 } else {
1609 request.result = -1;
1610 loge("Failed to set Forbidden Plmns");
1611 if (ar.result == null) {
1612 loge("setForbidenPlmns: Empty response");
1613 } else if (ar.exception != null) {
1614 loge("setForbiddenPlmns: Exception: " + ar.exception);
1615 request.result = -1;
1616 } else {
1617 loge("setForbiddenPlmns: Unknown exception");
1618 }
1619 }
1620 notifyRequester(request);
1621 break;
1622 case CMD_SET_FORBIDDEN_PLMNS:
1623 request = (MainThreadRequest) msg.obj;
1624 uiccCard = getUiccCardFromRequest(request);
1625 if (uiccCard == null) {
1626 loge("setForbiddenPlmns: UiccCard is null");
1627 request.result = -1;
1628 notifyRequester(request);
1629 break;
1630 }
1631 Pair<Integer, List<String>> setFplmnsArgs =
1632 (Pair<Integer, List<String>>) request.argument;
1633 appType = setFplmnsArgs.first;
1634 List<String> fplmns = setFplmnsArgs.second;
1635 uiccApp = uiccCard.getApplicationByType(appType);
1636 if (uiccApp == null) {
1637 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1638 request.result = -1;
1639 loge("Failed to get UICC App");
1640 notifyRequester(request);
1641 } else {
1642 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1643 ((SIMRecords) uiccApp.getIccRecords())
1644 .setForbiddenPlmns(onCompleted, fplmns);
1645 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001646 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001647 case CMD_ERASE_MODEM_CONFIG:
1648 request = (MainThreadRequest) msg.obj;
1649 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1650 defaultPhone.eraseModemConfig(onCompleted);
1651 break;
1652 case EVENT_ERASE_MODEM_CONFIG_DONE:
1653 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001654 break;
zoey chenf95ca592019-12-30 16:11:23 +08001655
1656 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1657 request = (MainThreadRequest) msg.obj;
1658 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1659 Pair<String, String> changed = (Pair<String, String>) request.argument;
1660 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1661 changed.first, changed.second, onCompleted);
1662 break;
1663 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1664 ar = (AsyncResult) msg.obj;
1665 request = (MainThreadRequest) ar.userObj;
1666 if (ar.exception == null) {
1667 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1668 } else {
1669 request.result = msg.arg1;
1670 }
1671 notifyRequester(request);
1672 break;
1673
1674 case CMD_SET_ICC_LOCK_ENABLED:
1675 request = (MainThreadRequest) msg.obj;
1676 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1677 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1678 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1679 enabled.first, enabled.second, onCompleted);
1680 break;
1681 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1682 ar = (AsyncResult) msg.obj;
1683 request = (MainThreadRequest) ar.userObj;
1684 if (ar.exception == null) {
1685 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1686 } else {
1687 request.result = msg.arg1;
1688 }
1689 notifyRequester(request);
1690 break;
1691
Peter Wangdafb9ac2020-01-15 14:13:38 -08001692 case MSG_NOTIFY_USER_ACTIVITY:
1693 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001694 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001695 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1696 getDefaultPhone().getContext().sendBroadcastAsUser(
1697 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1698 break;
Jack Nudelman24d51a52020-11-24 12:08:04 -08001699
1700 case CMD_SET_DATA_THROTTLING: {
1701 request = (MainThreadRequest) msg.obj;
1702 onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request);
1703 DataThrottlingRequest dataThrottlingRequest =
1704 (DataThrottlingRequest) request.argument;
1705 Phone phone = getPhoneFromRequest(request);
1706 if (phone != null) {
1707 phone.setDataThrottling(onCompleted,
1708 request.workSource, dataThrottlingRequest.getDataThrottlingAction(),
1709 dataThrottlingRequest.getCompletionDurationMillis());
1710 } else {
1711 loge("setDataThrottling: No phone object");
1712 request.result =
1713 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1714 notifyRequester(request);
1715 }
1716
1717 break;
1718 }
1719 case EVENT_SET_DATA_THROTTLING_DONE:
1720 ar = (AsyncResult) msg.obj;
1721 request = (MainThreadRequest) ar.userObj;
1722
1723 if (ar.exception == null) {
1724 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
1725 } else if (ar.exception instanceof CommandException) {
1726 loge("setDataThrottling: CommandException: " + ar.exception);
1727 CommandException.Error error =
1728 ((CommandException) (ar.exception)).getCommandError();
1729
1730 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
1731 request.result = TelephonyManager
1732 .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
1733 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1734 request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS;
1735 } else {
1736 request.result =
1737 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1738 }
1739 } else {
1740 request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
1741 }
1742 Log.w(LOG_TAG, "DataThrottlingResult = " + request.result);
1743 notifyRequester(request);
1744 break;
Jordan Liud5366d92020-11-24 14:50:34 -08001745
1746 case CMD_SET_SIM_POWER: {
1747 request = (MainThreadRequest) msg.obj;
1748 onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request);
1749 request = (MainThreadRequest) msg.obj;
1750 int stateToSet =
1751 ((Pair<Integer, IIntegerConsumer>)
1752 request.argument).first;
1753 request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource);
1754 break;
1755 }
1756 case EVENT_SET_SIM_POWER_DONE: {
1757 ar = (AsyncResult) msg.obj;
1758 request = (MainThreadRequest) ar.userObj;
1759 IIntegerConsumer callback =
1760 ((Pair<Integer, IIntegerConsumer>) request.argument).second;
1761 if (ar.exception != null) {
1762 loge("setSimPower exception: " + ar.exception);
1763 int errorCode = TelephonyManager.CallForwardingInfoCallback
1764 .RESULT_ERROR_UNKNOWN;
1765 if (ar.exception instanceof CommandException) {
1766 CommandException.Error error =
1767 ((CommandException) (ar.exception)).getCommandError();
1768 if (error == CommandException.Error.SIM_ERR) {
1769 errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR;
1770 } else if (error == CommandException.Error.INVALID_ARGUMENTS) {
1771 errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE;
1772 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1773 errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED;
1774 } else {
1775 errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR;
1776 }
1777 }
1778 try {
1779 callback.accept(errorCode);
1780 } catch (RemoteException e) {
1781 // Ignore if the remote process is no longer available to call back.
1782 Log.w(LOG_TAG, "setSimPower: callback not available.");
1783 }
1784 } else {
1785 try {
1786 callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS);
1787 } catch (RemoteException e) {
1788 // Ignore if the remote process is no longer available to call back.
1789 Log.w(LOG_TAG, "setSimPower: callback not available.");
1790 }
1791 }
1792 break;
1793 }
1794
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001795 default:
1796 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1797 break;
1798 }
1799 }
Jake Hambye994d462014-02-03 13:10:13 -08001800
Pengquan Menga1bb6272018-09-06 09:59:22 -07001801 private void notifyRequester(MainThreadRequest request) {
1802 synchronized (request) {
1803 request.notifyAll();
1804 }
1805 }
1806
Jake Hambye994d462014-02-03 13:10:13 -08001807 private void handleNullReturnEvent(Message msg, String command) {
1808 AsyncResult ar = (AsyncResult) msg.obj;
1809 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1810 if (ar.exception == null) {
1811 request.result = true;
1812 } else {
1813 request.result = false;
1814 if (ar.exception instanceof CommandException) {
1815 loge(command + ": CommandException: " + ar.exception);
1816 } else {
1817 loge(command + ": Unknown exception");
1818 }
1819 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001820 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001821 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 }
1823
1824 /**
1825 * Posts the specified command to be executed on the main thread,
1826 * waits for the request to complete, and returns the result.
1827 * @see #sendRequestAsync
1828 */
1829 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001830 return sendRequest(
1831 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001832 }
1833
1834 /**
1835 * Posts the specified command to be executed on the main thread,
1836 * waits for the request to complete, and returns the result.
1837 * @see #sendRequestAsync
1838 */
1839 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1840 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001841 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001842 }
1843
1844 /**
1845 * Posts the specified command to be executed on the main thread,
1846 * waits for the request to complete, and returns the result.
1847 * @see #sendRequestAsync
1848 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001849 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001850 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001851 }
1852
1853 /**
1854 * Posts the specified command to be executed on the main thread,
1855 * waits for the request to complete, and returns the result.
1856 * @see #sendRequestAsync
1857 */
Nathan Harold92bed182018-10-12 18:16:49 -07001858 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1859 return sendRequest(command, argument, subId, null, workSource);
1860 }
1861
1862 /**
1863 * Posts the specified command to be executed on the main thread,
1864 * waits for the request to complete, and returns the result.
1865 * @see #sendRequestAsync
1866 */
1867 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1868 return sendRequest(
1869 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1870 }
1871
1872 /**
1873 * Posts the specified command to be executed on the main thread,
1874 * waits for the request to complete, and returns the result.
1875 * @see #sendRequestAsync
1876 */
1877 private Object sendRequest(
1878 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001879 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1880 throw new RuntimeException("This method will deadlock if called from the main thread.");
1881 }
1882
Nathan Harold92bed182018-10-12 18:16:49 -07001883 MainThreadRequest request = null;
1884 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1885 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1886 } else if (phone != null) {
1887 request = new MainThreadRequest(argument, phone, workSource);
1888 } else {
1889 request = new MainThreadRequest(argument, subId, workSource);
1890 }
1891
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001892 Message msg = mMainThreadHandler.obtainMessage(command, request);
1893 msg.sendToTarget();
1894
1895 // Wait for the request to complete
1896 synchronized (request) {
1897 while (request.result == null) {
1898 try {
1899 request.wait();
1900 } catch (InterruptedException e) {
1901 // Do nothing, go back and wait until the request is complete
1902 }
1903 }
1904 }
1905 return request.result;
1906 }
1907
1908 /**
1909 * Asynchronous ("fire and forget") version of sendRequest():
1910 * Posts the specified command to be executed on the main thread, and
1911 * returns immediately.
1912 * @see #sendRequest
1913 */
1914 private void sendRequestAsync(int command) {
1915 mMainThreadHandler.sendEmptyMessage(command);
1916 }
1917
1918 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001919 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001920 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001921 */
1922 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001923 sendRequestAsync(command, argument, null, null);
1924 }
1925
1926 /**
1927 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1928 * @see {@link #sendRequest(int,Object)}
1929 */
1930 private void sendRequestAsync(
1931 int command, Object argument, Phone phone, WorkSource workSource) {
1932 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001933 Message msg = mMainThreadHandler.obtainMessage(command, request);
1934 msg.sendToTarget();
1935 }
1936
1937 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 * Initialize the singleton PhoneInterfaceManager instance.
1939 * This is only done once, at startup, from PhoneApp.onCreate().
1940 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001941 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001942 synchronized (PhoneInterfaceManager.class) {
1943 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001944 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 } else {
1946 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1947 }
1948 return sInstance;
1949 }
1950 }
1951
1952 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001953 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001955 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001956 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001957 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001958 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1959 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001960 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001961 mTelephonySharedPreferences =
1962 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001963 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001964 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001965 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001966
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001967 publish();
1968 }
1969
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001970 private Phone getDefaultPhone() {
1971 Phone thePhone = getPhone(getDefaultSubscription());
1972 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1973 }
1974
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001975 private void publish() {
1976 if (DBG) log("publish: " + this);
1977
Peter Wangc035ce42020-01-08 21:00:22 -08001978 TelephonyFrameworkInitializer
1979 .getTelephonyServiceManager()
1980 .getTelephonyServiceRegisterer()
1981 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001982 }
1983
Stuart Scott584921c2015-01-15 17:10:34 -08001984 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001985 if (request.phone != null) {
1986 return request.phone;
1987 } else {
1988 return getPhoneFromSubId(request.subId);
1989 }
1990 }
1991
1992 private Phone getPhoneFromSubId(int subId) {
1993 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1994 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001995 }
1996
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001997 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1998 Phone phone = getPhoneFromRequest(request);
1999 return phone == null ? null :
2000 UiccController.getInstance().getUiccCard(phone.getPhoneId());
2001 }
2002
Wink Saville36469e72014-06-11 15:17:00 -07002003 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07002004 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08002005 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002007
Naina Nalluri8ff344d2019-09-17 14:10:30 -07002008 private void sendEraseModemConfig(Phone phone) {
2009 if (phone != null) {
2010 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2011 mApp, phone.getSubId(), "eraseModemConfig");
2012 final long identity = Binder.clearCallingIdentity();
2013 try {
2014 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
2015 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
2016 } finally {
2017 Binder.restoreCallingIdentity(identity);
2018 }
2019 }
2020 }
2021
Peter Wang050bb052020-01-13 23:33:09 -08002022 private boolean isImsAvailableOnDevice() {
2023 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
2024 if (pm == null) {
2025 // For some reason package manger is not available.. This will fail internally anyway,
2026 // so do not throw error and allow.
2027 return true;
2028 }
2029 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
2030 }
2031
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002033 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07002034 }
2035
Wink Savilleb564aae2014-10-23 10:18:09 -07002036 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 if (DBG) log("dial: " + number);
2038 // No permission check needed here: This is just a wrapper around the
2039 // ACTION_DIAL intent, which is available to any app since it puts up
2040 // the UI before it does anything.
2041
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 String url = createTelUrl(number);
2045 if (url == null) {
2046 return;
2047 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002048
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002049 // PENDING: should we just silently fail if phone is offhook or ringing?
2050 PhoneConstants.State state = mCM.getState(subId);
2051 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
2052 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
2053 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2054 mApp.startActivity(intent);
2055 }
2056 } finally {
2057 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002058 }
2059 }
2060
2061 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002062 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07002063 }
2064
Wink Savilleb564aae2014-10-23 10:18:09 -07002065 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002066 if (DBG) log("call: " + number);
2067
2068 // This is just a wrapper around the ACTION_CALL intent, but we still
2069 // need to do a permission check since we're calling startActivity()
2070 // from the context of the phone app.
2071 enforceCallPermission();
2072
Jordan Liu1617b712019-07-10 15:06:26 -07002073 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002074 != AppOpsManager.MODE_ALLOWED) {
2075 return;
2076 }
2077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 String url = createTelUrl(number);
2081 if (url == null) {
2082 return;
2083 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002084
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002085 boolean isValid = false;
2086 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
2087 if (slist != null) {
2088 for (SubscriptionInfo subInfoRecord : slist) {
2089 if (subInfoRecord.getSubscriptionId() == subId) {
2090 isValid = true;
2091 break;
2092 }
Wink Saville3ab207e2014-11-20 13:07:20 -08002093 }
Wink Saville08874612014-08-31 19:19:58 -07002094 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 if (!isValid) {
2096 return;
2097 }
Wink Saville08874612014-08-31 19:19:58 -07002098
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002099 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
2100 intent.putExtra(SUBSCRIPTION_KEY, subId);
2101 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
2102 mApp.startActivity(intent);
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
2105 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002106 }
2107
Wink Savilleb564aae2014-10-23 10:18:09 -07002108 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002109 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002110 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2111 }
2112
Wink Savilleb564aae2014-10-23 10:18:09 -07002113 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002114 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07002115 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
2116 }
2117
Wink Savilleb564aae2014-10-23 10:18:09 -07002118 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
2124 checkSimPin.start();
2125 return checkSimPin.unlockSim(null, pin);
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
2128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Wink Savilleb564aae2014-10-23 10:18:09 -07002131 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002133
2134 final long identity = Binder.clearCallingIdentity();
2135 try {
2136 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
2137 checkSimPuk.start();
2138 return checkSimPuk.unlockSim(puk, pin);
2139 } finally {
2140 Binder.restoreCallingIdentity(identity);
2141 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002142 }
2143
2144 /**
Wink Saville9de0f752013-10-22 19:04:03 -07002145 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002146 * a synchronous one.
2147 */
2148 private static class UnlockSim extends Thread {
2149
2150 private final IccCard mSimCard;
2151
2152 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07002153 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2154 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002155
2156 // For replies from SimCard interface
2157 private Handler mHandler;
2158
2159 // For async handler to identify request type
2160 private static final int SUPPLY_PIN_COMPLETE = 100;
2161
2162 public UnlockSim(IccCard simCard) {
2163 mSimCard = simCard;
2164 }
2165
2166 @Override
2167 public void run() {
2168 Looper.prepare();
2169 synchronized (UnlockSim.this) {
2170 mHandler = new Handler() {
2171 @Override
2172 public void handleMessage(Message msg) {
2173 AsyncResult ar = (AsyncResult) msg.obj;
2174 switch (msg.what) {
2175 case SUPPLY_PIN_COMPLETE:
2176 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
2177 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07002178 mRetryCount = msg.arg1;
2179 if (ar.exception != null) {
2180 if (ar.exception instanceof CommandException &&
2181 ((CommandException)(ar.exception)).getCommandError()
2182 == CommandException.Error.PASSWORD_INCORRECT) {
2183 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08002184 } //When UiccCardApp dispose,handle message and return exception
2185 else if (ar.exception instanceof CommandException &&
2186 ((CommandException) (ar.exception)).getCommandError()
2187 == CommandException.Error.ABORTED) {
2188 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07002189 } else {
2190 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
2191 }
2192 } else {
2193 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
2194 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002195 mDone = true;
2196 UnlockSim.this.notifyAll();
2197 }
2198 break;
2199 }
2200 }
2201 };
2202 UnlockSim.this.notifyAll();
2203 }
2204 Looper.loop();
2205 }
2206
2207 /*
2208 * Use PIN or PUK to unlock SIM card
2209 *
2210 * If PUK is null, unlock SIM card with PIN
2211 *
2212 * If PUK is not null, unlock SIM card with PUK and set PIN code
2213 */
Wink Saville9de0f752013-10-22 19:04:03 -07002214 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002215
2216 while (mHandler == null) {
2217 try {
2218 wait();
2219 } catch (InterruptedException e) {
2220 Thread.currentThread().interrupt();
2221 }
2222 }
2223 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
2224
2225 if (puk == null) {
2226 mSimCard.supplyPin(pin, callback);
2227 } else {
2228 mSimCard.supplyPuk(puk, pin, callback);
2229 }
2230
2231 while (!mDone) {
2232 try {
2233 Log.d(LOG_TAG, "wait for done");
2234 wait();
2235 } catch (InterruptedException e) {
2236 // Restore the interrupted status
2237 Thread.currentThread().interrupt();
2238 }
2239 }
2240 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07002241 int[] resultArray = new int[2];
2242 resultArray[0] = mResult;
2243 resultArray[1] = mRetryCount;
2244 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002245 }
2246 }
2247
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002248 /**
2249 * This method has been removed due to privacy and stability concerns.
2250 */
2251 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002253 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
2254 return;
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Nathan Harold1f889d82020-06-04 17:05:26 -07002257 @Override
2258 public void updateServiceLocationWithPackageName(String callingPackage) {
2259 mApp.getSystemService(AppOpsManager.class)
2260 .checkPackage(Binder.getCallingUid(), callingPackage);
2261
Nathan Haroldf096d982020-11-18 17:18:06 -08002262 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harold1f889d82020-06-04 17:05:26 -07002263 if (targetSdk > android.os.Build.VERSION_CODES.R) {
2264 // Callers targeting S have no business invoking this method.
2265 return;
2266 }
2267
2268 LocationAccessPolicy.LocationPermissionResult locationResult =
2269 LocationAccessPolicy.checkLocationPermission(mApp,
2270 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2271 .setCallingPackage(callingPackage)
2272 .setCallingFeatureId(null)
2273 .setCallingPid(Binder.getCallingPid())
2274 .setCallingUid(Binder.getCallingUid())
2275 .setMethod("updateServiceLocation")
2276 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2277 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2278 .build());
2279 // Apps that lack location permission have no business calling this method;
2280 // however, because no permission was declared in the public API, denials must
2281 // all be "soft".
2282 switch (locationResult) {
2283 case DENIED_HARD: /* fall through */
2284 case DENIED_SOFT:
2285 return;
2286 }
2287
2288 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002289 final long identity = Binder.clearCallingIdentity();
2290 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07002291 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002292 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07002293 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002294 }
2295 } finally {
2296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002298 }
2299
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002300 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002301 @Override
2302 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002303 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002304 }
2305
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002306
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002307 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002308 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2309 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2310 callingFeatureId);
2311 }
2312
2313 @Deprecated
2314 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002315 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002316 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2317 }
2318
2319 @Override
2320 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2321 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002322 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002323 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002324 return false;
2325 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002326
2327 final long identity = Binder.clearCallingIdentity();
2328 try {
2329 return isRadioOnForSubscriber(subId);
2330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002333 }
2334
2335 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 final Phone phone = getPhone(subId);
2339 if (phone != null) {
2340 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2341 } else {
2342 return false;
2343 }
2344 } finally {
2345 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002347 }
2348
2349 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002350 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002351 }
Wink Saville36469e72014-06-11 15:17:00 -07002352
Wink Savilleb564aae2014-10-23 10:18:09 -07002353 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355
2356 final long identity = Binder.clearCallingIdentity();
2357 try {
2358 final Phone phone = getPhone(subId);
2359 if (phone != null) {
2360 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2361 }
2362 } finally {
2363 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002364 }
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
2367 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002368 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002369 }
2370
Wink Savilleb564aae2014-10-23 10:18:09 -07002371 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002372 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002373
2374 final long identity = Binder.clearCallingIdentity();
2375 try {
2376 final Phone phone = getPhone(subId);
2377 if (phone == null) {
2378 return false;
2379 }
2380 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2381 toggleRadioOnOffForSubscriber(subId);
2382 }
2383 return true;
2384 } finally {
2385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002386 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002387 }
Wink Saville36469e72014-06-11 15:17:00 -07002388
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002389 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002390 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002391 /*
2392 * If any of the Radios are available, it will need to be
2393 * shutdown. So return true if any Radio is available.
2394 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002395 final long identity = Binder.clearCallingIdentity();
2396 try {
2397 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2398 Phone phone = PhoneFactory.getPhone(i);
2399 if (phone != null && phone.isRadioAvailable()) return true;
2400 }
2401 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2402 return false;
2403 } finally {
2404 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002405 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002406 }
2407
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002408 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002409 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002410 enforceModifyPermission();
2411
2412 final long identity = Binder.clearCallingIdentity();
2413 try {
2414 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2415 logv("Shutting down Phone " + i);
2416 shutdownRadioUsingPhoneId(i);
2417 }
2418 } finally {
2419 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002420 }
2421 }
2422
2423 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002424 Phone phone = PhoneFactory.getPhone(phoneId);
2425 if (phone != null && phone.isRadioAvailable()) {
2426 phone.shutdownRadio();
2427 }
2428 }
2429
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002431 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002432
2433 final long identity = Binder.clearCallingIdentity();
2434 try {
2435 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2436 if (defaultPhone != null) {
2437 defaultPhone.setRadioPower(turnOn);
2438 return true;
2439 } else {
2440 loge("There's no default phone.");
2441 return false;
2442 }
2443 } finally {
2444 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002445 }
Wink Saville36469e72014-06-11 15:17:00 -07002446 }
2447
Wink Savilleb564aae2014-10-23 10:18:09 -07002448 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002449 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002450
2451 final long identity = Binder.clearCallingIdentity();
2452 try {
2453 final Phone phone = getPhone(subId);
2454 if (phone != null) {
2455 phone.setRadioPower(turnOn);
2456 return true;
2457 } else {
2458 return false;
2459 }
2460 } finally {
2461 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002462 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Wink Saville36469e72014-06-11 15:17:00 -07002465 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002466 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002467 public boolean enableDataConnectivity() {
2468 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469
2470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 int subId = mSubscriptionController.getDefaultDataSubId();
2473 final Phone phone = getPhone(subId);
2474 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002475 phone.getDataEnabledSettings().setDataEnabled(
2476 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002477 return true;
2478 } else {
2479 return false;
2480 }
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002484 }
2485
Wink Saville36469e72014-06-11 15:17:00 -07002486 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002487 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002488 public boolean disableDataConnectivity() {
2489 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490
2491 final long identity = Binder.clearCallingIdentity();
2492 try {
2493 int subId = mSubscriptionController.getDefaultDataSubId();
2494 final Phone phone = getPhone(subId);
2495 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07002496 phone.getDataEnabledSettings().setDataEnabled(
2497 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002498 return true;
2499 } else {
2500 return false;
2501 }
2502 } finally {
2503 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002504 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002505 }
2506
Sanket Padawe356d7632015-06-22 14:03:32 -07002507 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002508 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002509 final long identity = Binder.clearCallingIdentity();
2510 try {
2511 final Phone phone = getPhone(subId);
2512 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002513 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002514 } else {
2515 return false;
2516 }
2517 } finally {
2518 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002519 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002520 }
2521
2522 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002523 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002524 }
2525
pkanwarae03a6b2016-11-06 20:37:09 -08002526 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002527 enforceCallPermission();
2528
2529 final long identity = Binder.clearCallingIdentity();
2530 try {
2531 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2532 return;
2533 }
2534 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2535 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2536 } finally {
2537 Binder.restoreCallingIdentity(identity);
2538 }
pkanwar32d516d2016-10-14 19:37:38 -07002539 };
2540
Wink Savilleb564aae2014-10-23 10:18:09 -07002541 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002543
2544 final long identity = Binder.clearCallingIdentity();
2545 try {
2546 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2547 return false;
2548 }
2549 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2550 } finally {
2551 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002552 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002553 }
2554
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002555 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002556 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002557 }
2558
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002559 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002560 final long identity = Binder.clearCallingIdentity();
2561 try {
2562 Phone phone = PhoneFactory.getPhone(slotIndex);
2563 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2564 PhoneConstantConversions.convertCallState(phone.getState());
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Sanket Padawe356d7632015-06-22 14:03:32 -07002570 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002571 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002572 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2573 }
2574
2575 @Override
2576 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002577 final long identity = Binder.clearCallingIdentity();
2578 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002579 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002580 if (phone != null) {
2581 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2582 } else {
2583 return PhoneConstantConversions.convertDataState(
2584 PhoneConstants.DataState.DISCONNECTED);
2585 }
2586 } finally {
2587 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002588 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002589 }
2590
Sanket Padawe356d7632015-06-22 14:03:32 -07002591 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002592 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002593 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2594 }
2595
2596 @Override
2597 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002598 final long identity = Binder.clearCallingIdentity();
2599 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002600 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002601 if (phone != null) {
2602 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2603 } else {
2604 return TelephonyManager.DATA_ACTIVITY_NONE;
2605 }
2606 } finally {
2607 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002608 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002609 }
2610
2611 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002612 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002613 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002614 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002615
2616 LocationAccessPolicy.LocationPermissionResult locationResult =
2617 LocationAccessPolicy.checkLocationPermission(mApp,
2618 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2619 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002620 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002621 .setCallingPid(Binder.getCallingPid())
2622 .setCallingUid(Binder.getCallingUid())
2623 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002624 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002625 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2626 .build());
2627 switch (locationResult) {
2628 case DENIED_HARD:
2629 throw new SecurityException("Not allowed to access cell location");
2630 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002631 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2632 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002633 }
2634
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002635 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002636 final long identity = Binder.clearCallingIdentity();
2637 try {
2638 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002639 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002640 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
Svetoslav64fad262015-04-14 14:35:21 -07002644 }
2645
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002646 @Override
Jack Yu01425032020-02-22 19:38:58 -08002647 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002648 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2649 // registered cell info, so return a NULL country instead.
2650 final long identity = Binder.clearCallingIdentity();
2651 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002652 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2653 // Get default phone in this case.
2654 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2655 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002656 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002658 if (phone == null) return "";
2659 ServiceStateTracker sst = phone.getServiceStateTracker();
2660 if (sst == null) return "";
2661 LocaleTracker lt = sst.getLocaleTracker();
2662 if (lt == null) return "";
2663 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2664 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2665 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002666 } finally {
2667 Binder.restoreCallingIdentity(identity);
2668 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002669 }
2670
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002671 /**
2672 * This method was removed due to potential issues caused by performing partial
2673 * updates of service state, and lack of a credible use case.
2674 *
2675 * This has the ability to break the telephony implementation by disabling notification of
2676 * changes in device connectivity. DO NOT USE THIS!
2677 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002678 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002679 public void enableLocationUpdates() {
2680 mApp.enforceCallingOrSelfPermission(
2681 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002682 }
2683
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002684 /**
2685 * This method was removed due to potential issues caused by performing partial
2686 * updates of service state, and lack of a credible use case.
2687 *
2688 * This has the ability to break the telephony implementation by disabling notification of
2689 * changes in device connectivity. DO NOT USE THIS!
2690 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 @Override
2692 public void disableLocationUpdates() {
2693 mApp.enforceCallingOrSelfPermission(
2694 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002695 }
2696
2697 @Override
2698 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002699 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2700 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08002701 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002702 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2703 throw new SecurityException(
2704 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2705 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002706
Jordan Liu1617b712019-07-10 15:06:26 -07002707 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2709 return null;
2710 }
Svetoslav64fad262015-04-14 14:35:21 -07002711
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002712 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002713
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002714 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002715 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002716
Nathan Haroldf180aac2018-06-01 18:43:55 -07002717 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2718 for (CellInfo ci : info) {
2719 if (ci instanceof CellInfoGsm) {
2720 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2721 } else if (ci instanceof CellInfoWcdma) {
2722 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2723 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002724 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002725 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 }
2727
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002728 private List<CellInfo> getCachedCellInfo() {
2729 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2730 for (Phone phone : PhoneFactory.getPhones()) {
2731 List<CellInfo> info = phone.getAllCellInfo();
2732 if (info != null) cellInfos.addAll(info);
2733 }
2734 return cellInfos;
2735 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002736
2737 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002738 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002739 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002740 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002741
2742 LocationAccessPolicy.LocationPermissionResult locationResult =
2743 LocationAccessPolicy.checkLocationPermission(mApp,
2744 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2745 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002746 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002747 .setCallingPid(Binder.getCallingPid())
2748 .setCallingUid(Binder.getCallingUid())
2749 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002750 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002751 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2752 .build());
2753 switch (locationResult) {
2754 case DENIED_HARD:
2755 throw new SecurityException("Not allowed to access cell info");
2756 case DENIED_SOFT:
2757 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002758 }
2759
Nathan Haroldf096d982020-11-18 17:18:06 -08002760 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002761 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2762 return getCachedCellInfo();
2763 }
2764
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002765 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002766 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002767 final long identity = Binder.clearCallingIdentity();
2768 try {
2769 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2770 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002771 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002772 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002773 if (info != null) cellInfos.addAll(info);
2774 }
2775 return cellInfos;
2776 } finally {
2777 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 }
2779 }
2780
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002782 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2783 String callingFeatureId) {
2784 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2785 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002786 }
2787
2788 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002789 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2790 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002791 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002792 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002793 }
2794
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002795 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2796 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002797 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002798 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002799
2800 LocationAccessPolicy.LocationPermissionResult locationResult =
2801 LocationAccessPolicy.checkLocationPermission(mApp,
2802 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2803 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002804 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002805 .setCallingPid(Binder.getCallingPid())
2806 .setCallingUid(Binder.getCallingUid())
2807 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002808 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2809 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002810 .build());
2811 switch (locationResult) {
2812 case DENIED_HARD:
Nathan Haroldf096d982020-11-18 17:18:06 -08002813 if (TelephonyPermissions
2814 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002815 // Safetynet logging for b/154934934
2816 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2817 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002818 throw new SecurityException("Not allowed to access cell info");
2819 case DENIED_SOFT:
Nathan Haroldf096d982020-11-18 17:18:06 -08002820 if (TelephonyPermissions
2821 .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) {
Hall Liuaa4283b2020-05-21 17:09:35 -07002822 // Safetynet logging for b/154934934
2823 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2824 }
Nathan Harold5320c422019-05-09 10:26:08 -07002825 try {
2826 cb.onCellInfo(new ArrayList<CellInfo>());
2827 } catch (RemoteException re) {
2828 // Drop without consequences
2829 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002830 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002831 }
2832
Nathan Harolda939a962019-05-09 10:13:47 -07002833
2834 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002835 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2836
2837 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2838 }
2839
2840 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002842 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002843 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002844
2845 final long identity = Binder.clearCallingIdentity();
2846 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002847 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002848 } finally {
2849 Binder.restoreCallingIdentity(identity);
2850 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002851 }
2852
Shishir Agrawala9f32182016-04-12 12:00:16 -07002853 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002854 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002855 Phone phone = PhoneFactory.getPhone(slotIndex);
2856 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002857 return null;
2858 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002859 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002860 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002861 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002862 return null;
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 return phone.getImei();
2868 } finally {
2869 Binder.restoreCallingIdentity(identity);
2870 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002871 }
2872
2873 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002874 public String getTypeAllocationCodeForSlot(int slotIndex) {
2875 Phone phone = PhoneFactory.getPhone(slotIndex);
2876 String tac = null;
2877 if (phone != null) {
2878 String imei = phone.getImei();
2879 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2880 }
2881 return tac;
2882 }
2883
2884 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002885 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002886 Phone phone = PhoneFactory.getPhone(slotIndex);
2887 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002888 return null;
2889 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002890
Jeff Davidson913390f2018-02-23 17:11:49 -08002891 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002892 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002893 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002894 return null;
2895 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002896
2897 final long identity = Binder.clearCallingIdentity();
2898 try {
2899 return phone.getMeid();
2900 } finally {
2901 Binder.restoreCallingIdentity(identity);
2902 }
Jack Yu2af8d712017-03-15 17:14:14 -07002903 }
2904
2905 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002906 public String getManufacturerCodeForSlot(int slotIndex) {
2907 Phone phone = PhoneFactory.getPhone(slotIndex);
2908 String manufacturerCode = null;
2909 if (phone != null) {
2910 String meid = phone.getMeid();
2911 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2912 }
2913 return manufacturerCode;
2914 }
2915
2916 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002917 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2918 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002919 Phone phone = PhoneFactory.getPhone(slotIndex);
2920 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 return null;
2922 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002923 int subId = phone.getSubId();
2924 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002925 mApp, subId, callingPackage, callingFeatureId,
2926 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002927 return null;
2928 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002929
2930 final long identity = Binder.clearCallingIdentity();
2931 try {
2932 return phone.getDeviceSvn();
2933 } finally {
2934 Binder.restoreCallingIdentity(identity);
2935 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002936 }
2937
fionaxu43304da2017-11-27 22:51:16 -08002938 @Override
2939 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002940 final long identity = Binder.clearCallingIdentity();
2941 try {
2942 final Phone phone = getPhone(subId);
2943 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2944 } finally {
2945 Binder.restoreCallingIdentity(identity);
2946 }
fionaxu43304da2017-11-27 22:51:16 -08002947 }
2948
2949 @Override
2950 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
2953 final Phone phone = getPhone(subId);
2954 return phone == null ? null : phone.getCarrierName();
2955 } finally {
2956 Binder.restoreCallingIdentity(identity);
2957 }
fionaxu43304da2017-11-27 22:51:16 -08002958 }
2959
calvinpanffe225e2018-11-01 19:43:06 +08002960 @Override
chen xu0026ca62019-03-06 15:28:50 -08002961 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002962 final long identity = Binder.clearCallingIdentity();
2963 try {
2964 final Phone phone = getPhone(subId);
2965 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002966 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002967 } finally {
2968 Binder.restoreCallingIdentity(identity);
2969 }
2970 }
2971
2972 @Override
chen xu0026ca62019-03-06 15:28:50 -08002973 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002977 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002978 } finally {
2979 Binder.restoreCallingIdentity(identity);
2980 }
2981 }
2982
chen xu651eec72018-11-11 19:03:44 -08002983 @Override
chen xu864e11c2018-12-06 22:10:03 -08002984 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2985 if (!isSubscriptionMccMnc) {
2986 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2987 }
chen xu651eec72018-11-11 19:03:44 -08002988 final Phone phone = PhoneFactory.getPhone(slotIndex);
2989 if (phone == null) {
2990 return TelephonyManager.UNKNOWN_CARRIER_ID;
2991 }
2992 final long identity = Binder.clearCallingIdentity();
2993 try {
2994 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2995 } finally {
2996 Binder.restoreCallingIdentity(identity);
2997 }
2998 }
2999
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003000 //
3001 // Internal helper methods.
3002 //
3003
Sanket Padaweee13a9b2016-03-08 17:30:28 -08003004 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003005 * Make sure the caller has the MODIFY_PHONE_STATE permission.
3006 *
3007 * @throws SecurityException if the caller does not have the required permission
3008 */
3009 private void enforceModifyPermission() {
3010 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
3011 }
3012
Shuo Qian5bac1ee2020-01-16 20:51:11 -08003013 /**
3014 * Make sure the caller is system.
3015 *
3016 * @throws SecurityException if the caller is not system.
3017 */
3018 private void enforceSystemCaller() {
3019 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
3020 throw new SecurityException("Caller must be system");
3021 }
3022 }
3023
Shuo Qianf2b2df42019-11-13 17:43:31 -08003024 private void enforceActiveEmergencySessionPermission() {
3025 mApp.enforceCallingOrSelfPermission(
3026 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
3027 }
3028
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003029 /**
3030 * Make sure the caller has the CALL_PHONE permission.
3031 *
3032 * @throws SecurityException if the caller does not have the required permission
3033 */
3034 private void enforceCallPermission() {
3035 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
3036 }
3037
paulhu423b5f22019-08-23 19:17:33 +08003038 private void enforceSettingsPermission() {
3039 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07003040 }
3041
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003042 private String createTelUrl(String number) {
3043 if (TextUtils.isEmpty(number)) {
3044 return null;
3045 }
3046
Jake Hambye994d462014-02-03 13:10:13 -08003047 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003048 }
3049
Ihab Awadf9e92732013-12-05 18:02:52 -08003050 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003051 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
3052 }
3053
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07003054 private static void logv(String msg) {
3055 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
3056 }
3057
Ihab Awadf9e92732013-12-05 18:02:52 -08003058 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003059 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
3060 }
3061
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003062 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003063 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07003064 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07003065 }
3066
Sanket Padawe356d7632015-06-22 14:03:32 -07003067 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07003068 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003069 final long identity = Binder.clearCallingIdentity();
3070 try {
3071 final Phone phone = PhoneFactory.getPhone(slotIndex);
3072 if (phone == null) {
3073 return PhoneConstants.PHONE_TYPE_NONE;
3074 } else {
3075 return phone.getPhoneType();
3076 }
3077 } finally {
3078 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003079 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003080 }
3081
3082 /**
3083 * Returns the CDMA ERI icon index to display
3084 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003085 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003086 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
3087 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
3088 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003089 }
3090
Sanket Padawe356d7632015-06-22 14:03:32 -07003091 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003092 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
3093 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003095 mApp, subId, callingPackage, callingFeatureId,
3096 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003097 return -1;
3098 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003099
3100 final long identity = Binder.clearCallingIdentity();
3101 try {
3102 final Phone phone = getPhone(subId);
3103 if (phone != null) {
3104 return phone.getCdmaEriIconIndex();
3105 } else {
3106 return -1;
3107 }
3108 } finally {
3109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003110 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003111 }
3112
3113 /**
3114 * Returns the CDMA ERI icon mode,
3115 * 0 - ON
3116 * 1 - FLASHING
3117 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003118 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003119 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
3120 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
3121 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003122 }
3123
Sanket Padawe356d7632015-06-22 14:03:32 -07003124 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003125 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
3126 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003127 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003128 mApp, subId, callingPackage, callingFeatureId,
3129 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003130 return -1;
3131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132
3133 final long identity = Binder.clearCallingIdentity();
3134 try {
3135 final Phone phone = getPhone(subId);
3136 if (phone != null) {
3137 return phone.getCdmaEriIconMode();
3138 } else {
3139 return -1;
3140 }
3141 } finally {
3142 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003143 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003144 }
3145
3146 /**
3147 * Returns the CDMA ERI text,
3148 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003149 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003150 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
3151 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
3152 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07003153 }
3154
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003156 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
3157 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003159 mApp, subId, callingPackage, callingFeatureId,
3160 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07003161 return null;
3162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163
3164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 final Phone phone = getPhone(subId);
3167 if (phone != null) {
3168 return phone.getCdmaEriText();
3169 } else {
3170 return null;
3171 }
3172 } finally {
3173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003175 }
3176
3177 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07003178 * Returns the CDMA MDN.
3179 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003180 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003181 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003182 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3183 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003184
3185 final long identity = Binder.clearCallingIdentity();
3186 try {
3187 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003188 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 return phone.getLine1Number();
3190 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003191 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 return null;
3193 }
3194 } finally {
3195 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003196 }
3197 }
3198
3199 /**
3200 * Returns the CDMA MIN.
3201 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003202 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07003203 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003204 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3205 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
3209 final Phone phone = getPhone(subId);
3210 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
3211 return phone.getCdmaMin();
3212 } else {
3213 return null;
3214 }
3215 } finally {
3216 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07003217 }
3218 }
3219
Hall Liud892bec2018-11-30 14:51:45 -08003220 @Override
3221 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
3222 INumberVerificationCallback callback, String callingPackage) {
3223 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
3224 != PERMISSION_GRANTED) {
3225 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
3226 }
3227 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
3228
3229 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
3230 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
3231 throw new SecurityException("Calling package must be configured in the device config");
3232 }
3233
3234 if (range == null) {
3235 throw new NullPointerException("Range must be non-null");
3236 }
3237
3238 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08003239 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08003240
3241 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
3242 }
3243
Junda Liuca05d5d2014-08-14 22:36:34 -07003244 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003245 * Returns true if CDMA provisioning needs to run.
3246 */
3247 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003248 final long identity = Binder.clearCallingIdentity();
3249 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003250 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003254 }
3255
3256 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003257 * Sets the voice mail number of a given subId.
3258 */
3259 @Override
3260 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08003261 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
3262 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003263
3264 final long identity = Binder.clearCallingIdentity();
3265 try {
3266 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
3267 new Pair<String, String>(alphaTag, number), new Integer(subId));
3268 return success;
3269 } finally {
3270 Binder.restoreCallingIdentity(identity);
3271 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003272 }
3273
Ta-wei Yen87c49842016-05-13 21:19:52 -07003274 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003275 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
3276 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003277 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
3278 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003279 if (!TextUtils.equals(callingPackage, systemDialer)) {
3280 throw new SecurityException("caller must be system dialer");
3281 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003282
3283 final long identity = Binder.clearCallingIdentity();
3284 try {
3285 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3286 if (phoneAccountHandle == null) {
3287 return null;
3288 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003290 } finally {
3291 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003292 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003293 }
3294
3295 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003296 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3297 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003298 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003300 mApp, subId, callingPackage, callingFeatureId,
3301 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003302 return null;
3303 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003304
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003305 final long identity = Binder.clearCallingIdentity();
3306 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003307 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003308 } finally {
3309 Binder.restoreCallingIdentity(identity);
3310 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003311 }
3312
3313 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003314 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3315 VisualVoicemailSmsFilterSettings settings) {
3316 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003317
3318 final long identity = Binder.clearCallingIdentity();
3319 try {
3320 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003321 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003322 } finally {
3323 Binder.restoreCallingIdentity(identity);
3324 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003325 }
3326
3327 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003328 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3329 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003330
3331 final long identity = Binder.clearCallingIdentity();
3332 try {
3333 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003334 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003335 } finally {
3336 Binder.restoreCallingIdentity(identity);
3337 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003338 }
3339
3340 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003341 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3342 String callingPackage, int subId) {
3343 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003344
3345 final long identity = Binder.clearCallingIdentity();
3346 try {
3347 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003348 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003349 } finally {
3350 Binder.restoreCallingIdentity(identity);
3351 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003352 }
3353
3354 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003355 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003356 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003357
3358 final long identity = Binder.clearCallingIdentity();
3359 try {
3360 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003361 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003362 } finally {
3363 Binder.restoreCallingIdentity(identity);
3364 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003365 }
3366
3367 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003368 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3369 String callingAttributionTag, int subId, String number, int port, String text,
3370 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003371 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003372 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003373 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003374 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003375 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3376 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003377 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003378
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003379 /**
fionaxu0152e512016-11-14 13:36:14 -08003380 * Sets the voice activation state of a given subId.
3381 */
3382 @Override
3383 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003384 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3385 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003386
3387 final long identity = Binder.clearCallingIdentity();
3388 try {
3389 final Phone phone = getPhone(subId);
3390 if (phone != null) {
3391 phone.setVoiceActivationState(activationState);
3392 } else {
3393 loge("setVoiceActivationState fails with invalid subId: " + subId);
3394 }
3395 } finally {
3396 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003397 }
3398 }
3399
3400 /**
3401 * Sets the data activation state of a given subId.
3402 */
3403 @Override
3404 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003405 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3406 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003407
3408 final long identity = Binder.clearCallingIdentity();
3409 try {
3410 final Phone phone = getPhone(subId);
3411 if (phone != null) {
3412 phone.setDataActivationState(activationState);
3413 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003414 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003415 }
3416 } finally {
3417 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003418 }
3419 }
3420
3421 /**
3422 * Returns the voice activation state of a given subId.
3423 */
3424 @Override
3425 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003426 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003427
fionaxu0152e512016-11-14 13:36:14 -08003428 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003429 final long identity = Binder.clearCallingIdentity();
3430 try {
3431 if (phone != null) {
3432 return phone.getVoiceActivationState();
3433 } else {
3434 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3435 }
3436 } finally {
3437 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003438 }
3439 }
3440
3441 /**
3442 * Returns the data activation state of a given subId.
3443 */
3444 @Override
3445 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003447
fionaxu0152e512016-11-14 13:36:14 -08003448 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003449 final long identity = Binder.clearCallingIdentity();
3450 try {
3451 if (phone != null) {
3452 return phone.getDataActivationState();
3453 } else {
3454 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3455 }
3456 } finally {
3457 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003458 }
3459 }
3460
3461 /**
Wink Saville36469e72014-06-11 15:17:00 -07003462 * Returns the unread count of voicemails for a subId
3463 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003464 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003465 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3466 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003467 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003468 mApp, subId, callingPackage, callingFeatureId,
3469 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003470 return 0;
3471 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003472 final long identity = Binder.clearCallingIdentity();
3473 try {
3474 final Phone phone = getPhone(subId);
3475 if (phone != null) {
3476 return phone.getVoiceMessageCount();
3477 } else {
3478 return 0;
3479 }
3480 } finally {
3481 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003482 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003483 }
3484
3485 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003486 * returns true, if the device is in a state where both voice and data
3487 * are supported simultaneously. This can change based on location or network condition.
3488 */
3489 @Override
3490 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003491 final long identity = Binder.clearCallingIdentity();
3492 try {
3493 final Phone phone = getPhone(subId);
3494 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3495 } finally {
3496 Binder.restoreCallingIdentity(identity);
3497 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003498 }
3499
3500 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003501 * Send the dialer code if called from the current default dialer or the caller has
3502 * carrier privilege.
3503 * @param inputCode The dialer code to send
3504 */
3505 @Override
3506 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003507 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003508 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003509 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3510 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003511 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003512 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003513 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003514 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003515
3516 final long identity = Binder.clearCallingIdentity();
3517 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003518 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003519 } finally {
3520 Binder.restoreCallingIdentity(identity);
3521 }
fionaxu235cc5e2017-03-06 22:25:57 -08003522 }
3523
Pengquan Menga1bb6272018-09-06 09:59:22 -07003524 @Override
3525 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003526 TelephonyPermissions
3527 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3528 mApp, subId, "getNetworkSelectionMode");
3529 final long identity = Binder.clearCallingIdentity();
3530 try {
3531 if (!isActiveSubscription(subId)) {
3532 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3533 }
3534 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3535 } finally {
3536 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003537 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003538 }
3539
Brad Ebinger35c841c2018-10-01 10:40:55 -07003540 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003541 public boolean isInEmergencySmsMode() {
3542 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3543 final long identity = Binder.clearCallingIdentity();
3544 try {
3545 for (Phone phone : PhoneFactory.getPhones()) {
3546 if (phone.isInEmergencySmsMode()) {
3547 return true;
3548 }
3549 }
3550 } finally {
3551 Binder.restoreCallingIdentity(identity);
3552 }
3553 return false;
3554 }
3555
shilu366312e2019-12-17 09:28:10 -08003556 /**
3557 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3558 * @param subId The subscription to use to check the configuration.
3559 * @param c The callback that will be used to send the result.
3560 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003561 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003562 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3563 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003564 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3565 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003566
Brad Ebinger77b832e2019-10-17 17:03:22 -07003567 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3568 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3569 "IMS not available on device.");
3570 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003571 final long token = Binder.clearCallingIdentity();
3572 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003573 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003574 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003576 } catch (ImsException e) {
3577 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 } finally {
3579 Binder.restoreCallingIdentity(token);
3580 }
3581 }
3582
shilu366312e2019-12-17 09:28:10 -08003583 /**
3584 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3585 * @param subId The subscription to use to check the configuration.
3586 * @param c The callback that will be used to send the result.
3587 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003589 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003590 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3591 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003592 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3593 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3594 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003595 final long token = Binder.clearCallingIdentity();
3596 try {
3597 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3598 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3599 .removeRegistrationCallbackForSubscription(c, subId);
3600 } catch (ImsException e) {
3601 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3602 + "is inactive, ignoring unregister.");
3603 // If the subscription is no longer active, just return, since the callback
3604 // will already have been removed internally.
3605 } finally {
3606 Binder.restoreCallingIdentity(token);
3607 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 }
3609
Brad Ebinger774ba362019-10-22 17:36:18 -07003610 /**
3611 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3612 */
3613 @Override
3614 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3615 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3616 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3617 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3618 "IMS not available on device.");
3619 }
3620 final long token = Binder.clearCallingIdentity();
3621 try {
3622 Phone phone = getPhone(subId);
3623 if (phone == null) {
3624 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3625 + subId + "'");
3626 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3627 }
3628 phone.getImsRegistrationState(regState -> {
3629 try {
3630 consumer.accept((regState == null)
3631 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3632 } catch (RemoteException e) {
3633 // Ignore if the remote process is no longer available to call back.
3634 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3635 }
3636 });
3637 } finally {
3638 Binder.restoreCallingIdentity(token);
3639 }
3640 }
3641
3642 /**
3643 * Get the transport type for the IMS service registration state.
3644 */
3645 @Override
3646 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003647 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3648 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003649 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3650 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3651 "IMS not available on device.");
3652 }
3653 final long token = Binder.clearCallingIdentity();
3654 try {
3655 Phone phone = getPhone(subId);
3656 if (phone == null) {
3657 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3658 + subId + "'");
3659 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3660 }
3661 phone.getImsRegistrationTech(regTech -> {
3662 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3663 int regTechConverted = (regTech == null)
3664 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3665 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3666 regTechConverted);
3667 try {
3668 consumer.accept(regTechConverted);
3669 } catch (RemoteException e) {
3670 // Ignore if the remote process is no longer available to call back.
3671 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3672 }
3673 });
3674 } finally {
3675 Binder.restoreCallingIdentity(token);
3676 }
3677 }
3678
shilu366312e2019-12-17 09:28:10 -08003679 /**
3680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3681 * @param subId The subscription to use to check the configuration.
3682 * @param c The callback that will be used to send the result.
3683 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003684 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003685 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3686 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003687 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3688 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003689 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3690 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3691 "IMS not available on device.");
3692 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3694 final long token = Binder.clearCallingIdentity();
3695 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003696 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003697 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003698 } catch (ImsException e) {
3699 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003700 } finally {
3701 Binder.restoreCallingIdentity(token);
3702 }
3703 }
3704
shilu366312e2019-12-17 09:28:10 -08003705 /**
3706 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3707 * @param subId The subscription to use to check the configuration.
3708 * @param c The callback that will be used to send the result.
3709 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003711 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003712 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3713 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003714 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3715 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3716 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003717
3718 final long token = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3721 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003722 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003723 } catch (ImsException e) {
3724 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3725 + "is inactive, ignoring unregister.");
3726 // If the subscription is no longer active, just return, since the callback
3727 // will already have been removed internally.
3728 } finally {
3729 Binder.restoreCallingIdentity(token);
3730 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003731 }
3732
3733 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003734 public boolean isCapable(int subId, int capability, int regTech) {
3735 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3737 final long token = Binder.clearCallingIdentity();
3738 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3743 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003744 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003745 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3746 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 } finally {
3748 Binder.restoreCallingIdentity(token);
3749 }
3750 }
3751
3752 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003753 public boolean isAvailable(int subId, int capability, int regTech) {
3754 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 final long token = Binder.clearCallingIdentity();
3756 try {
3757 Phone phone = getPhone(subId);
3758 if (phone == null) return false;
3759 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003760 } catch (com.android.ims.ImsException e) {
3761 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3762 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003763 } finally {
3764 Binder.restoreCallingIdentity(token);
3765 }
3766 }
3767
Brad Ebinger77b832e2019-10-17 17:03:22 -07003768 /**
3769 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3770 * subscription.
3771 * @param subId The subscription to use to check the configuration.
3772 * @param callback The callback that will be used to send the result.
3773 * @param capability The MmTelFeature capability that will be used to send the result.
3774 * @param transportType The transport type of the MmTelFeature capability.
3775 */
3776 @Override
3777 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3778 int transportType) {
3779 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3780 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3781 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3782 "IMS not available on device.");
3783 }
3784 final long token = Binder.clearCallingIdentity();
3785 try {
3786 int slotId = getSlotIndex(subId);
3787 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3788 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3789 + subId + "'");
3790 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3791 }
3792 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3793 transportType, aBoolean -> {
3794 try {
3795 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3796 } catch (RemoteException e) {
3797 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3798 + "running. Ignore");
3799 }
3800 });
3801 } finally {
3802 Binder.restoreCallingIdentity(token);
3803 }
3804 }
3805
shilu366312e2019-12-17 09:28:10 -08003806 /**
3807 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3808 * @param subId The subscription to use to check the configuration.
3809 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003810 @Override
3811 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003812 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3813 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003814
Brad Ebinger35c841c2018-10-01 10:40:55 -07003815 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3816 final long token = Binder.clearCallingIdentity();
3817 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003818 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003819 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003820 } catch (ImsException e) {
3821 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003822 } finally {
3823 Binder.restoreCallingIdentity(token);
3824 }
3825 }
3826
3827 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003828 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003829 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003830 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003831 final long identity = Binder.clearCallingIdentity();
3832 try {
3833 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003834 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003835 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003836 } catch (ImsException e) {
3837 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003838 } finally {
3839 Binder.restoreCallingIdentity(identity);
3840 }
3841 }
3842
shilu366312e2019-12-17 09:28:10 -08003843 /**
3844 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3845 * @param subId The subscription to use to check the configuration.
3846 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003847 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003848 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003849 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3850 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003854 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3855 } catch (ImsException e) {
3856 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860 }
3861
3862 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003863 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003864 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003865 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003866 final long identity = Binder.clearCallingIdentity();
3867 try {
3868 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003869 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003870 } catch (ImsException e) {
3871 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003872 } finally {
3873 Binder.restoreCallingIdentity(identity);
3874 }
3875 }
3876
shilu366312e2019-12-17 09:28:10 -08003877 /**
3878 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3879 * @param subId The subscription to use to check the configuration.
3880 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003881 @Override
3882 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003883 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3884 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003885 final long identity = Binder.clearCallingIdentity();
3886 try {
3887 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003888 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003889 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003890 } catch (ImsException e) {
3891 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003892 } finally {
3893 Binder.restoreCallingIdentity(identity);
3894 }
3895 }
3896
3897 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003898 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003900 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003901 final long identity = Binder.clearCallingIdentity();
3902 try {
3903 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003904 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003905 } catch (ImsException e) {
3906 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003907 } finally {
3908 Binder.restoreCallingIdentity(identity);
3909 }
3910 }
3911
shilu366312e2019-12-17 09:28:10 -08003912 /**
3913 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3914 * @param subId The subscription to use to check the configuration.
3915 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003916 @Override
3917 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003918 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3919 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003920 final long identity = Binder.clearCallingIdentity();
3921 try {
3922 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003923 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003924 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003925 } catch (ImsException e) {
3926 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003927 } finally {
3928 Binder.restoreCallingIdentity(identity);
3929 }
3930 }
3931
3932 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003933 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003934 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003935 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003936 final long identity = Binder.clearCallingIdentity();
3937 try {
3938 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003939 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003940 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003941 } catch (ImsException e) {
3942 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
3946 }
3947
3948 @Override
3949 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3951 "setVoWiFiNonPersistent");
3952 final long identity = Binder.clearCallingIdentity();
3953 try {
3954 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003955 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003956 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003957 } catch (ImsException e) {
3958 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003959 } finally {
3960 Binder.restoreCallingIdentity(identity);
3961 }
3962 }
3963
shilu366312e2019-12-17 09:28:10 -08003964 /**
3965 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3966 * @param subId The subscription to use to check the configuration.
3967 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003968 @Override
3969 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003970 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3971 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003972 final long identity = Binder.clearCallingIdentity();
3973 try {
3974 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003975 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003976 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003977 } catch (ImsException e) {
3978 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003979 } finally {
3980 Binder.restoreCallingIdentity(identity);
3981 }
3982 }
3983
3984 @Override
3985 public void setVoWiFiModeSetting(int subId, int mode) {
3986 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3987 "setVoWiFiModeSetting");
3988 final long identity = Binder.clearCallingIdentity();
3989 try {
3990 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003991 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003992 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003993 } catch (ImsException e) {
3994 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003995 } finally {
3996 Binder.restoreCallingIdentity(identity);
3997 }
3998 }
3999
4000 @Override
4001 public int getVoWiFiRoamingModeSetting(int subId) {
4002 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
4003 final long identity = Binder.clearCallingIdentity();
4004 try {
4005 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004006 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004007 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004008 } catch (ImsException e) {
4009 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 }
4014
4015 @Override
4016 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
4017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4018 "setVoWiFiRoamingModeSetting");
4019 final long identity = Binder.clearCallingIdentity();
4020 try {
4021 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004022 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004023 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004024 } catch (ImsException e) {
4025 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004026 } finally {
4027 Binder.restoreCallingIdentity(identity);
4028 }
4029 }
4030
4031 @Override
4032 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setRttCapabilityEnabled");
4035 final long identity = Binder.clearCallingIdentity();
4036 try {
4037 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004038 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
4039 } catch (ImsException e) {
4040 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004041 } finally {
4042 Binder.restoreCallingIdentity(identity);
4043 }
4044 }
4045
shilu366312e2019-12-17 09:28:10 -08004046 /**
4047 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
4048 * @param subId The subscription to use to check the configuration.
4049 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07004050 @Override
4051 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08004052 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
4053 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07004054 final long identity = Binder.clearCallingIdentity();
4055 try {
4056 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004057 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07004058 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004059 } catch (ImsException e) {
4060 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07004061 } finally {
4062 Binder.restoreCallingIdentity(identity);
4063 }
4064 }
4065
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004066 @Override
4067 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4068 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
4069 final long identity = Binder.clearCallingIdentity();
4070 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08004071 if (!isImsAvailableOnDevice()) {
4072 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
4073 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08004074 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004075 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004076 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004077 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004078 } catch (ImsException e) {
4079 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004080 } finally {
4081 Binder.restoreCallingIdentity(identity);
4082 }
4083 }
4084
4085 @Override
4086 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
4087 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
4088 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004089 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4090 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
4091 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004092 try {
4093 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004094 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004095 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004096 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08004097 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
4098 + "is inactive, ignoring unregister.");
4099 // If the subscription is no longer active, just return, since the callback will already
4100 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004101 } finally {
4102 Binder.restoreCallingIdentity(identity);
4103 }
4104 }
4105
allenwtsu99c623b2020-01-03 18:24:23 +08004106
4107 private void checkModifyPhoneStatePermission(int subId, String message) {
4108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4109 message);
4110 }
4111
4112 private boolean isImsProvisioningRequired(int subId, int capability,
4113 boolean isMmtelCapability) {
4114 Phone phone = getPhone(subId);
4115 if (phone == null) {
4116 loge("phone instance null for subid " + subId);
4117 return false;
4118 }
4119 if (isMmtelCapability) {
4120 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4121 return false;
4122 }
4123 } else {
4124 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
4125 return false;
4126 }
4127 }
4128 return true;
4129 }
4130
4131 @Override
4132 public void setRcsProvisioningStatusForCapability(int subId, int capability,
4133 boolean isProvisioned) {
4134 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
4135
4136 final long identity = Binder.clearCallingIdentity();
4137 try {
4138 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4139 if (!isImsProvisioningRequired(subId, capability, false)) {
4140 return;
4141 }
4142
4143 // this capability requires provisioning, route to the correct API.
4144 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4145 switch (capability) {
4146 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4147 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4148 ims.setEabProvisioned(isProvisioned);
4149 break;
4150 default: {
4151 throw new IllegalArgumentException("Tried to set provisioning for "
4152 + "rcs capability '" + capability + "', which does not require "
4153 + "provisioning.");
4154 }
4155 }
4156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159
4160 }
4161
4162
4163 @Override
4164 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
4165 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
4166 final long identity = Binder.clearCallingIdentity();
4167 try {
4168 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
4169 if (!isImsProvisioningRequired(subId, capability, false)) {
4170 return true;
4171 }
4172
4173 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4174 switch (capability) {
4175 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
4176 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4177 return ims.isEabProvisionedOnDevice();
4178
4179 default: {
4180 throw new IllegalArgumentException("Tried to get rcs provisioning for "
4181 + "capability '" + capability + "', which does not require "
4182 + "provisioning.");
4183 }
4184 }
4185
4186 } finally {
4187 Binder.restoreCallingIdentity(identity);
4188 }
4189 }
4190
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004191 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004192 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
4193 boolean isProvisioned) {
4194 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4195 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4196 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4197 }
allenwtsu99c623b2020-01-03 18:24:23 +08004198 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004199 final long identity = Binder.clearCallingIdentity();
4200 try {
4201 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004202 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004203 return;
4204 }
4205
4206 // this capability requires provisioning, route to the correct API.
4207 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4208 switch (capability) {
4209 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4210 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4211 ims.setVolteProvisioned(isProvisioned);
4212 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4213 ims.setWfcProvisioned(isProvisioned);
4214 }
4215 break;
4216 }
4217 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4218 // There is currently no difference in VT provisioning type.
4219 ims.setVtProvisioned(isProvisioned);
4220 break;
4221 }
4222 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4223 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
4224 // change the capability of the feature instead if needed.
4225 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
4226 == isProvisioned) {
4227 // No change in provisioning.
4228 return;
4229 }
4230 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
4231 try {
4232 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004233 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004234 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
4235 + ", Exception" + e.getMessage());
4236 }
4237 break;
4238 }
4239 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004240 throw new IllegalArgumentException("Tried to set provisioning for "
4241 + "MmTel capability '" + capability + "', which does not require "
4242 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004243 }
4244 }
4245
4246 } finally {
4247 Binder.restoreCallingIdentity(identity);
4248 }
4249 }
4250
4251 @Override
4252 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
4253 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4254 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4255 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4256 }
4257 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
4258 final long identity = Binder.clearCallingIdentity();
4259 try {
4260 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08004261 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004262 return true;
4263 }
4264
4265 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
4266 switch (capability) {
4267 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
4268 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4269 return ims.isVolteProvisionedOnDevice();
4270 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
4271 return ims.isWfcProvisionedOnDevice();
4272 }
4273 // This should never happen, since we are checking tech above to make sure it
4274 // is either LTE or IWLAN.
4275 throw new IllegalArgumentException("Invalid radio technology for voice "
4276 + "capability.");
4277 }
4278 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4279 // There is currently no difference in VT provisioning type.
4280 return ims.isVtProvisionedOnDevice();
4281 }
4282 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4283 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4284 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4285 }
4286 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004287 throw new IllegalArgumentException(
4288 "Tried to get provisioning for MmTel capability '" + capability
4289 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004290 }
4291 }
4292
4293 } finally {
4294 Binder.restoreCallingIdentity(identity);
4295 }
4296 }
4297
4298 @Override
4299 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4300 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4301 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4302 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4303 }
4304 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4305 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4306 return (provisionedBits & capability) > 0;
4307 }
4308
4309 @Override
4310 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4311 boolean isProvisioned) {
4312 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4313 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4314 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4315 }
4316 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4317 "setProvisioningStatusForCapability");
4318 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4319 // If the current provisioning status for capability already matches isProvisioned,
4320 // do nothing.
4321 if (((provisionedBits & capability) > 0) == isProvisioned) {
4322 return;
4323 }
4324 if (isProvisioned) {
4325 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4326 } else {
4327 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4328 }
4329 }
4330
4331 /**
4332 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4333 * technology. The bitfield should mirror the bitfield defined by
4334 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4335 */
4336 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4337 String key = getMmTelProvisioningKey(subId, tech);
4338 // Default is no capabilities are provisioned.
4339 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4340 }
4341
4342 /**
4343 * Sets the MmTel capability provisioning bitfield (defined by
4344 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4345 * technology specified.
4346 *
4347 * Note: This is a synchronous command and should not be called on UI thread.
4348 */
4349 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4350 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4351 String key = getMmTelProvisioningKey(subId, tech);
4352 editor.putInt(key, newField);
4353 editor.commit();
4354 }
4355
4356 private static String getMmTelProvisioningKey(int subId, int tech) {
4357 // resulting key is provision_ims_mmtel_{subId}_{tech}
4358 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4359 }
4360
4361 /**
4362 * Query CarrierConfig to see if the specified capability requires provisioning for the
4363 * carrier associated with the subscription id.
4364 */
4365 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4366 int capability) {
4367 CarrierConfigManager configManager = new CarrierConfigManager(context);
4368 PersistableBundle c = configManager.getConfigForSubId(subId);
4369 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004370 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004371 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4372 false);
4373 boolean requireVoiceVtProvisioning = c.getBoolean(
4374 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4375
4376 // First check to make sure that the capability requires provisioning.
4377 switch (capability) {
4378 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4379 // intentional fallthrough
4380 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4381 if (requireVoiceVtProvisioning) {
4382 // Voice and Video requires provisioning
4383 return true;
4384 }
4385 break;
4386 }
4387 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4388 if (requireUtProvisioning) {
4389 // UT requires provisioning
4390 return true;
4391 }
4392 break;
4393 }
4394 }
4395 return false;
4396 }
4397
allenwtsu99c623b2020-01-03 18:24:23 +08004398 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4399 int capability) {
4400 CarrierConfigManager configManager = new CarrierConfigManager(context);
4401 PersistableBundle c = configManager.getConfigForSubId(subId);
4402
4403 boolean requireRcsProvisioning = c.getBoolean(
4404 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4405
4406 // First check to make sure that the capability requires provisioning.
4407 switch (capability) {
4408 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4409 // intentional fallthrough
4410 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4411 if (requireRcsProvisioning) {
4412 // OPTION or PRESENCE requires provisioning
4413 return true;
4414 }
4415 break;
4416 }
4417 }
4418 return false;
4419 }
4420
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004421 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004422 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004423 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4424 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4425 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004426 enforceReadPrivilegedPermission("getImsProvisioningInt");
4427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004430 int slotId = getSlotIndex(subId);
4431 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4432 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4433 + subId + "' for key:" + key);
4434 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4435 }
4436 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004437 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004438 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4439 + subId + "' for key:" + key);
4440 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004441 } finally {
4442 Binder.restoreCallingIdentity(identity);
4443 }
4444 }
4445
4446 @Override
4447 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004448 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4449 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4450 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004451 enforceReadPrivilegedPermission("getImsProvisioningString");
4452 final long identity = Binder.clearCallingIdentity();
4453 try {
4454 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004455 int slotId = getSlotIndex(subId);
4456 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4457 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4458 + subId + "' for key:" + key);
4459 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4460 }
4461 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004462 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004463 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4464 + subId + "' for key:" + key);
4465 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004466 } finally {
4467 Binder.restoreCallingIdentity(identity);
4468 }
4469 }
4470
4471 @Override
4472 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004473 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4474 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4475 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4477 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004478 final long identity = Binder.clearCallingIdentity();
4479 try {
4480 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004481 int slotId = getSlotIndex(subId);
4482 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4483 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4484 + subId + "' for key:" + key);
4485 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4486 }
4487 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004488 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004489 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4490 + "' for key:" + key);
4491 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004492 } finally {
4493 Binder.restoreCallingIdentity(identity);
4494 }
4495 }
4496
4497 @Override
4498 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004499 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4500 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4501 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004502 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4503 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004504 final long identity = Binder.clearCallingIdentity();
4505 try {
4506 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004507 int slotId = getSlotIndex(subId);
4508 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4509 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4510 + subId + "' for key:" + key);
4511 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4512 }
4513 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004514 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004515 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4516 + "' for key:" + key);
4517 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004518 } finally {
4519 Binder.restoreCallingIdentity(identity);
4520 }
4521 }
4522
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004523 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004524 int slotId = SubscriptionManager.getSlotIndex(subId);
4525 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004526 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4527 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004528 }
4529 return slotId;
4530 }
4531
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004532 private int getSlotIndex(int subId) {
4533 int slotId = SubscriptionManager.getSlotIndex(subId);
4534 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4535 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4536 }
4537 return slotId;
4538 }
4539
Wink Saville36469e72014-06-11 15:17:00 -07004540 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004541 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004542 */
4543 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004544 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4545 String callingFeatureId) {
Nathan Haroldf096d982020-11-18 17:18:06 -08004546 final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004547 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004548 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004549 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004550 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004551 mApp, subId, callingPackage, callingFeatureId,
4552 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004553 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4554 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004555
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004556 final long identity = Binder.clearCallingIdentity();
4557 try {
4558 final Phone phone = getPhone(subId);
4559 if (phone != null) {
4560 return phone.getServiceState().getDataNetworkType();
4561 } else {
4562 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4563 }
4564 } finally {
4565 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004566 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004567 }
4568
4569 /**
4570 * Returns the data network type
4571 */
4572 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004573 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4574 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4575 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004576 }
4577
4578 /**
4579 * Returns the data network type for a subId
4580 */
4581 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004582 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4583 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004584 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004585 mApp, subId, callingPackage, callingFeatureId,
4586 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004587 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4588 }
4589
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004590 final long identity = Binder.clearCallingIdentity();
4591 try {
4592 final Phone phone = getPhone(subId);
4593 if (phone != null) {
4594 return phone.getServiceState().getDataNetworkType();
4595 } else {
4596 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4597 }
4598 } finally {
4599 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004600 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004601 }
4602
4603 /**
Wink Saville36469e72014-06-11 15:17:00 -07004604 * Returns the Voice network type for a subId
4605 */
4606 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004607 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4608 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004609 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004610 mApp, subId, callingPackage, callingFeatureId,
4611 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004612 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4613 }
4614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 final Phone phone = getPhone(subId);
4618 if (phone != null) {
4619 return phone.getServiceState().getVoiceNetworkType();
4620 } else {
4621 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4622 }
4623 } finally {
4624 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004625 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004626 }
4627
4628 /**
4629 * @return true if a ICC card is present
4630 */
4631 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004632 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004633 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4634 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004635 }
4636
4637 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004638 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004639 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004640 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004641 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004642 final long identity = Binder.clearCallingIdentity();
4643 try {
4644 final Phone phone = PhoneFactory.getPhone(slotIndex);
4645 if (phone != null) {
4646 return phone.getIccCard().hasIccCard();
4647 } else {
4648 return false;
4649 }
4650 } finally {
4651 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004652 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004653 }
4654
4655 /**
4656 * Return if the current radio is LTE on CDMA. This
4657 * is a tri-state return value as for a period of time
4658 * the mode may be unknown.
4659 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004660 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004661 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004662 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004663 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004664 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004665 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4666 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4667 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004668 }
4669
Sanket Padawe356d7632015-06-22 14:03:32 -07004670 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004671 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4672 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004673 try {
4674 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4675 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004676 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4677 }
4678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 final Phone phone = getPhone(subId);
4682 if (phone == null) {
4683 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4684 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004685 return TelephonyProperties.lte_on_cdma_device()
4686 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004687 }
4688 } finally {
4689 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004690 }
Wink Saville36469e72014-06-11 15:17:00 -07004691 }
4692
Wink Saville36469e72014-06-11 15:17:00 -07004693 /**
4694 * {@hide}
4695 * Returns Default subId, 0 in the case of single standby.
4696 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004697 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004698 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004699 }
4700
Shishir Agrawala9f32182016-04-12 12:00:16 -07004701 private int getSlotForDefaultSubscription() {
4702 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4703 }
4704
Wink Savilleb564aae2014-10-23 10:18:09 -07004705 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004706 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004707 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004708
Pengquan Menge92a50d2018-09-21 15:54:48 -07004709 private boolean isActiveSubscription(int subId) {
4710 return mSubscriptionController.isActiveSubId(subId);
4711 }
4712
Ihab Awadf2177b72013-11-25 13:33:23 -08004713 /**
4714 * @see android.telephony.TelephonyManager.WifiCallingChoices
4715 */
4716 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004717 final long identity = Binder.clearCallingIdentity();
4718 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004719 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004720 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4721 getWhenToMakeWifiCallsDefaultPreference());
4722 } finally {
4723 Binder.restoreCallingIdentity(identity);
4724 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004725 }
4726
4727 /**
4728 * @see android.telephony.TelephonyManager.WifiCallingChoices
4729 */
4730 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004731 final long identity = Binder.clearCallingIdentity();
4732 try {
4733 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004734 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4736 } finally {
4737 Binder.restoreCallingIdentity(identity);
4738 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004739 }
4740
Sailesh Nepald1e68152013-12-12 19:08:02 -08004741 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004742 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004743 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004744 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004745
Jordan Liu4c733742019-02-28 12:03:40 -08004746 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4747 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4748 if (phoneId == -1) {
4749 throw new IllegalArgumentException("Given slot index: " + slotIndex
4750 + " does not correspond to an active phone");
4751 }
4752 return PhoneFactory.getPhone(phoneId);
4753 }
4754
Shishir Agrawal566b7612013-10-28 14:41:00 -07004755 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004756 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4757 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004758 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4759 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004760 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004761 if (DBG) {
4762 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4763 }
4764 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4765 p2);
4766 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004767
Jordan Liu4c733742019-02-28 12:03:40 -08004768
4769 @Override
4770 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4771 int slotIndex, String callingPackage, String aid, int p2) {
4772 enforceModifyPermission();
4773 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4774 if (DBG) {
4775 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4776 }
4777 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4778 callingPackage, aid, p2);
4779 }
4780
4781 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4782 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 final long identity = Binder.clearCallingIdentity();
4784 try {
4785 if (TextUtils.equals(ISDR_AID, aid)) {
4786 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004787 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4788 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 if (bestComponent == null
4790 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4791 loge("The calling package is not allowed to access ISD-R.");
4792 throw new SecurityException(
4793 "The calling package is not allowed to access ISD-R.");
4794 }
Derek Tan740e1672017-06-27 14:56:27 -07004795 }
Derek Tan740e1672017-06-27 14:56:27 -07004796
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004797 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004798 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4799 null /* workSource */);
4800 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004801 return response;
4802 } finally {
4803 Binder.restoreCallingIdentity(identity);
4804 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004805 }
4806
4807 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004808 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4810 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004811 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4812 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4813 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004814
Jordan Liu4c733742019-02-28 12:03:40 -08004815 @Override
4816 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4817 enforceModifyPermission();
4818 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4819 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4820 channel);
4821 }
4822
4823 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824 final long identity = Binder.clearCallingIdentity();
4825 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004826 if (channel < 0) {
4827 return false;
4828 }
Jordan Liu4c733742019-02-28 12:03:40 -08004829 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4830 null /* workSource */);
4831 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004832 return success;
4833 } finally {
4834 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004835 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004836 }
4837
4838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004839 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004840 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004843 if (DBG) {
4844 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4845 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4846 + p3 + " data=" + data);
4847 }
4848 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4849 command, p1, p2, p3, data);
4850 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004851
Jordan Liu4c733742019-02-28 12:03:40 -08004852 @Override
4853 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4854 int command, int p1, int p2, int p3, String data) {
4855 enforceModifyPermission();
4856 if (DBG) {
4857 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4858 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4859 + p3 + " data=" + data);
4860 }
4861 return iccTransmitApduLogicalChannelWithPermission(
4862 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4863 data);
4864 }
4865
4866 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4867 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004868 final long identity = Binder.clearCallingIdentity();
4869 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004870 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004871 return "";
4872 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004875 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4876 null /* workSource */);
4877 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004878
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879 // Append the returned status code to the end of the response payload.
4880 String s = Integer.toHexString(
4881 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4882 if (response.payload != null) {
4883 s = IccUtils.bytesToHexString(response.payload) + s;
4884 }
4885 return s;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004888 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004889 }
Jake Hambye994d462014-02-03 13:10:13 -08004890
Evan Charltonc66da362014-05-16 14:06:40 -07004891 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004892 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4893 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004894 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4895 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004896 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004897 if (DBG) {
4898 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4899 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4900 }
4901 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4902 cla, command, p1, p2, p3, data);
4903 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004904
Jordan Liu4c733742019-02-28 12:03:40 -08004905 @Override
4906 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4907 int command, int p1, int p2, int p3, String data) {
4908 enforceModifyPermission();
4909 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4910 if (DBG) {
4911 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4912 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4913 + " data=" + data);
4914 }
4915
4916 return iccTransmitApduBasicChannelWithPermission(
4917 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4918 p2, p3, data);
4919 }
4920
4921 // open APDU basic channel assuming the caller has sufficient permissions
4922 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4923 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 final long identity = Binder.clearCallingIdentity();
4925 try {
4926 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4927 && TextUtils.equals(ISDR_AID, data)) {
4928 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4930 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004931 if (bestComponent == null
4932 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4933 loge("The calling package is not allowed to select ISD-R.");
4934 throw new SecurityException(
4935 "The calling package is not allowed to select ISD-R.");
4936 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004937 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004938
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004939 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004940 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4941 null /* workSource */);
4942 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004943
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004944 // Append the returned status code to the end of the response payload.
4945 String s = Integer.toHexString(
4946 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4947 if (response.payload != null) {
4948 s = IccUtils.bytesToHexString(response.payload) + s;
4949 }
4950 return s;
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004953 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004954 }
4955
4956 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004957 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004958 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004959 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4960 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004961
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962 final long identity = Binder.clearCallingIdentity();
4963 try {
4964 if (DBG) {
4965 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4966 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4967 }
4968
4969 IccIoResult response =
4970 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4971 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4972 subId);
4973
4974 if (DBG) {
4975 log("Exchange SIM_IO [R]" + response);
4976 }
4977
4978 byte[] result = null;
4979 int length = 2;
4980 if (response.payload != null) {
4981 length = 2 + response.payload.length;
4982 result = new byte[length];
4983 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4984 } else {
4985 result = new byte[length];
4986 }
4987
4988 result[length - 1] = (byte) response.sw2;
4989 result[length - 2] = (byte) response.sw1;
4990 return result;
4991 } finally {
4992 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004993 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004994 }
4995
Nathan Haroldb3014052017-01-25 15:57:32 -08004996 /**
4997 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4998 * on a particular subscription
4999 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005000 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
5001 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07005002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005003 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07005004 return null;
5005 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005006
5007 final long identity = Binder.clearCallingIdentity();
5008 try {
5009 if (appType != TelephonyManager.APPTYPE_USIM
5010 && appType != TelephonyManager.APPTYPE_SIM) {
5011 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
5012 return null;
5013 }
5014 Object response = sendRequest(
5015 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
5016 if (response instanceof String[]) {
5017 return (String[]) response;
5018 }
yincheng zhaod698b842019-09-06 17:06:54 -07005019 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08005021 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022 } finally {
5023 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08005024 }
Nathan Haroldb3014052017-01-25 15:57:32 -08005025 }
5026
yincheng zhaod698b842019-09-06 17:06:54 -07005027 /**
5028 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
5029 * subscription.
5030 *
5031 * @param subId the id of the subscription.
5032 * @param appType the uicc app type, must be USIM or SIM.
5033 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
5034 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005035 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07005036 * @return number of fplmns that is successfully written to the SIM.
5037 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005038 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
5039 String callingFeatureId) {
5040 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
5041 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07005042 if (DBG) logv("no permissions for setForbiddenplmns");
5043 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
5044 }
5045 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
5046 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
5047 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
5048 }
5049 if (fplmns == null) {
5050 throw new IllegalArgumentException("Fplmn List provided is null");
5051 }
5052 for (String fplmn : fplmns) {
5053 if (!CellIdentity.isValidPlmn(fplmn)) {
5054 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
5055 }
5056 }
5057 final long identity = Binder.clearCallingIdentity();
5058 try {
5059 Object response = sendRequest(
5060 CMD_SET_FORBIDDEN_PLMNS,
5061 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
5062 subId);
5063 return (int) response;
5064 } finally {
5065 Binder.restoreCallingIdentity(identity);
5066 }
5067 }
5068
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07005069 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005070 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005071 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5072 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07005073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 final long identity = Binder.clearCallingIdentity();
5075 try {
5076 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
5077 if (response.payload == null) {
5078 return "";
5079 }
Evan Charltonc66da362014-05-16 14:06:40 -07005080
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 // Append the returned status code to the end of the response payload.
5082 String s = Integer.toHexString(
5083 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
5084 s = IccUtils.bytesToHexString(response.payload) + s;
5085 return s;
5086 } finally {
5087 Binder.restoreCallingIdentity(identity);
5088 }
Evan Charltonc66da362014-05-16 14:06:40 -07005089 }
5090
Jake Hambye994d462014-02-03 13:10:13 -08005091 /**
5092 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5093 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5094 *
5095 * @param itemID the ID of the item to read
5096 * @return the NV item as a String, or null on error.
5097 */
5098 @Override
5099 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005100 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5102 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103
5104 final long identity = Binder.clearCallingIdentity();
5105 try {
5106 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07005107 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
5109 return value;
5110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
Jake Hambye994d462014-02-03 13:10:13 -08005113 }
5114
5115 /**
5116 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
5117 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
5118 *
5119 * @param itemID the ID of the item to read
5120 * @param itemValue the value to write, as a String
5121 * @return true on success; false on any failure
5122 */
5123 @Override
5124 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07005125 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08005126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5127 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005128
5129 final long identity = Binder.clearCallingIdentity();
5130 try {
5131 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
5132 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07005133 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005134 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
5135 return success;
5136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Jake Hambye994d462014-02-03 13:10:13 -08005139 }
5140
5141 /**
5142 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
5143 * Used for device configuration by some CDMA operators.
5144 *
5145 * @param preferredRoamingList byte array containing the new PRL
5146 * @return true on success; false on any failure
5147 */
5148 @Override
5149 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005150 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5151 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152
5153 final long identity = Binder.clearCallingIdentity();
5154 try {
5155 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
5156 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
5157 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
5158 return success;
5159 } finally {
5160 Binder.restoreCallingIdentity(identity);
5161 }
Jake Hambye994d462014-02-03 13:10:13 -08005162 }
5163
5164 /**
chen xu6dac5ab2018-10-26 17:39:23 -07005165 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08005166 * Used for device configuration by some CDMA operators.
5167 *
chen xu6dac5ab2018-10-26 17:39:23 -07005168 * @param slotIndex - device slot.
5169 *
Jake Hambye994d462014-02-03 13:10:13 -08005170 * @return true on success; false on any failure
5171 */
5172 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07005173 public boolean resetModemConfig(int slotIndex) {
5174 Phone phone = PhoneFactory.getPhone(slotIndex);
5175 if (phone != null) {
5176 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5177 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005178
chen xu6dac5ab2018-10-26 17:39:23 -07005179 final long identity = Binder.clearCallingIdentity();
5180 try {
5181 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
5182 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
5183 return success;
5184 } finally {
5185 Binder.restoreCallingIdentity(identity);
5186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187 }
chen xu6dac5ab2018-10-26 17:39:23 -07005188 return false;
5189 }
5190
5191 /**
5192 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
5193 *
5194 * @param slotIndex - device slot.
5195 *
5196 * @return true on success; false on any failure
5197 */
5198 @Override
5199 public boolean rebootModem(int slotIndex) {
5200 Phone phone = PhoneFactory.getPhone(slotIndex);
5201 if (phone != null) {
5202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5203 mApp, phone.getSubId(), "rebootModem");
5204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
5207 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
5208 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
5209 return success;
5210 } finally {
5211 Binder.restoreCallingIdentity(identity);
5212 }
5213 }
5214 return false;
Jake Hambye994d462014-02-03 13:10:13 -08005215 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005216
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005217 public String[] getPcscfAddress(String apnType, String callingPackage,
5218 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005219 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005220 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
5221 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005222 return new String[0];
5223 }
5224
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225 final long identity = Binder.clearCallingIdentity();
5226 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005227 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005228 } finally {
5229 Binder.restoreCallingIdentity(identity);
5230 }
Wink Saville36469e72014-06-11 15:17:00 -07005231 }
5232
Brad Ebinger51f743a2017-01-23 13:50:20 -08005233 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08005234 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
5235 * {@link #disableIms(int)}.
5236 * @param slotIndex device slot.
5237 */
5238 public void resetIms(int slotIndex) {
5239 enforceModifyPermission();
5240
5241 final long identity = Binder.clearCallingIdentity();
5242 try {
5243 if (mImsResolver == null) {
5244 // may happen if the does not support IMS.
5245 return;
5246 }
5247 mImsResolver.disableIms(slotIndex);
5248 mImsResolver.enableIms(slotIndex);
5249 } finally {
5250 Binder.restoreCallingIdentity(identity);
5251 }
5252 }
5253
5254 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005255 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
5256 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08005257 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005258 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08005259 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005260
5261 final long identity = Binder.clearCallingIdentity();
5262 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005263 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005264 // may happen if the device does not support IMS.
5265 return;
5266 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005267 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005271 }
5272
5273 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005274 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
5275 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08005276 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005277 public void disableIms(int slotId) {
5278 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005279
5280 final long identity = Binder.clearCallingIdentity();
5281 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005282 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005283 // may happen if the device does not support IMS.
5284 return;
5285 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005286 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005290 }
5291
5292 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005293 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5294 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005295 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005296 @Override
Brad Ebinger6366ce92020-10-01 13:51:05 -07005297 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005298 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005299
5300 final long identity = Binder.clearCallingIdentity();
5301 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005302 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005303 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5304 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005305 }
Brad Ebinger6366ce92020-10-01 13:51:05 -07005306 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307 } finally {
5308 Binder.restoreCallingIdentity(identity);
5309 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005310 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005311 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005312 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5313 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005314 @Override
5315 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005316 enforceModifyPermission();
5317
5318 final long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005321 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005322 } finally {
5323 Binder.restoreCallingIdentity(identity);
5324 }
5325 }
5326
5327 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005328 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005329 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005330 */
5331 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5332 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333
5334 final long identity = Binder.clearCallingIdentity();
5335 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005336 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005337 // may happen if the device does not support IMS.
5338 return null;
5339 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005340 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005341 } finally {
5342 Binder.restoreCallingIdentity(identity);
5343 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005344 }
5345
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005346 /**
5347 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005348 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005349 */
5350 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5351 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005352
5353 final long identity = Binder.clearCallingIdentity();
5354 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005355 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005356 // may happen if the device does not support IMS.
5357 return null;
5358 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005359 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005360 } finally {
5361 Binder.restoreCallingIdentity(identity);
5362 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005363 }
5364
Brad Ebinger884c07b2018-02-15 16:17:40 -08005365 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005366 * Sets the ImsService Package Name that Telephony will bind to.
5367 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005368 * @param slotIndex the slot ID that the ImsService should bind for.
5369 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005370 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005371 * @param featureTypes An integer array of feature types associated with a packageName.
5372 * @param packageName The name of the package that the current configuration will be replaced
5373 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005374 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005375 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005376 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5377 int[] featureTypes, String packageName) {
5378 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5379 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005380 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5381 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005382 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005383
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005384 final long identity = Binder.clearCallingIdentity();
5385 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005386 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005387 // may happen if the device does not support IMS.
5388 return false;
5389 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005390 Map<Integer, String> featureConfig = new HashMap<>();
5391 for (int featureType : featureTypes) {
5392 featureConfig.put(featureType, packageName);
5393 }
5394 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5395 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005396 } finally {
5397 Binder.restoreCallingIdentity(identity);
5398 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005399 }
5400
5401 /**
Brad Ebinger999d3302020-11-25 14:31:39 -08005402 * Clears any carrier ImsService overrides for the slot index specified that were previously
5403 * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}.
5404 *
5405 * This should only be used for testing.
5406 *
5407 * @param slotIndex the slot ID that the ImsService should bind for.
5408 * @return true if clearing the carrier ImsService override succeeded or false if it did not.
5409 */
5410 @Override
5411 public boolean clearCarrierImsServiceOverride(int slotIndex) {
5412 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5413 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
5414 "clearCarrierImsServiceOverride");
5415 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5416 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5417 "clearCarrierImsServiceOverride");
5418
5419 final long identity = Binder.clearCallingIdentity();
5420 try {
5421 if (mImsResolver == null) {
5422 // may happen if the device does not support IMS.
5423 return false;
5424 }
5425 return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex);
5426 } finally {
5427 Binder.restoreCallingIdentity(identity);
5428 }
5429 }
5430
5431 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005432 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005433 *
5434 * @param slotId The slot that the ImsService is associated with.
5435 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5436 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005437 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005438 * @return the package name of the ImsService configuration.
5439 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005440 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5441 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005442 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005443 TelephonyPermissions
5444 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5445 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5446 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005447
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 final long identity = Binder.clearCallingIdentity();
5449 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005450 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005451 // may happen if the device does not support IMS.
5452 return "";
5453 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005454 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005455 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5456 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 } finally {
5458 Binder.restoreCallingIdentity(identity);
5459 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005460 }
5461
Brad Ebinger77b832e2019-10-17 17:03:22 -07005462 /**
5463 * Get the MmTelFeature state associated with the requested subscription id.
5464 * @param subId The subscription that the MmTelFeature is associated with.
5465 * @param callback A callback with an integer containing the
5466 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5467 */
5468 @Override
5469 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5470 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5471 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5472 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5473 "IMS not available on device.");
5474 }
5475 final long token = Binder.clearCallingIdentity();
5476 try {
5477 int slotId = getSlotIndex(subId);
5478 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5479 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5480 + subId + "'");
5481 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5482 }
5483 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5484 try {
5485 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5486 } catch (RemoteException e) {
5487 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5488 + "Ignore");
5489 }
5490 });
5491 } finally {
5492 Binder.restoreCallingIdentity(token);
5493 }
5494 }
5495
Wink Saville36469e72014-06-11 15:17:00 -07005496 public void setImsRegistrationState(boolean registered) {
5497 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005498
5499 final long identity = Binder.clearCallingIdentity();
5500 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005501 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 } finally {
5503 Binder.restoreCallingIdentity(identity);
5504 }
Wink Saville36469e72014-06-11 15:17:00 -07005505 }
5506
5507 /**
Stuart Scott54788802015-03-30 13:18:01 -07005508 * Set the network selection mode to automatic.
5509 *
5510 */
5511 @Override
5512 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005513 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5514 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005515
5516 final long identity = Binder.clearCallingIdentity();
5517 try {
shilufc958392020-01-20 11:36:01 -08005518 if (!isActiveSubscription(subId)) {
5519 return;
5520 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005521 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5522 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5523 } finally {
5524 Binder.restoreCallingIdentity(identity);
5525 }
Stuart Scott54788802015-03-30 13:18:01 -07005526 }
5527
Jack Yud10cdd42020-09-28 20:28:01 -07005528 /**
Pengquan Mengea84e042018-09-20 14:57:26 -07005529 * Ask the radio to connect to the input network and change selection mode to manual.
5530 *
5531 * @param subId the id of the subscription.
5532 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5533 * the operator to attach to.
5534 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5535 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5536 * normal network selection next time.
5537 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005538 */
5539 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005540 public boolean setNetworkSelectionModeManual(
5541 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5543 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005544
5545 if (!isActiveSubscription(subId)) {
5546 return false;
5547 }
5548
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005549 final long identity = Binder.clearCallingIdentity();
5550 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005551 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005552 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005553 if (DBG) {
5554 log("setNetworkSelectionModeManual: subId: " + subId
5555 + " operator: " + operatorInfo);
5556 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005557 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5558 } finally {
5559 Binder.restoreCallingIdentity(identity);
5560 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005561 }
shilu84f6e8b2019-12-19 13:58:01 -08005562 /**
5563 * Get the manual network selection
5564 *
5565 * @param subId the id of the subscription.
5566 *
5567 * @return the previously saved user selected PLMN
5568 */
5569 @Override
5570 public String getManualNetworkSelectionPlmn(int subId) {
5571 TelephonyPermissions
5572 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5573 mApp, subId, "getManualNetworkSelectionPlmn");
5574
5575 final long identity = Binder.clearCallingIdentity();
5576 try {
5577 if (!isActiveSubscription(subId)) {
5578 return "";
5579 }
5580
5581 final Phone phone = getPhone(subId);
5582 if (phone == null) {
5583 return "";
5584 }
5585 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5586 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5587 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5588 } finally {
5589 Binder.restoreCallingIdentity(identity);
5590 }
5591 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005592
5593 /**
5594 * Scans for available networks.
5595 */
5596 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005597 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5598 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005599 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5600 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005601 LocationAccessPolicy.LocationPermissionResult locationResult =
5602 LocationAccessPolicy.checkLocationPermission(mApp,
5603 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5604 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005605 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005606 .setCallingPid(Binder.getCallingPid())
5607 .setCallingUid(Binder.getCallingUid())
5608 .setMethod("getCellNetworkScanResults")
5609 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5610 .build());
5611 switch (locationResult) {
5612 case DENIED_HARD:
5613 throw new SecurityException("Not allowed to access scan results -- location");
5614 case DENIED_SOFT:
5615 return null;
5616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005617
Pengquan Menga1bb6272018-09-06 09:59:22 -07005618 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 try {
5620 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005621 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005622 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005623 } finally {
5624 Binder.restoreCallingIdentity(identity);
5625 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005626 }
5627
5628 /**
sqian80370722020-01-29 15:02:51 -08005629 * Get the call forwarding info, given the call forwarding reason.
5630 */
5631 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005632 public void getCallForwarding(int subId, int callForwardingReason,
5633 ICallForwardingInfoCallback callback) {
sqian80370722020-01-29 15:02:51 -08005634 enforceReadPrivilegedPermission("getCallForwarding");
5635 long identity = Binder.clearCallingIdentity();
5636 try {
5637 if (DBG) {
5638 log("getCallForwarding: subId " + subId
5639 + " callForwardingReason" + callForwardingReason);
5640 }
Hall Liua1acea22020-09-18 19:04:59 -07005641
5642 Phone phone = getPhone(subId);
5643 if (phone == null) {
5644 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005645 callback.onError(
5646 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005647 } catch (RemoteException e) {
5648 // ignore
5649 }
5650 return;
5651 }
5652
5653 Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create(
5654 callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() {
5655 @Override
5656 public void onCallForwardingInfoAvailable(CallForwardingInfo info) {
5657 try {
5658 callback.onCallForwardingInfoAvailable(info);
5659 } catch (RemoteException e) {
5660 // ignore
5661 }
5662 }
5663
5664 @Override
5665 public void onError(int error) {
5666 try {
5667 callback.onError(error);
5668 } catch (RemoteException e) {
5669 // ignore
5670 }
5671 }
5672 });
5673 sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005674 } finally {
5675 Binder.restoreCallingIdentity(identity);
5676 }
5677 }
5678
5679 /**
5680 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5681 * reason, the number to forward, and the timeout before the forwarding is attempted.
5682 */
5683 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005684 public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo,
5685 IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005686 enforceModifyPermission();
5687 long identity = Binder.clearCallingIdentity();
5688 try {
5689 if (DBG) {
5690 log("setCallForwarding: subId " + subId
5691 + " callForwardingInfo" + callForwardingInfo);
5692 }
Hall Liua1acea22020-09-18 19:04:59 -07005693
5694 Phone phone = getPhone(subId);
5695 if (phone == null) {
5696 try {
Hall Liuae527aa2020-09-29 17:10:18 -07005697 callback.accept(
5698 TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN);
Hall Liua1acea22020-09-18 19:04:59 -07005699 } catch (RemoteException e) {
5700 // ignore
5701 }
5702 return;
5703 }
5704
5705 Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo,
5706 FunctionalUtils.ignoreRemoteException(callback::accept));
5707
5708 sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
5714 /**
Hall Liua1acea22020-09-18 19:04:59 -07005715 * Get the call waiting status for a subId.
sqian80370722020-01-29 15:02:51 -08005716 */
5717 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005718 public void getCallWaitingStatus(int subId, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005719 enforceReadPrivilegedPermission("getCallForwarding");
5720 long identity = Binder.clearCallingIdentity();
5721 try {
Hall Liua1acea22020-09-18 19:04:59 -07005722
5723 Phone phone = getPhone(subId);
5724 if (phone == null) {
5725 try {
5726 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5727 } catch (RemoteException e) {
5728 // ignore
5729 }
5730 return;
5731 }
5732
5733 Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept);
5734
sqian80370722020-01-29 15:02:51 -08005735 if (DBG) log("getCallWaitingStatus: subId " + subId);
Hall Liua1acea22020-09-18 19:04:59 -07005736 sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null);
sqian80370722020-01-29 15:02:51 -08005737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
Hall Liua1acea22020-09-18 19:04:59 -07005743 * Sets whether call waiting is enabled for a given subId.
sqian80370722020-01-29 15:02:51 -08005744 */
5745 @Override
Hall Liua1acea22020-09-18 19:04:59 -07005746 public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) {
sqian80370722020-01-29 15:02:51 -08005747 enforceModifyPermission();
5748 long identity = Binder.clearCallingIdentity();
5749 try {
Hall Liua1acea22020-09-18 19:04:59 -07005750 if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable);
5751
5752 Phone phone = getPhone(subId);
5753 if (phone == null) {
5754 try {
5755 callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR);
5756 } catch (RemoteException e) {
5757 // ignore
5758 }
5759 return;
5760 }
5761
5762 Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable,
5763 FunctionalUtils.ignoreRemoteException(callback::accept));
5764
5765 sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null);
sqian80370722020-01-29 15:02:51 -08005766 } finally {
5767 Binder.restoreCallingIdentity(identity);
5768 }
5769 }
5770
5771 /**
yinxub1bed742017-04-17 11:45:04 -07005772 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005773 *
yinxub1bed742017-04-17 11:45:04 -07005774 * @param subId id of the subscription
5775 * @param request contains the radio access networks with bands/channels to scan
5776 * @param messenger callback messenger for scan results or errors
5777 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005778 * @return the id of the requested scan which can be used to stop the scan.
5779 */
5780 @Override
5781 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005782 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005783 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5784 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005785 LocationAccessPolicy.LocationPermissionResult locationResult =
5786 LocationAccessPolicy.checkLocationPermission(mApp,
5787 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5788 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005789 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005790 .setCallingPid(Binder.getCallingPid())
5791 .setCallingUid(Binder.getCallingUid())
5792 .setMethod("requestNetworkScan")
5793 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5794 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005795 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold284aa042020-09-22 17:54:53 -07005796 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5797 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005798 if (e != null) {
5799 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5800 throw e;
5801 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005802 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005803 return TelephonyScanManager.INVALID_SCAN_ID;
5804 }
5805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005806 }
Hall Liu912dfd32019-04-25 14:02:26 -07005807 int callingUid = Binder.getCallingUid();
5808 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005809 final long identity = Binder.clearCallingIdentity();
5810 try {
5811 return mNetworkScanRequestTracker.startNetworkScan(
5812 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005813 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005814 } finally {
5815 Binder.restoreCallingIdentity(identity);
5816 }
yinxu504e1392017-04-12 16:03:22 -07005817 }
5818
Hall Liub2ac8ef2019-02-28 15:56:23 -08005819 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold284aa042020-09-22 17:54:53 -07005820 NetworkScanRequest request, int subId, String callingPackage) {
5821 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005822 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5823 boolean hasNetworkScanPermission =
5824 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5825 == PERMISSION_GRANTED;
5826
5827 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5828 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5829 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005830 }
5831
5832 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5833 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005834 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5835 return new SecurityException("Specific channels must not be"
5836 + " scanned without location access.");
5837 }
5838 }
5839 }
5840
Hall Liub2ac8ef2019-02-28 15:56:23 -08005841 return null;
5842 }
5843
yinxu504e1392017-04-12 16:03:22 -07005844 /**
5845 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005846 *
5847 * @param subId id of the subscription
5848 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005849 */
5850 @Override
5851 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5853 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005854
Hall Liu912dfd32019-04-25 14:02:26 -07005855 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005856 final long identity = Binder.clearCallingIdentity();
5857 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005858 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005859 } finally {
5860 Binder.restoreCallingIdentity(identity);
5861 }
yinxu504e1392017-04-12 16:03:22 -07005862 }
5863
5864 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005865 * Get the calculated preferred network type.
5866 * Used for debugging incorrect network type.
5867 *
5868 * @return the preferred network type, defined in RILConstants.java.
5869 */
5870 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005871 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005872 final Phone defaultPhone = getDefaultPhone();
5873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005874 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005875 return RILConstants.PREFERRED_NETWORK_MODE;
5876 }
5877
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005878 final long identity = Binder.clearCallingIdentity();
5879 try {
5880 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005881 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005882 } finally {
5883 Binder.restoreCallingIdentity(identity);
5884 }
Junda Liu84d15a22014-07-02 11:21:04 -07005885 }
5886
5887 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005888 * Get the preferred network type.
5889 * Used for device configuration by some CDMA operators.
5890 *
5891 * @return the preferred network type, defined in RILConstants.java.
5892 */
5893 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005894 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005895 TelephonyPermissions
5896 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5897 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005898
5899 final long identity = Binder.clearCallingIdentity();
5900 try {
5901 if (DBG) log("getPreferredNetworkType");
5902 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5903 int networkType = (result != null ? result[0] : -1);
5904 if (DBG) log("getPreferredNetworkType: " + networkType);
5905 return networkType;
5906 } finally {
5907 Binder.restoreCallingIdentity(identity);
5908 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005909 }
5910
5911 /**
5912 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005913 *
5914 * @param networkType the preferred network type, defined in RILConstants.java.
5915 * @return true on success; false on any failure.
5916 */
5917 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005918 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5920 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005921
5922 final long identity = Binder.clearCallingIdentity();
5923 try {
calvinpan089c2a62020-03-12 14:17:55 +08005924 Boolean success = (Boolean) sendRequest(
5925 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005926
5927 if (success) {
5928 Settings.Global.putInt(mApp.getContentResolver(),
5929 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5930 }
calvinpan089c2a62020-03-12 14:17:55 +08005931 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5932 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005933 } finally {
5934 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005935 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005936 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005937
5938 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005939 * Get the allowed network types that store in the telephony provider.
5940 *
5941 * @param subId the id of the subscription.
5942 * @return allowedNetworkTypes the allowed network types.
5943 */
5944 @Override
5945 public long getAllowedNetworkTypes(int subId) {
5946 TelephonyPermissions
5947 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5948 mApp, subId, "getAllowedNetworkTypes");
5949
5950 final long identity = Binder.clearCallingIdentity();
5951 try {
5952 return SubscriptionManager.getLongSubscriptionProperty(
5953 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5954 } finally {
5955 Binder.restoreCallingIdentity(identity);
5956 }
5957 }
5958
5959 /**
5960 * Set the allowed network types.
5961 *
5962 * @param subId the id of the subscription.
5963 * @param allowedNetworkTypes the allowed network types.
5964 * @return true on success; false on any failure.
5965 */
5966 @Override
5967 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5968 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5969 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005970
calvinpan089c2a62020-03-12 14:17:55 +08005971 SubscriptionManager.setSubscriptionProperty(subId,
5972 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5973 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005974
calvinpan089c2a62020-03-12 14:17:55 +08005975 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5976 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5977 RILConstants.PREFERRED_NETWORK_MODE);
5978 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005979 }
5980
5981 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005982 * Get the allowed network types for certain reason.
5983 *
5984 * @param subId the id of the subscription.
5985 * @param reason the reason the allowed network type change is taking place
5986 * @return the allowed network types.
5987 */
5988 @Override
5989 public long getAllowedNetworkTypesForReason(int subId,
5990 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5991 TelephonyPermissions
5992 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5993 mApp, subId, "getAllowedNetworkTypesForReason");
5994 final long identity = Binder.clearCallingIdentity();
5995 try {
5996 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5997 } finally {
5998 Binder.restoreCallingIdentity(identity);
5999 }
6000 }
6001
6002 /**
Sooraj Sasindranb4a99602020-08-11 10:40:43 -07006003 * Enable/Disable E-UTRA-NR Dual Connectivity
6004 * @param subId subscription id of the sim card
6005 * @param nrDualConnectivityState expected NR dual connectivity state
6006 * This can be passed following states
6007 * <ol>
6008 * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE}
6009 * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE}
6010 * <li>Disable NR dual connectivity and force secondary cell to be released
6011 * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE}
6012 * </ol>
6013 * @return operation result.
6014 */
6015 @Override
6016 public int setNrDualConnectivityState(int subId,
6017 @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) {
6018 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6019 mApp, subId, "enableNRDualConnectivity");
6020 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6021 final long identity = Binder.clearCallingIdentity();
6022 try {
6023 int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY,
6024 nrDualConnectivityState, subId,
6025 workSource);
6026 if (DBG) log("enableNRDualConnectivity result: " + result);
6027 return result;
6028 } finally {
6029 Binder.restoreCallingIdentity(identity);
6030 }
6031 }
6032
6033 /**
6034 * Is E-UTRA-NR Dual Connectivity enabled
6035 * @return true if dual connectivity is enabled else false
6036 */
6037 @Override
6038 public boolean isNrDualConnectivityEnabled(int subId) {
6039 TelephonyPermissions
6040 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6041 mApp, subId, "isNRDualConnectivityEnabled");
6042 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6043 final long identity = Binder.clearCallingIdentity();
6044 try {
6045 boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED,
6046 null, subId, workSource);
6047 if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled);
6048 return isEnabled;
6049 } finally {
6050 Binder.restoreCallingIdentity(identity);
6051 }
6052 }
6053
6054 /**
Sooraj Sasindran1f812e02020-10-30 13:17:53 -07006055 * get carrier bandwidth per primary and secondary carrier
6056 * @param subId subscription id of the sim card
6057 * @return CarrierBandwidth with bandwidth of both primary and secondary carrier..
6058 */
6059 @Override
6060 public CarrierBandwidth getCarrierBandwidth(int subId) {
6061 TelephonyPermissions
6062 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6063 mApp, subId, "isNRDualConnectivityEnabled");
6064 WorkSource workSource = getWorkSource(Binder.getCallingUid());
6065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 CarrierBandwidth carrierBandwidth =
6068 getPhoneFromSubId(subId).getCarrierBandwidth();
6069 if (DBG) log("getCarrierBandwidth: " + carrierBandwidth);
6070 return carrierBandwidth;
6071 } finally {
6072 Binder.restoreCallingIdentity(identity);
6073 }
6074 }
6075
6076 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07006077 * Get the effective allowed network types on the device.
6078 * This API will return an intersection of allowed network types for all reasons,
6079 * including the configuration done through setAllowedNetworkTypes
6080 *
6081 * @param subId the id of the subscription.
6082 * @return the allowed network types
6083 */
6084 @Override
6085 public long getEffectiveAllowedNetworkTypes(int subId) {
6086 TelephonyPermissions
6087 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6088 mApp, subId, "getEffectiveAllowedNetworkTypes");
6089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
6094 }
6095 }
6096
6097 /**
6098 * Set the allowed network types of the device and
6099 * provide the reason triggering the allowed network change.
6100 *
6101 * @param subId the id of the subscription.
6102 * @param reason the reason the allowed network type change is taking place
6103 * @param allowedNetworkTypes the allowed network types.
6104 * @return true on success; false on any failure.
6105 */
6106 @Override
6107 public boolean setAllowedNetworkTypesForReason(int subId,
6108 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
6109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6110 mApp, subId, "setAllowedNetworkTypesForReason");
6111 final long identity = Binder.clearCallingIdentity();
6112 try {
6113 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
6114 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
6115 Settings.Global.PREFERRED_NETWORK_MODE + subId,
6116 RILConstants.PREFERRED_NETWORK_MODE);
6117 return setPreferredNetworkType(subId, preferredNetworkMode);
6118 } finally {
6119 Binder.restoreCallingIdentity(identity);
6120 }
6121 }
6122
6123 /**
Miaoa84611c2019-03-15 09:21:10 +08006124 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08006125 *
Miaoa84611c2019-03-15 09:21:10 +08006126 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07006127 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08006128 * @hide
6129 */
6130 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08006131 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006132 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08006134 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006135 try {
Miaoa84611c2019-03-15 09:21:10 +08006136 if (phone != null) {
6137 return phone.hasMatchedTetherApnSetting();
6138 } else {
6139 return false;
6140 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08006143 }
Junda Liu475951f2014-11-07 16:45:03 -08006144 }
6145
6146 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08006147 * Enable or disable always reporting signal strength changes from radio.
6148 *
6149 * @param isEnable {@code true} for enabling; {@code false} for disabling.
6150 */
6151 @Override
6152 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
6153 enforceModifyPermission();
6154 enforceSystemCaller();
6155
6156 final long identity = Binder.clearCallingIdentity();
6157 final Phone phone = getPhone(subId);
6158 try {
6159 if (phone != null) {
6160 if (DBG) {
6161 log("setAlwaysReportSignalStrength: subId=" + subId
6162 + " isEnable=" + isEnable);
6163 }
6164 phone.setAlwaysReportSignalStrength(isEnable);
6165 } else {
6166 loge("setAlwaysReportSignalStrength: no phone found for subId="
6167 + subId);
6168 }
6169 } finally {
6170 Binder.restoreCallingIdentity(identity);
6171 }
6172 }
6173
6174 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08006175 * Get the user enabled state of Mobile Data.
6176 *
6177 * TODO: remove and use isUserDataEnabled.
6178 * This can't be removed now because some vendor codes
6179 * calls through ITelephony directly while they should
6180 * use TelephonyManager.
6181 *
6182 * @return true on enabled
6183 */
6184 @Override
6185 public boolean getDataEnabled(int subId) {
6186 return isUserDataEnabled(subId);
6187 }
6188
6189 /**
6190 * Get whether mobile data is enabled per user setting.
6191 *
6192 * There are other factors deciding whether mobile data is actually enabled, but they are
6193 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07006194 *
Jeff Davidsona1920712016-11-18 17:05:56 -08006195 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07006196 *
6197 * @return {@code true} if data is enabled else {@code false}
6198 */
6199 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08006200 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07006201 try {
6202 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6203 null);
6204 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6206 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07006207 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006208
6209 final long identity = Binder.clearCallingIdentity();
6210 try {
6211 int phoneId = mSubscriptionController.getPhoneId(subId);
6212 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6213 Phone phone = PhoneFactory.getPhone(phoneId);
6214 if (phone != null) {
6215 boolean retVal = phone.isUserDataEnabled();
6216 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
6217 return retVal;
6218 } else {
6219 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
6220 return false;
6221 }
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08006224 }
6225 }
6226
6227 /**
Shuo Qian985d1232020-01-08 14:30:06 -08006228 * Checks if the device is capable of mobile data by considering whether whether the
6229 * user has enabled mobile data, whether the carrier has enabled mobile data, and
6230 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08006231 *
Shuo Qian985d1232020-01-08 14:30:06 -08006232 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08006233 */
6234 @Override
6235 public boolean isDataEnabled(int subId) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006236 try {
6237 try {
6238 mApp.enforceCallingOrSelfPermission(
6239 android.Manifest.permission.ACCESS_NETWORK_STATE,
6240 null);
6241 } catch (Exception e) {
6242 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
6243 "isDataEnabled");
6244 }
6245 } catch (Exception e) {
6246 enforceReadPrivilegedPermission("isDataEnabled");
6247 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 int phoneId = mSubscriptionController.getPhoneId(subId);
6252 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
6253 Phone phone = PhoneFactory.getPhone(phoneId);
6254 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08006255 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006256 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
6257 return retVal;
6258 } else {
6259 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
6260 return false;
6261 }
6262 } finally {
6263 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08006264 }
Robert Greenwalted86e582014-05-21 20:03:20 -07006265 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006266
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006267 /**
6268 * Check if data is enabled for a specific reason
6269 * @param subId Subscription index
6270 * @param reason the reason the data enable change is taking place
6271 * @return {@code true} if the overall data is enabled; {@code false} if not.
6272 */
6273 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006274 public boolean isDataEnabledForReason(int subId,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006275 @TelephonyManager.DataEnabledReason int reason) {
6276 try {
6277 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
6278 null);
6279 } catch (Exception e) {
6280 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006281 "isDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006282 }
6283
6284
6285 final long identity = Binder.clearCallingIdentity();
6286 try {
6287 int phoneId = mSubscriptionController.getPhoneId(subId);
6288 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006289 log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006290 + " reason=" + reason);
6291 }
6292 Phone phone = PhoneFactory.getPhone(phoneId);
6293 if (phone != null) {
6294 boolean retVal;
6295 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
6296 retVal = phone.isUserDataEnabled();
6297 } else {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006298 retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006299 }
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006300 if (DBG) log("isDataEnabledForReason: retVal=" + retVal);
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006301 return retVal;
6302 } else {
6303 if (DBG) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07006304 loge("isDataEnabledForReason: no phone subId="
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07006305 + subId + " retVal=false");
6306 }
6307 return false;
6308 }
6309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
6312 }
6313
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006314 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006315 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07006316 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
6317 // Skip the check if it's one of these special uids
6318 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6319 }
6320
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006321 //load access rules from carrier configs, and check those as well: b/139133814
6322 SubscriptionController subController = SubscriptionController.getInstance();
6323 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6324 || subController == null) return privilegeFromSim;
6325
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006326 PackageManager pkgMgr = phone.getContext().getPackageManager();
6327 String[] packages = pkgMgr.getPackagesForUid(uid);
6328
6329 final long identity = Binder.clearCallingIdentity();
6330 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006331 int subId = phone.getSubId();
6332 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6333 // A test override is in place for the privileges for this subId, so don't try to
6334 // read the subscription privileges.
6335 return privilegeFromSim;
6336 }
6337 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006338 SubscriptionManager subManager = (SubscriptionManager)
6339 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6340 for (String pkg : packages) {
6341 if (subManager.canManageSubscription(subInfo, pkg)) {
6342 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
6343 }
6344 }
6345 return privilegeFromSim;
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
6349 }
6350
6351 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
6352 String pkgName) {
6353 //load access rules from carrier configs, and check those as well: b/139133814
6354 SubscriptionController subController = SubscriptionController.getInstance();
6355 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
6356 || subController == null) return privilegeFromSim;
6357
6358 final long identity = Binder.clearCallingIdentity();
6359 try {
Jeff Davidson0103e8c2020-03-28 12:24:40 -07006360 int subId = phone.getSubId();
6361 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
6362 // A test override is in place for the privileges for this subId, so don't try to
6363 // read the subscription privileges.
6364 return privilegeFromSim;
6365 }
6366 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006367 SubscriptionManager subManager = (SubscriptionManager)
6368 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
6369 return subManager.canManageSubscription(subInfo, pkgName)
6370 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
6371 } finally {
6372 Binder.restoreCallingIdentity(identity);
6373 }
6374 }
6375
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006376 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006377 public int getCarrierPrivilegeStatus(int subId) {
6378 final Phone phone = getPhone(subId);
6379 if (phone == null) {
6380 loge("getCarrierPrivilegeStatus: Invalid subId");
6381 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6382 }
6383 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006384 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08006385 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006386 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6387 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006388
6389 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6390 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006391 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07006392 }
Junda Liu29340342014-07-10 15:23:27 -07006393
6394 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08006395 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08006396 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006397 final Phone phone = getPhone(subId);
6398 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006399 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006400 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
6401 }
6402 UiccProfile profile =
6403 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
6404 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006405 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08006406 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6407 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006408 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08006409 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08006410 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08006411 }
6412
6413 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006414 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
6415 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08006416 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07006417 }
6418
6419 int phoneId = SubscriptionManager.getPhoneId(subId);
6420 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006421 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07006422 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07006423 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6424 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006425 return getCarrierPrivilegeStatusFromCarrierConfigRules(
6426 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6427 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006428 }
6429
6430 @Override
6431 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08006432 if (TextUtils.isEmpty(pkgName))
6433 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07006434 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
6435 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6436 UiccCard card = UiccController.getInstance().getUiccCard(i);
6437 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07006438 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07006439 continue;
6440 }
6441
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006442 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
6443 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
6444 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07006445 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
6446 break;
6447 }
6448 }
6449
6450 return result;
Junda Liu29340342014-07-10 15:23:27 -07006451 }
Derek Tan89e89d42014-07-08 17:00:10 -07006452
6453 @Override
Junda Liue64de782015-04-16 17:19:16 -07006454 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
6455 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
6456 loge("phoneId " + phoneId + " is not valid.");
6457 return null;
6458 }
6459 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006460 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09006461 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006462 return null ;
6463 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006464 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006465 }
6466
Amith Yamasani6e118872016-02-19 12:53:51 -08006467 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006468 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006469 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006470 List<String> privilegedPackages = new ArrayList<>();
6471 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006472 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6473 // has UICC in that slot.
6474 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006475 if (card.hasCarrierPrivilegeRules()) {
6476 if (packages == null) {
6477 // Only check packages in user 0 for now
6478 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006479 PackageManager.MATCH_DISABLED_COMPONENTS
6480 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006481 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006482 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006483 }
6484 for (int p = packages.size() - 1; p >= 0; p--) {
6485 PackageInfo pkgInfo = packages.get(p);
6486 if (pkgInfo != null && pkgInfo.packageName != null
6487 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006488 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006489 privilegedPackages.add(pkgInfo.packageName);
6490 }
6491 }
6492 }
6493 }
6494 return privilegedPackages;
6495 }
6496
chen xuf7e9fe82019-05-09 19:31:02 -07006497 @Override
6498 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006499 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6500
6501 final long identity = Binder.clearCallingIdentity();
6502
chen xuf7e9fe82019-05-09 19:31:02 -07006503 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006504 try {
6505 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6506 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6507 }
6508 } finally {
6509 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006510 }
6511 return privilegedPackages;
6512 }
6513
Wink Savilleb564aae2014-10-23 10:18:09 -07006514 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006515 final Phone phone = getPhone(subId);
6516 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006517 if (card == null) {
Derek Tan97ebb422014-09-05 16:55:38 -07006518 return null;
6519 }
6520 String iccId = card.getIccId();
6521 if (TextUtils.isEmpty(iccId)) {
Derek Tan97ebb422014-09-05 16:55:38 -07006522 return null;
6523 }
6524 return iccId;
6525 }
6526
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006527 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006528 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6529 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006530 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006531 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006532
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006533 final long identity = Binder.clearCallingIdentity();
6534 try {
6535 final String iccId = getIccId(subId);
6536 final Phone phone = getPhone(subId);
6537 if (phone == null) {
6538 return false;
6539 }
6540 final String subscriberId = phone.getSubscriberId();
6541
6542 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006543 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006544 + subscriberId + " to " + number);
6545 }
6546
6547 if (TextUtils.isEmpty(iccId)) {
6548 return false;
6549 }
6550
6551 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6552
6553 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6554 if (alphaTag == null) {
6555 editor.remove(alphaTagPrefKey);
6556 } else {
6557 editor.putString(alphaTagPrefKey, alphaTag);
6558 }
6559
6560 // Record both the line number and IMSI for this ICCID, since we need to
6561 // track all merged IMSIs based on line number
6562 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6563 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6564 if (number == null) {
6565 editor.remove(numberPrefKey);
6566 editor.remove(subscriberPrefKey);
6567 } else {
6568 editor.putString(numberPrefKey, number);
6569 editor.putString(subscriberPrefKey, subscriberId);
6570 }
6571
6572 editor.commit();
6573 return true;
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006576 }
Derek Tan7226c842014-07-02 17:42:23 -07006577 }
6578
6579 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006580 public String getLine1NumberForDisplay(int subId, String callingPackage,
6581 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006582 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006583 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006584 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006585 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006586 return null;
6587 }
Derek Tan97ebb422014-09-05 16:55:38 -07006588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006589 final long identity = Binder.clearCallingIdentity();
6590 try {
6591 String iccId = getIccId(subId);
6592 if (iccId != null) {
6593 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6594 if (DBG_MERGE) {
6595 log("getLine1NumberForDisplay returning "
6596 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6597 }
6598 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006599 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006600 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6601 return null;
6602 } finally {
6603 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006604 }
Derek Tan7226c842014-07-02 17:42:23 -07006605 }
6606
6607 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006608 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6609 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006610 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006611 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006612 return null;
6613 }
Derek Tan97ebb422014-09-05 16:55:38 -07006614
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 String iccId = getIccId(subId);
6618 if (iccId != null) {
6619 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6620 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6621 }
6622 return null;
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006625 }
Derek Tan7226c842014-07-02 17:42:23 -07006626 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006627
6628 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006629 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6630 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006631 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6632 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006633 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006634 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006635 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006636 return null;
6637 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006638
Jordan Liub49b04b2019-05-06 14:45:15 -07006639 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6640 // the process, where TelephonyManager was instantiated.
6641 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006642 final long identity = Binder.clearCallingIdentity();
6643 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006644 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final TelephonyManager tele = TelephonyManager.from(context);
6646 final SubscriptionManager sub = SubscriptionManager.from(context);
6647
6648 // Figure out what subscribers are currently active
6649 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006650
Jordan Liub49b04b2019-05-06 14:45:15 -07006651 // Only consider subs which match the current subId
6652 // This logic can be simplified. See b/131189269 for progress.
6653 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006654 activeSubscriberIds.add(tele.getSubscriberId(subId));
6655 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656
6657 // First pass, find a number override for an active subscriber
6658 String mergeNumber = null;
6659 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6660 for (String key : prefs.keySet()) {
6661 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6662 final String subscriberId = (String) prefs.get(key);
6663 if (activeSubscriberIds.contains(subscriberId)) {
6664 final String iccId = key.substring(
6665 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6666 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6667 mergeNumber = (String) prefs.get(numberKey);
6668 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006669 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006670 + " for active subscriber " + subscriberId);
6671 }
6672 if (!TextUtils.isEmpty(mergeNumber)) {
6673 break;
6674 }
6675 }
6676 }
6677 }
6678
6679 // Shortcut when no active merged subscribers
6680 if (TextUtils.isEmpty(mergeNumber)) {
6681 return null;
6682 }
6683
6684 // Second pass, find all subscribers under that line override
6685 final ArraySet<String> result = new ArraySet<>();
6686 for (String key : prefs.keySet()) {
6687 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6688 final String number = (String) prefs.get(key);
6689 if (mergeNumber.equals(number)) {
6690 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6691 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6692 final String subscriberId = (String) prefs.get(subscriberKey);
6693 if (!TextUtils.isEmpty(subscriberId)) {
6694 result.add(subscriberId);
6695 }
6696 }
6697 }
6698 }
6699
6700 final String[] resultArray = result.toArray(new String[result.size()]);
6701 Arrays.sort(resultArray);
6702 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006703 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006704 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6705 }
6706 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006707 } finally {
6708 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006709 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006710 }
6711
6712 @Override
zoey chen38003472019-12-13 17:16:31 +08006713 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6714 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006715
6716 final long identity = Binder.clearCallingIdentity();
6717 try {
6718 final TelephonyManager telephonyManager = mApp.getSystemService(
6719 TelephonyManager.class);
6720 String subscriberId = telephonyManager.getSubscriberId(subId);
6721 if (subscriberId == null) {
6722 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006723 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006724 + subId);
6725 }
6726 return null;
6727 }
6728
6729 final SubscriptionInfo info = SubscriptionController.getInstance()
6730 .getSubscriptionInfo(subId);
6731 final ParcelUuid groupUuid = info.getGroupUuid();
6732 // If it doesn't belong to any group, return just subscriberId of itself.
6733 if (groupUuid == null) {
6734 return new String[]{subscriberId};
6735 }
6736
6737 // Get all subscriberIds from the group.
6738 final List<String> mergedSubscriberIds = new ArrayList<>();
6739 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006740 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006741 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006742 for (SubscriptionInfo subInfo : groupInfos) {
6743 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6744 if (subscriberId != null) {
6745 mergedSubscriberIds.add(subscriberId);
6746 }
6747 }
6748
6749 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752
6753 }
6754 }
6755
6756 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006757 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006758 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006759 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760
6761 final long identity = Binder.clearCallingIdentity();
6762 try {
6763 final Phone phone = getPhone(subId);
6764 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6765 } finally {
6766 Binder.restoreCallingIdentity(identity);
6767 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006768 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006769
6770 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006771 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006772 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6773 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006774 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6775 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006776
6777 final long identity = Binder.clearCallingIdentity();
6778 try {
6779 final Phone phone = getPhone(subId);
6780 if (phone == null) {
6781 return false;
6782 }
6783 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6784 cdmaNonRoamingList);
6785 } finally {
6786 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006787 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006788 }
6789
6790 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006791 @Deprecated
6792 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6793 enforceModifyPermission();
6794
6795 int returnValue = 0;
6796 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006797 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006798 if(result.exception == null) {
6799 if (result.result != null) {
6800 byte[] responseData = (byte[])(result.result);
6801 if(responseData.length > oemResp.length) {
6802 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6803 responseData.length + "bytes. Buffer Size is " +
6804 oemResp.length + "bytes.");
6805 }
6806 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6807 returnValue = responseData.length;
6808 }
6809 } else {
6810 CommandException ex = (CommandException) result.exception;
6811 returnValue = ex.getCommandError().ordinal();
6812 if(returnValue > 0) returnValue *= -1;
6813 }
6814 } catch (RuntimeException e) {
6815 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6816 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6817 if(returnValue > 0) returnValue *= -1;
6818 }
6819
6820 return returnValue;
6821 }
6822
6823 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006824 public void setRadioCapability(RadioAccessFamily[] rafs) {
6825 try {
6826 ProxyController.getInstance().setRadioCapability(rafs);
6827 } catch (RuntimeException e) {
6828 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6829 }
6830 }
6831
6832 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006833 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006834 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006835 try {
6836 TelephonyPermissions
6837 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6838 mApp, phone.getSubId(), "getRadioAccessFamily");
6839 } catch (SecurityException e) {
6840 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6841 throw e;
6842 }
chen xub97461a2018-10-26 14:17:57 -07006843 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006844 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006845 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
chen xub97461a2018-10-26 14:17:57 -07006849 TelephonyPermissions
6850 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6851 mApp, phone.getSubId(), "getRadioAccessFamily");
6852 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006853 } finally {
6854 Binder.restoreCallingIdentity(identity);
6855 }
chen xub97461a2018-10-26 14:17:57 -07006856 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006857 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006858
6859 @Override
6860 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006862 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006863
6864 final long identity = Binder.clearCallingIdentity();
6865 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006866 ImsManager.getInstance(defaultPhone.getContext(),
6867 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 } finally {
6869 Binder.restoreCallingIdentity(identity);
6870 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006871 }
6872
6873 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006874 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006875 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006876 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6877 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006878 return false;
6879 }
Svet Ganovb320e182015-04-16 12:30:10 -07006880
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006881 final long identity = Binder.clearCallingIdentity();
6882 try {
6883 // Check the user preference and the system-level IMS setting. Even if the user has
6884 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6885 // In the long run, we may instead need to check if there exists a connection service
6886 // which can support video calling.
6887 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006888 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 return imsManager.isVtEnabledByPlatform()
6890 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6891 && imsManager.isVtEnabledByUser();
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006895 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006896
Andrew Leea1239f22015-03-02 17:44:07 -08006897 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006898 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6899 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006900 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006901 mApp, subId, callingPackage, callingFeatureId,
6902 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 return false;
6904 }
6905
6906 final long identity = Binder.clearCallingIdentity();
6907 try {
6908 CarrierConfigManager configManager =
6909 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006910 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Andrew Leea1239f22015-03-02 17:44:07 -08006915 }
6916
6917 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006918 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006920 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921 return false;
6922 }
6923
6924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 CarrierConfigManager configManager =
6927 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006928 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6930 } finally {
6931 Binder.restoreCallingIdentity(identity);
6932 }
Andrew Leea1239f22015-03-02 17:44:07 -08006933 }
6934
Andrew Lee9431b832015-03-09 18:46:45 -07006935 @Override
6936 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006937 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006938 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006939 }
6940
6941 @Override
6942 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 final long identity = Binder.clearCallingIdentity();
6944 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006945 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 } finally {
6947 Binder.restoreCallingIdentity(identity);
6948 }
Andrew Lee9431b832015-03-09 18:46:45 -07006949 }
6950
Hall Liuf6668912018-10-31 17:05:23 -07006951 /**
6952 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6953 * support for the feature and device firmware support.
6954 *
6955 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6956 */
6957 @Override
6958 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006959 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006960 final Phone phone = getPhone(subscriptionId);
6961 if (phone == null) {
6962 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6963 return false;
6964 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006966 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006967 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6968 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006969 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006970 return isCarrierSupported && isDeviceSupported;
6971 } finally {
6972 Binder.restoreCallingIdentity(identity);
6973 }
Hall Liu98187582018-01-22 19:15:32 -08006974 }
6975
Hall Liuf6668912018-10-31 17:05:23 -07006976 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006977 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6978 * RTT setting, will return true if the device and carrier both support RTT.
6979 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006980 */
6981 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 final long identity = Binder.clearCallingIdentity();
6983 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006984 boolean isRttSupported = isRttSupported(subscriptionId);
6985 boolean isUserRttSettingOn = Settings.Secure.getInt(
6986 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6987 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6988 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6989 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006990 } finally {
6991 Binder.restoreCallingIdentity(identity);
6992 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006993 }
6994
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006995 @Deprecated
6996 @Override
6997 public String getDeviceId(String callingPackage) {
6998 return getDeviceIdWithFeature(callingPackage, null);
6999 }
7000
Sanket Padawe7310cc72015-01-14 09:53:20 -08007001 /**
7002 * Returns the unique device ID of phone, for example, the IMEI for
7003 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
7004 *
7005 * <p>Requires Permission:
7006 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
7007 */
7008 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007009 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007010 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08007011 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08007012 return null;
7013 }
Jeff Davidson913390f2018-02-23 17:11:49 -08007014 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07007015 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007016 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08007017 return null;
7018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019
7020 final long identity = Binder.clearCallingIdentity();
7021 try {
7022 return phone.getDeviceId();
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
7025 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08007026 }
7027
Ping Sunc67b7c22016-03-02 19:16:45 +08007028 /**
7029 * {@hide}
7030 * Returns the IMS Registration Status on a particular subid
7031 *
7032 * @param subId
7033 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007034 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08007035 Phone phone = getPhone(subId);
7036 if (phone != null) {
7037 return phone.isImsRegistered();
7038 } else {
7039 return false;
7040 }
7041 }
7042
Santos Cordon7a1885b2015-02-03 11:15:19 -08007043 @Override
7044 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007045 final long identity = Binder.clearCallingIdentity();
7046 try {
7047 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
7048 } finally {
7049 Binder.restoreCallingIdentity(identity);
7050 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08007051 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07007052
Tyler Gunnf70ed162019-04-03 15:28:53 -07007053 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07007054 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007055 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07007056 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007057 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07007058 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7059 }
7060 final long identity = Binder.clearCallingIdentity();
7061 try {
7062 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
7063 } finally {
7064 Binder.restoreCallingIdentity(identity);
7065 }
7066 }
7067
7068 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07007069 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09007070 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
7071 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07007072 final long identity = Binder.clearCallingIdentity();
7073 try {
7074 Phone phone = getPhone(subscriptionId);
7075 if (phone == null) {
7076 return null;
7077 }
7078 return PhoneUtils.makePstnPhoneAccountHandle(phone);
7079 } finally {
7080 Binder.restoreCallingIdentity(identity);
7081 }
7082 }
7083
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007084 /**
7085 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07007086 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007087 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007088 final long identity = Binder.clearCallingIdentity();
7089 try {
7090 Phone phone = getPhone(subId);
7091 if (phone != null) {
7092 return phone.isWifiCallingEnabled();
7093 } else {
7094 return false;
7095 }
7096 } finally {
7097 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007098 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07007099 }
7100
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007101 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007102 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007103 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007104 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007105 final long identity = Binder.clearCallingIdentity();
7106 try {
7107 Phone phone = getPhone(subId);
7108 if (phone != null) {
7109 return phone.isVideoEnabled();
7110 } else {
7111 return false;
7112 }
7113 } finally {
7114 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007115 }
7116 }
7117
7118 /**
7119 * @return the IMS registration technology for the MMTEL feature. Valid return values are
7120 * defined in {@link ImsRegistrationImplBase}.
7121 */
7122 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007123 final long identity = Binder.clearCallingIdentity();
7124 try {
7125 Phone phone = getPhone(subId);
7126 if (phone != null) {
7127 return phone.getImsRegistrationTech();
7128 } else {
7129 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
7130 }
7131 } finally {
7132 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08007133 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07007134 }
7135
Stuart Scott8eef64f2015-04-08 15:13:54 -07007136 @Override
7137 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08007138 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07007139 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
7140 return;
7141 }
7142
Svet Ganovcc087f82015-05-12 20:35:54 -07007143 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007144
Svet Ganovcc087f82015-05-12 20:35:54 -07007145 try {
Stuart Scott981d8582015-04-21 14:09:50 -07007146 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
7147 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007148 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007149 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07007150 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007151 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007152 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
7153 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07007154 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007155 // There has been issues when Sms raw table somehow stores orphan
7156 // fragments. They lead to garbled message when new fragments come
7157 // in and combined with those stale ones. In case this happens again,
7158 // user can reset all network settings which will clean up this table.
7159 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07007160 // Clean up IMS settings as well here.
7161 int slotId = getSlotIndex(subId);
7162 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
7163 ImsManager.getInstance(mApp, slotId).factoryReset();
7164 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07007165
7166 // Erase modem config if erase modem on network setting is enabled.
7167 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
7168 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
7169 if (configValue != null && Boolean.parseBoolean(configValue)) {
7170 sendEraseModemConfig(getDefaultPhone());
7171 }
Svet Ganovcc087f82015-05-12 20:35:54 -07007172 } finally {
7173 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07007174 }
7175 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007176
Amit Mahajan7dbbd822019-03-13 17:33:47 -07007177 private void cleanUpSmsRawTable(Context context) {
7178 ContentResolver resolver = context.getContentResolver();
7179 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
7180 resolver.delete(uri, null, null);
7181 }
7182
Narayan Kamath1c496c22015-04-16 14:40:19 +01007183 @Override
chen xu5d3637b2019-01-21 23:31:38 -08007184 public String getSimLocaleForSubscriber(int subId) {
7185 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
7186 final Phone phone = getPhone(subId);
7187 if (phone == null) {
7188 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08007189 return null;
chen xu5d3637b2019-01-21 23:31:38 -08007190 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 final long identity = Binder.clearCallingIdentity();
7192 try {
chen xu5d3637b2019-01-21 23:31:38 -08007193 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007194 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08007195 if (info == null) {
7196 log("getSimLocaleForSubscriber, inactive subId: " + subId);
7197 return null;
7198 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007199 // Try and fetch the locale from the carrier properties or from the SIM language
7200 // preferences (EF-PL and EF-LI)...
7201 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08007203 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
7204 if (localeFromDefaultSim != null) {
7205 if (!localeFromDefaultSim.getCountry().isEmpty()) {
7206 if (DBG) log("Using locale from subId: " + subId + " locale: "
7207 + localeFromDefaultSim);
7208 return localeFromDefaultSim.toLanguageTag();
7209 } else {
7210 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007211 }
7212 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007213
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 // The SIM language preferences only store a language (e.g. fr = French), not an
7215 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
7216 // the SIM and carrier preferences does not include a country we add the country
7217 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08007218 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007219 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08007220 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007221 return mccLocale.toLanguageTag();
7222 }
7223
7224 if (DBG) log("No locale found - returning null");
7225 return null;
7226 } finally {
7227 Binder.restoreCallingIdentity(identity);
7228 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01007229 }
7230
7231 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007232 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007233 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007234 }
7235
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007236 /**
7237 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
7238 */
7239 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007240 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08007241 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01007242 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007243
Chenjie Yu1ba97252018-01-11 18:16:20 -08007244 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07007245 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007246
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007247 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07007248 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
7249 * representing the state of the modem.
7250 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08007251 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
7252 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07007253 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007254 */
7255 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07007256 public void requestModemActivityInfo(ResultReceiver result) {
7257 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007258 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007259
7260 final long identity = Binder.clearCallingIdentity();
7261 try {
sqian1a1be542020-03-05 11:37:28 -08007262 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007263 } finally {
7264 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08007265 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07007266 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007267
Siddharth Rayb8114062018-06-17 15:02:38 -07007268 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
7269 // less than total activity duration.
7270 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
7271 if (info == null) {
7272 return false;
7273 }
7274 int activityDurationMs =
7275 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
7276 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07007277 int[] txTimeMs = info.getTransmitTimeMillis();
7278 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
7279 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07007280 }
7281 return (info.isValid()
7282 && (info.getSleepTimeMillis() <= activityDurationMs)
7283 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07007284 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07007285 && (totalTxTimeMs <= activityDurationMs));
7286 }
7287
Jack Yu85bd38a2015-11-09 11:34:32 -08007288 /**
7289 * {@hide}
7290 * Returns the service state information on specified subscription.
7291 */
7292 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007293 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
7294 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007295 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007296 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08007297 return null;
7298 }
7299
Hall Liuf19c44f2018-11-27 14:38:17 -08007300 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
7301 LocationAccessPolicy.checkLocationPermission(mApp,
7302 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7303 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007304 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007305 .setCallingPid(Binder.getCallingPid())
7306 .setCallingUid(Binder.getCallingUid())
7307 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007308 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007309 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
7310 .build());
7311
7312 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
7313 LocationAccessPolicy.checkLocationPermission(mApp,
7314 new LocationAccessPolicy.LocationPermissionQuery.Builder()
7315 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007316 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08007317 .setCallingPid(Binder.getCallingPid())
7318 .setCallingUid(Binder.getCallingUid())
7319 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07007320 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08007321 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
7322 .build());
7323 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
7324 boolean hasFinePermission =
7325 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7326 boolean hasCoarsePermission =
7327 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
7328
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007329 final long identity = Binder.clearCallingIdentity();
7330 try {
Jordan Liuc437b192020-08-17 10:59:12 -07007331 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
7332 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
7333 Rlog.d(LOG_TAG,
7334 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
7335 return null;
7336 }
7337
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007338 final Phone phone = getPhone(subId);
7339 if (phone == null) {
7340 return null;
7341 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007342
Hall Liuf19c44f2018-11-27 14:38:17 -08007343 ServiceState ss = phone.getServiceState();
7344
7345 // Scrub out the location info in ServiceState depending on what level of access
7346 // the caller has.
7347 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08007348 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
7349 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007350 } finally {
7351 Binder.restoreCallingIdentity(identity);
7352 }
Jack Yu85bd38a2015-11-09 11:34:32 -08007353 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007354
7355 /**
7356 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
7357 *
7358 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7359 * voicemail ringtone.
7360 * @return The URI for the ringtone to play when receiving a voicemail from a specific
7361 * PhoneAccount.
7362 */
7363 @Override
7364 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007365 final long identity = Binder.clearCallingIdentity();
7366 try {
7367 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7368 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007369 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007371
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007372 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
7373 } finally {
7374 Binder.restoreCallingIdentity(identity);
7375 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007376 }
7377
7378 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007379 * Sets the per-account voicemail ringtone.
7380 *
7381 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7382 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7383 *
7384 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7385 * voicemail ringtone.
7386 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
7387 * PhoneAccount.
7388 */
7389 @Override
7390 public void setVoicemailRingtoneUri(String callingPackage,
7391 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007392 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007393 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007394 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7395 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007396 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7397 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7398 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007399 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007400
7401 final long identity = Binder.clearCallingIdentity();
7402 try {
7403 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7404 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007405 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 }
7407 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
7408 } finally {
7409 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007410 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007411 }
7412
7413 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08007414 * Returns whether vibration is set for voicemail notification in Phone settings.
7415 *
7416 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
7417 * voicemail vibration setting.
7418 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
7419 */
7420 @Override
7421 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007422 final long identity = Binder.clearCallingIdentity();
7423 try {
7424 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
7425 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007426 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007427 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007428
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007429 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
7430 } finally {
7431 Binder.restoreCallingIdentity(identity);
7432 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08007433 }
7434
Youhan Wange64578a2016-05-02 15:32:42 -07007435 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007436 * Sets the per-account voicemail vibration.
7437 *
7438 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
7439 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7440 *
7441 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
7442 * voicemail vibration setting.
7443 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
7444 * specific PhoneAccount.
7445 */
7446 @Override
7447 public void setVoicemailVibrationEnabled(String callingPackage,
7448 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007449 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007450 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07007451 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
7452 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007453 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7454 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
7455 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007456 }
7457
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007458 final long identity = Binder.clearCallingIdentity();
7459 try {
7460 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
7461 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007462 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007463 }
7464 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
7465 } finally {
7466 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007467 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08007468 }
7469
7470 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007471 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
7472 *
7473 * @throws SecurityException if the caller does not have the required permission
7474 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07007475 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07007476 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07007477 message);
Youhan Wange64578a2016-05-02 15:32:42 -07007478 }
7479
7480 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007481 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7482 * permission.
7483 *
7484 * @throws SecurityException if the caller does not have the required permission
7485 */
7486 private void enforceSendSmsPermission() {
7487 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7488 }
7489
7490 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007491 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007492 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007493 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007494 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007495 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007496 final long identity = Binder.clearCallingIdentity();
7497 try {
7498 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007499 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007500 if (componentName == null) {
7501 throw new SecurityException(
7502 "Caller not current active visual voicemail package[null]");
7503 }
7504 String vvmPackage = componentName.getPackageName();
7505 if (!callingPackage.equals(vvmPackage)) {
7506 throw new SecurityException("Caller not current active visual voicemail package["
7507 + vvmPackage + "]");
7508 }
7509 } finally {
7510 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007511 }
7512 }
7513
7514 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007515 * Return the application ID for the app type.
7516 *
7517 * @param subId the subscription ID that this request applies to.
7518 * @param appType the uicc app type.
7519 * @return Application ID for specificied app type, or null if no uicc.
7520 */
7521 @Override
7522 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007523 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007524 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007525
7526 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007527 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007528 if (phone == null) {
7529 return null;
7530 }
7531 String aid = null;
7532 try {
7533 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7534 .getApplicationByType(appType).getAid();
7535 } catch (Exception e) {
7536 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7537 }
7538 return aid;
7539 } finally {
7540 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007541 }
Youhan Wange64578a2016-05-02 15:32:42 -07007542 }
7543
Youhan Wang4001d252016-05-11 10:29:41 -07007544 /**
7545 * Return the Electronic Serial Number.
7546 *
7547 * @param subId the subscription ID that this request applies to.
7548 * @return ESN or null if error.
7549 */
7550 @Override
7551 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007552 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007553 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554
7555 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007556 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 if (phone == null) {
7558 return null;
7559 }
7560 String esn = null;
7561 try {
7562 esn = phone.getEsn();
7563 } catch (Exception e) {
7564 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7565 }
7566 return esn;
7567 } finally {
7568 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007569 }
Youhan Wang4001d252016-05-11 10:29:41 -07007570 }
7571
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007572 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007573 * Return the Preferred Roaming List Version.
7574 *
7575 * @param subId the subscription ID that this request applies to.
7576 * @return PRLVersion or null if error.
7577 */
7578 @Override
7579 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007580 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007581 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007582
7583 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007584 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 if (phone == null) {
7586 return null;
7587 }
7588 String cdmaPrlVersion = null;
7589 try {
7590 cdmaPrlVersion = phone.getCdmaPrlVersion();
7591 } catch (Exception e) {
7592 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7593 }
7594 return cdmaPrlVersion;
7595 } finally {
7596 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007597 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007598 }
7599
7600 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007601 * Get snapshot of Telephony histograms
7602 * @return List of Telephony histograms
7603 * @hide
7604 */
7605 @Override
7606 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007607 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7608 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609
7610 final long identity = Binder.clearCallingIdentity();
7611 try {
7612 return RIL.getTelephonyRILTimingHistograms();
7613 } finally {
7614 Binder.restoreCallingIdentity(identity);
7615 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007616 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007617
7618 /**
7619 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007620 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7621 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007622 * Require system privileges. In the future we may add this to carrier APIs.
7623 *
Michele Berionne482f8202018-11-27 18:57:59 -08007624 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007625 */
7626 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007627 @TelephonyManager.SetCarrierRestrictionResult
7628 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007629 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007630 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007631
Michele Berionne482f8202018-11-27 18:57:59 -08007632 if (carrierRestrictionRules == null) {
7633 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007634 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007635
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007636 final long identity = Binder.clearCallingIdentity();
7637 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007638 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007639 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 } finally {
7641 Binder.restoreCallingIdentity(identity);
7642 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007643 }
7644
7645 /**
7646 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007647 * Get the allowed carrier list and the excluded carrier list, including the priority between
7648 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007649 * Require system privileges. In the future we may add this to carrier APIs.
7650 *
Michele Berionne482f8202018-11-27 18:57:59 -08007651 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007652 */
7653 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007654 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007655 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007656 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007657
7658 final long identity = Binder.clearCallingIdentity();
7659 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007660 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7661 if (response instanceof CarrierRestrictionRules) {
7662 return (CarrierRestrictionRules) response;
7663 }
7664 // Response is an Exception of some kind,
7665 // which is signalled to the user as a NULL retval
7666 return null;
7667 } catch (Exception e) {
7668 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7669 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007670 } finally {
7671 Binder.restoreCallingIdentity(identity);
7672 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007673 }
7674
fionaxu59545b42016-05-25 15:53:37 -07007675 /**
fionaxu59545b42016-05-25 15:53:37 -07007676 * Action set from carrier signalling broadcast receivers to enable/disable radio
7677 * @param subId the subscription ID that this action applies to.
7678 * @param enabled control enable or disable radio.
7679 * {@hide}
7680 */
7681 @Override
7682 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7683 enforceModifyPermission();
7684 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007685
7686 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007687 if (phone == null) {
7688 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7689 return;
7690 }
7691 try {
7692 phone.carrierActionSetRadioEnabled(enabled);
7693 } catch (Exception e) {
7694 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695 } finally {
7696 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007697 }
7698 }
7699
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007700 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007701 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7702 * network status based on which carrier apps could apply actions accordingly,
7703 * enable/disable default url handler for example.
7704 *
7705 * @param subId the subscription ID that this action applies to.
7706 * @param report control start/stop reporting the default network status.
7707 * {@hide}
7708 */
7709 @Override
7710 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7711 enforceModifyPermission();
7712 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007713
7714 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007715 if (phone == null) {
7716 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7717 return;
7718 }
7719 try {
7720 phone.carrierActionReportDefaultNetworkStatus(report);
7721 } catch (Exception e) {
7722 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007723 } finally {
7724 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007725 }
7726 }
7727
7728 /**
fionaxud9622282017-07-17 17:51:30 -07007729 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7730 * @param subId the subscription ID that this action applies to.
7731 * {@hide}
7732 */
7733 @Override
7734 public void carrierActionResetAll(int subId) {
7735 enforceModifyPermission();
7736 final Phone phone = getPhone(subId);
7737 if (phone == null) {
7738 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7739 return;
7740 }
7741 try {
7742 phone.carrierActionResetAll();
7743 } catch (Exception e) {
7744 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7745 }
7746 }
7747
7748 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007749 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7750 * bug report is being generated.
7751 */
7752 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007753 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007754 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7755 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007756 writer.println("Permission Denial: can't dump Phone from pid="
7757 + Binder.getCallingPid()
7758 + ", uid=" + Binder.getCallingUid()
7759 + "without permission "
7760 + android.Manifest.permission.DUMP);
7761 return;
7762 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007763 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007764 }
Jack Yueb89b242016-06-22 13:27:47 -07007765
Brad Ebingerdac2f002018-04-03 15:17:52 -07007766 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007767 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7768 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7769 @NonNull String[] args) {
7770 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7771 this, in.getFileDescriptor(), out.getFileDescriptor(),
7772 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007773 }
7774
Jack Yueb89b242016-06-22 13:27:47 -07007775 /**
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007776 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Jack Yu75ab2952016-07-08 14:29:33 -07007777 * @param subId Subscription index
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007778 * @param reason the reason the data enable change is taking place
7779 * @param enabled True if enabling the data, otherwise disabling.
7780 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007781 */
7782 @Override
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007783 public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason,
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007784 boolean enabled) {
7785 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7786 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7787 try {
7788 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
Sooraj Sasindranff75de62020-07-15 01:35:24 -07007789 mApp, subId, "setDataEnabledForReason");
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007790 } catch (SecurityException se) {
7791 enforceModifyPermission();
7792 }
7793 } else {
7794 enforceModifyPermission();
7795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007796
7797 final long identity = Binder.clearCallingIdentity();
7798 try {
7799 Phone phone = getPhone(subId);
7800 if (phone != null) {
Sooraj Sasindran2675c0b2020-04-19 18:14:03 -07007801 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7802 phone.carrierActionSetMeteredApnsEnabled(enabled);
7803 } else {
7804 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7805 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007806 }
7807 } finally {
7808 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007809 }
7810 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007811
7812 /**
7813 * Get Client request stats
7814 * @return List of Client Request Stats
7815 * @hide
7816 */
7817 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007818 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7819 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007820 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007821 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007822 return null;
7823 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007824 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007826 final long identity = Binder.clearCallingIdentity();
7827 try {
7828 if (phone != null) {
7829 return phone.getClientRequestStats();
7830 }
7831
7832 return null;
7833 } finally {
7834 Binder.restoreCallingIdentity(identity);
7835 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007836 }
7837
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007838 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007839 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007840 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007841 }
Jack Yueb4124c2017-02-16 15:32:43 -08007842
7843 /**
Grace Chen70990072017-03-24 17:21:30 -07007844 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007845 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007846 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007847 * @param state State of SIM (power down, power up, pass through)
7848 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7849 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7850 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007851 *
7852 **/
7853 @Override
Grace Chen70990072017-03-24 17:21:30 -07007854 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007855 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007856 Phone phone = PhoneFactory.getPhone(slotIndex);
7857
vagdeviaf9a5b92018-08-15 16:01:53 -07007858 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7859
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007860 final long identity = Binder.clearCallingIdentity();
7861 try {
7862 if (phone != null) {
Jordan Liud5366d92020-11-24 14:50:34 -08007863 phone.setSimPowerState(state, null, workSource);
7864 }
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
7868 }
7869
7870 /**
7871 * Set SIM card power state.
7872 *
7873 * @param slotIndex SIM slot id.
7874 * @param state State of SIM (power down, power up, pass through)
7875 * @param callback callback to trigger after success or failure
7876 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7877 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7878 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
7879 *
7880 **/
7881 @Override
7882 public void setSimPowerStateForSlotWithCallback(int slotIndex, int state,
7883 IIntegerConsumer callback) {
7884 enforceModifyPermission();
7885 Phone phone = PhoneFactory.getPhone(slotIndex);
7886
7887 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 if (phone != null) {
7892 Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback);
7893 sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007894 }
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007897 }
7898 }
Shuo Qiandd210312017-04-12 22:11:33 +00007899
Tyler Gunn65d45c22017-06-05 11:22:26 -07007900 private boolean isUssdApiAllowed(int subId) {
7901 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007902 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007903 if (configManager == null) {
7904 return false;
7905 }
7906 PersistableBundle pb = configManager.getConfigForSubId(subId);
7907 if (pb == null) {
7908 return false;
7909 }
7910 return pb.getBoolean(
7911 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7912 }
7913
Shuo Qiandd210312017-04-12 22:11:33 +00007914 /**
7915 * Check if phone is in emergency callback mode
7916 * @return true if phone is in emergency callback mode
7917 * @param subId sub id
7918 */
goneil9c5f4872017-12-05 14:07:56 -08007919 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007920 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007921 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007922 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007923
7924 final long identity = Binder.clearCallingIdentity();
7925 try {
7926 if (phone != null) {
7927 return phone.isInEcm();
7928 } else {
7929 return false;
7930 }
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007933 }
7934 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007935
7936 /**
7937 * Get the current signal strength information for the given subscription.
7938 * Because this information is not updated when the device is in a low power state
7939 * it should not be relied-upon to be current.
7940 * @param subId Subscription index
7941 * @return the most recent cached signal strength info from the modem
7942 */
7943 @Override
7944 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007945 final long identity = Binder.clearCallingIdentity();
7946 try {
7947 Phone p = getPhone(subId);
7948 if (p == null) {
7949 return null;
7950 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007951
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007952 return p.getSignalStrength();
7953 } finally {
7954 Binder.restoreCallingIdentity(identity);
7955 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007956 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007957
Pengquan Meng77b7f132018-08-22 14:49:57 -07007958 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007959 * Get the current modem radio state for the given slot.
7960 * @param slotIndex slot index.
7961 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007962 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007963 * @return the current radio power state from the modem
7964 */
7965 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007966 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007967 Phone phone = PhoneFactory.getPhone(slotIndex);
7968 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007969 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7970 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007971 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7972 }
7973
7974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 return phone.getRadioPowerState();
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
7980 }
7981 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7982 }
7983
7984 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007985 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7986 *
7987 * <p>Requires one of the following permissions:
7988 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7989 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7990 * privileges.
7991 *
7992 * @param subId subscription id
7993 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7994 * {@code false}.
7995 */
7996 @Override
7997 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007998 try {
7999 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
8000 null);
8001 } catch (Exception e) {
8002 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
8003 mApp, subId, "isDataRoamingEnabled");
8004 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07008005
Pengquan Menga1bb6272018-09-06 09:59:22 -07008006 boolean isEnabled = false;
8007 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07008008 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008009 Phone phone = getPhone(subId);
8010 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07008011 } finally {
8012 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008013 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008014 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07008015 }
8016
8017
8018 /**
8019 * Enables/Disables the data roaming on the subscription with id {@code subId}.
8020 *
8021 * <p> Requires permission:
8022 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
8023 * privileges.
8024 *
8025 * @param subId subscription id
8026 * @param isEnabled {@code true} means enable, {@code false} means disable.
8027 */
8028 @Override
8029 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07008030 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8031 mApp, subId, "setDataRoamingEnabled");
8032
Pengquan Menga1bb6272018-09-06 09:59:22 -07008033 final long identity = Binder.clearCallingIdentity();
8034 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07008035 Phone phone = getPhone(subId);
8036 if (phone != null) {
8037 phone.setDataRoamingEnabled(isEnabled);
8038 }
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07008041 }
8042 }
8043
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008044 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008045 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08008046 TelephonyPermissions
8047 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07008048 mApp, subId, "isManualNetworkSelectionAllowed");
8049
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008050 boolean isAllowed = true;
8051 final long identity = Binder.clearCallingIdentity();
8052 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07008053 Phone phone = getPhone(subId);
8054 if (phone != null) {
8055 isAllowed = phone.isCspPlmnEnabled();
8056 }
8057 } finally {
8058 Binder.restoreCallingIdentity(identity);
8059 }
8060 return isAllowed;
8061 }
8062
8063 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08008064 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07008065 // Verify that tha callingPackage belongs to the calling UID
8066 mApp.getSystemService(AppOpsManager.class)
8067 .checkPackage(Binder.getCallingUid(), callingPackage);
8068
Jordan Liu1e142fc2019-04-22 15:10:43 -07008069 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08008070 try {
8071 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07008072 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08008073 } catch (SecurityException e) {
8074 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
8075 // has carrier privileges on an active UICC
8076 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
8077 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07008078 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08008079 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08008080 }
Jordan Liu5aa07002018-12-18 15:44:48 -08008081
8082 final long identity = Binder.clearCallingIdentity();
8083 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08008084 UiccController uiccController = UiccController.getInstance();
8085 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07008086 if (hasReadPermission) {
8087 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08008088 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07008089
8090 // Remove private info if the caller doesn't have access
8091 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
8092 for (UiccCardInfo cardInfo : cardInfos) {
8093 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
8094 // is available
8095 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
8096 if (card == null || card.getUiccProfile() == null) {
8097 // assume no access if the card or profile is unavailable
8098 filteredInfos.add(cardInfo.getUnprivileged());
8099 continue;
8100 }
8101 UiccProfile profile = card.getUiccProfile();
8102 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
8103 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
8104 filteredInfos.add(cardInfo);
8105 } else {
8106 filteredInfos.add(cardInfo.getUnprivileged());
8107 }
8108 }
8109 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08008110 } finally {
8111 Binder.restoreCallingIdentity(identity);
8112 }
8113 }
8114
8115 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008116 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008117 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008118
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008119 final long identity = Binder.clearCallingIdentity();
8120 try {
8121 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
8122 if (slots == null) {
8123 Rlog.i(LOG_TAG, "slots is null.");
8124 return null;
8125 }
8126
8127 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
8128 for (int i = 0; i < slots.length; i++) {
8129 UiccSlot slot = slots[i];
8130 if (slot == null) {
8131 continue;
8132 }
8133
Jordan Liu7be7e652019-05-06 18:55:02 +00008134 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008135 UiccCard card = slot.getUiccCard();
8136 if (card != null) {
8137 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00008138 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07008139 cardId = slot.getEid();
8140 if (TextUtils.isEmpty(cardId)) {
8141 cardId = slot.getIccId();
8142 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008143 }
8144
Jordan Liu857451f2019-05-09 16:35:35 -07008145 if (cardId != null) {
8146 // if cardId is an ICCID, strip off trailing Fs before exposing to user
8147 // if cardId is an EID, it's all digits so this is fine
8148 cardId = IccUtils.stripTrailingFs(cardId);
8149 }
8150
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008151 int cardState = 0;
8152 switch (slot.getCardState()) {
8153 case CARDSTATE_ABSENT:
8154 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
8155 break;
8156 case CARDSTATE_PRESENT:
8157 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
8158 break;
8159 case CARDSTATE_ERROR:
8160 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
8161 break;
8162 case CARDSTATE_RESTRICTED:
8163 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
8164 break;
8165 default:
8166 break;
8167
8168 }
8169
8170 infos[i] = new UiccSlotInfo(
8171 slot.isActive(),
8172 slot.isEuicc(),
8173 cardId,
8174 cardState,
8175 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08008176 slot.isExtendedApduSupported(),
8177 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008178 }
8179 return infos;
8180 } finally {
8181 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07008182 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008183 }
8184
8185 @Override
8186 public boolean switchSlots(int[] physicalSlots) {
8187 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008188
8189 final long identity = Binder.clearCallingIdentity();
8190 try {
8191 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
8192 } finally {
8193 Binder.restoreCallingIdentity(identity);
8194 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00008195 }
Jack Yu4c988042018-02-27 15:30:01 -08008196
8197 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08008198 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08008199 final long identity = Binder.clearCallingIdentity();
8200 try {
8201 return UiccController.getInstance().getCardIdForDefaultEuicc();
8202 } finally {
8203 Binder.restoreCallingIdentity(identity);
8204 }
8205 }
8206
Pengquan Meng85728fb2018-03-12 16:31:21 -07008207 /**
goneil47ffb6e2018-04-06 15:40:58 -07008208 * A test API to reload the UICC profile.
8209 *
8210 * <p>Requires that the calling app has permission
8211 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
8212 * @hide
8213 */
8214 @Override
8215 public void refreshUiccProfile(int subId) {
8216 enforceModifyPermission();
8217
8218 final long identity = Binder.clearCallingIdentity();
8219 try {
8220 Phone phone = getPhone(subId);
8221 if (phone == null) {
8222 return;
8223 }
8224 UiccCard uiccCard = phone.getUiccCard();
8225 if (uiccCard == null) {
8226 return;
8227 }
8228 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8229 if (uiccProfile == null) {
8230 return;
8231 }
8232 uiccProfile.refresh();
8233 } finally {
8234 Binder.restoreCallingIdentity(identity);
8235 }
8236 }
8237
8238 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07008239 * Returns false if the mobile data is disabled by default, otherwise return true.
8240 */
8241 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09008242 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008243 }
8244
8245 /**
8246 * Returns true if the data roaming is enabled by default, i.e the system property
8247 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
8248 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
8249 */
8250 private boolean getDefaultDataRoamingEnabled(int subId) {
8251 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008252 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07008253 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07008254 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
8255 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
8256 return isDataRoamingEnabled;
8257 }
8258
8259 /**
8260 * Returns the default network type for the given {@code subId}, if the default network type is
8261 * not set, return {@link Phone#PREFERRED_NT_MODE}.
8262 */
8263 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09008264 List<Integer> list = TelephonyProperties.default_network();
8265 int phoneId = mSubscriptionController.getPhoneId(subId);
8266 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
8267 return list.get(phoneId);
8268 }
8269 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07008270 }
fionaxua13278b2018-03-21 00:08:13 -07008271
8272 @Override
8273 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07008274 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07008275 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008276
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 final Phone phone = getPhone(subId);
8280 if (phone == null) {
8281 loge("setCarrierTestOverride fails with invalid subId: " + subId);
8282 return;
8283 }
chen xueaba88a2019-03-15 13:15:10 -07008284 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
8285 carrierPrivilegeRules, apn);
Jeff Davidson0103e8c2020-03-28 12:24:40 -07008286 if (carrierPrivilegeRules == null) {
8287 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
8288 } else {
8289 mCarrierPrivilegeTestOverrideSubIds.add(subId);
8290 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008291 } finally {
8292 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008293 }
fionaxua13278b2018-03-21 00:08:13 -07008294 }
8295
8296 @Override
8297 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07008298 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08008299
8300 final long identity = Binder.clearCallingIdentity();
8301 try {
8302 final Phone phone = getPhone(subId);
8303 if (phone == null) {
8304 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
8305 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
8306 }
8307 return phone.getCarrierIdListVersion();
8308 } finally {
8309 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07008310 }
fionaxua13278b2018-03-21 00:08:13 -07008311 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07008312
8313 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008314 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
8315 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008316 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008317 mApp, subId, callingPackage, callingFeatureId,
8318 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07008319 return -1;
8320 }
8321
8322 final long identity = Binder.clearCallingIdentity();
8323 try {
8324 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
8325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07008329
8330 @Override
8331 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08008332 TelephonyPermissions
8333 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07008334 mApp, subId, "getCdmaRoamingMode");
8335
8336 final long identity = Binder.clearCallingIdentity();
8337 try {
8338 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 @Override
8345 public boolean setCdmaRoamingMode(int subId, int mode) {
8346 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8347 mApp, subId, "setCdmaRoamingMode");
8348
8349 final long identity = Binder.clearCallingIdentity();
8350 try {
8351 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
8352 } finally {
8353 Binder.restoreCallingIdentity(identity);
8354 }
8355 }
8356
8357 @Override
Sarah Chin49f22af2020-10-28 13:46:24 -07008358 public int getCdmaSubscriptionMode(int subId) {
8359 TelephonyPermissions
8360 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8361 mApp, subId, "getCdmaSubscriptionMode");
8362
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId);
8366 } finally {
8367 Binder.restoreCallingIdentity(identity);
8368 }
8369 }
8370
8371 @Override
Pengquan Menga1bb6272018-09-06 09:59:22 -07008372 public boolean setCdmaSubscriptionMode(int subId, int mode) {
8373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8374 mApp, subId, "setCdmaSubscriptionMode");
8375
8376 final long identity = Binder.clearCallingIdentity();
8377 try {
8378 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
8379 } finally {
8380 Binder.restoreCallingIdentity(identity);
8381 }
8382 }
Makoto Onukida3bf792018-09-18 16:06:29 -07008383
sqianc5eccab2018-10-19 18:46:41 -07008384 @Override
sqian8c685422019-02-22 15:55:18 -08008385 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008386 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08008387 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008388 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
8389 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08008390 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8391 }
8392 final long identity = Binder.clearCallingIdentity();
8393 try {
sqian854d44b2018-12-12 16:48:18 -08008394 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
8395 for (Phone phone: PhoneFactory.getPhones()) {
8396 if (phone.getEmergencyNumberTracker() != null
8397 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
8398 emergencyNumberListInternal.put(
8399 phone.getSubId(),
8400 phone.getEmergencyNumberTracker().getEmergencyNumberList());
8401 }
sqian11b7a0e2018-12-05 18:48:28 -08008402 }
sqian854d44b2018-12-12 16:48:18 -08008403 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08008404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
sqianc5eccab2018-10-19 18:46:41 -07008407 }
8408
8409 @Override
sqian8c685422019-02-22 15:55:18 -08008410 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08008411 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08008412 if (!exactMatch) {
8413 TelephonyPermissions
8414 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08008415 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08008416 }
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
sqian854d44b2018-12-12 16:48:18 -08008419 for (Phone phone: PhoneFactory.getPhones()) {
8420 if (phone.getEmergencyNumberTracker() != null
Taesu Leee050c002020-10-13 17:19:35 +09008421 && phone.getEmergencyNumberTracker()
8422 .isEmergencyNumber(number, exactMatch)) {
8423 return true;
sqian11b7a0e2018-12-05 18:48:28 -08008424 }
sqian11b7a0e2018-12-05 18:48:28 -08008425 }
8426 return false;
8427 } finally {
8428 Binder.restoreCallingIdentity(identity);
8429 }
8430 }
8431
sqianf4ca7ed2019-01-15 18:32:07 -08008432 /**
8433 * Update emergency number list for test mode.
8434 */
8435 @Override
8436 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
8437 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8438 "updateEmergencyNumberListTestMode");
8439
8440 final long identity = Binder.clearCallingIdentity();
8441 try {
8442 for (Phone phone: PhoneFactory.getPhones()) {
8443 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8444 if (tracker != null) {
8445 tracker.executeEmergencyNumberTestModeCommand(action, num);
8446 }
8447 }
8448 } finally {
8449 Binder.restoreCallingIdentity(identity);
8450 }
8451 }
8452
8453 /**
8454 * Get the full emergency number list for test mode.
8455 */
8456 @Override
8457 public List<String> getEmergencyNumberListTestMode() {
8458 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
8459 "getEmergencyNumberListTestMode");
8460
8461 final long identity = Binder.clearCallingIdentity();
8462 try {
8463 Set<String> emergencyNumbers = new HashSet<>();
8464 for (Phone phone: PhoneFactory.getPhones()) {
8465 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8466 if (tracker != null) {
8467 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
8468 emergencyNumbers.add(num.getNumber());
8469 }
8470 }
8471 }
8472 return new ArrayList<>(emergencyNumbers);
8473 } finally {
8474 Binder.restoreCallingIdentity(identity);
8475 }
8476 }
8477
chen xud6b45bd2018-10-30 22:27:10 -07008478 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08008479 public int getEmergencyNumberDbVersion(int subId) {
8480 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
8481
8482 final long identity = Binder.clearCallingIdentity();
8483 try {
8484 final Phone phone = getPhone(subId);
8485 if (phone == null) {
8486 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
8487 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
8488 }
8489 return phone.getEmergencyNumberDbVersion();
8490 } finally {
8491 Binder.restoreCallingIdentity(identity);
8492 }
8493 }
8494
8495 @Override
8496 public void notifyOtaEmergencyNumberDbInstalled() {
8497 enforceModifyPermission();
8498
8499 final long identity = Binder.clearCallingIdentity();
8500 try {
8501 for (Phone phone: PhoneFactory.getPhones()) {
8502 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8503 if (tracker != null) {
8504 tracker.updateOtaEmergencyNumberDatabase();
8505 }
8506 }
8507 } finally {
8508 Binder.restoreCallingIdentity(identity);
8509 }
8510 }
8511
8512 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08008513 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08008514 enforceActiveEmergencySessionPermission();
8515
8516 final long identity = Binder.clearCallingIdentity();
8517 try {
8518 for (Phone phone: PhoneFactory.getPhones()) {
8519 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8520 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08008521 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8522 }
8523 }
8524 } finally {
8525 Binder.restoreCallingIdentity(identity);
8526 }
8527 }
8528
8529 @Override
8530 public void resetOtaEmergencyNumberDbFilePath() {
8531 enforceActiveEmergencySessionPermission();
8532
8533 final long identity = Binder.clearCallingIdentity();
8534 try {
8535 for (Phone phone: PhoneFactory.getPhones()) {
8536 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8537 if (tracker != null) {
8538 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008539 }
8540 }
8541 } finally {
8542 Binder.restoreCallingIdentity(identity);
8543 }
8544 }
8545
8546 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008547 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8548 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8549 Phone phone = getPhone(subId);
8550 if (phone == null) {
8551 return null;
8552 }
8553 final long identity = Binder.clearCallingIdentity();
8554 try {
8555 UiccProfile profile = UiccController.getInstance()
8556 .getUiccProfileForPhone(phone.getPhoneId());
8557 if (profile != null) {
8558 return profile.getCertsFromCarrierPrivilegeAccessRules();
8559 }
8560 } finally {
8561 Binder.restoreCallingIdentity(identity);
8562 }
8563 return null;
8564 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008565
8566 /**
8567 * Enable or disable a modem stack.
8568 */
8569 @Override
8570 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8571 enforceModifyPermission();
8572
8573 final long identity = Binder.clearCallingIdentity();
8574 try {
8575 Phone phone = PhoneFactory.getPhone(slotIndex);
8576 if (phone == null) {
8577 return false;
8578 } else {
8579 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8580 }
8581 } finally {
8582 Binder.restoreCallingIdentity(identity);
8583 }
8584 }
Michelecea4cf22018-12-21 15:00:11 -08008585
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008586 /**
8587 * Whether a modem stack is enabled or not.
8588 */
8589 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008590 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8591 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008592 Phone phone = PhoneFactory.getPhone(slotIndex);
8593 if (phone == null) return false;
8594
8595 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008596 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8597 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008598 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8599 }
8600
8601 final long identity = Binder.clearCallingIdentity();
8602 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008603 try {
8604 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8605 } catch (NoSuchElementException ex) {
8606 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8607 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008608 } finally {
8609 Binder.restoreCallingIdentity(identity);
8610 }
8611 }
8612
Michelecea4cf22018-12-21 15:00:11 -08008613 @Override
Michele0ea7d782019-03-19 14:58:42 -07008614 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008615 enforceModifyPermission();
8616
8617 final long identity = Binder.clearCallingIdentity();
8618 try {
8619 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008620 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008621 .commit();
8622 } finally {
8623 Binder.restoreCallingIdentity(identity);
8624 }
8625 }
8626
8627 @Override
Michele0ea7d782019-03-19 14:58:42 -07008628 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008629 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008630 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008631 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8632 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008633 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008634 }
Michelecea4cf22018-12-21 15:00:11 -08008635
8636 final long identity = Binder.clearCallingIdentity();
8637 try {
Michele0ea7d782019-03-19 14:58:42 -07008638 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008639 } finally {
8640 Binder.restoreCallingIdentity(identity);
8641 }
8642 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008643
Michele0ea7d782019-03-19 14:58:42 -07008644 @TelephonyManager.IsMultiSimSupportedResult
8645 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008646 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8647 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8648 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008649 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8650 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008651 }
8652 // Check if the hardware supports multisim functionality. If usage of multisim is not
8653 // supported by the modem, indicate that it is restricted.
8654 PhoneCapability staticCapability =
8655 mPhoneConfigurationManager.getStaticPhoneCapability();
8656 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008657 loge("isMultiSimSupportedInternal: no static configuration available");
8658 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008659 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008660 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008661 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8662 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008663 }
8664 // Check if support of multiple SIMs is restricted by carrier
8665 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008666 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008667 }
8668
Michele0ea7d782019-03-19 14:58:42 -07008669 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008670 }
8671
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008672 /**
8673 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008674 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8675 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8676 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008677 * @param numOfSims number of active sims we want to switch to
8678 */
8679 @Override
8680 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008681 if (numOfSims == 1) {
8682 enforceModifyPermission();
8683 } else {
8684 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8685 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8686 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008687 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008688
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008689 try {
Michele30b57b22019-03-01 12:01:14 -08008690 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008691 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008692 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8693 return;
8694 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008695 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8696 } finally {
8697 Binder.restoreCallingIdentity(identity);
8698 }
8699 }
8700
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008701 @Override
8702 public boolean isApplicationOnUicc(int subId, int appType) {
8703 enforceReadPrivilegedPermission("isApplicationOnUicc");
8704 Phone phone = getPhone(subId);
8705 if (phone == null) {
8706 return false;
8707 }
8708 final long identity = Binder.clearCallingIdentity();
8709 try {
8710 UiccCard uiccCard = phone.getUiccCard();
8711 if (uiccCard == null) {
8712 return false;
8713 }
8714 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8715 if (uiccProfile == null) {
8716 return false;
8717 }
8718 if (TelephonyManager.APPTYPE_SIM <= appType
8719 && appType <= TelephonyManager.APPTYPE_ISIM) {
8720 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8721 }
8722 return false;
8723 } finally {
8724 Binder.restoreCallingIdentity(identity);
8725 }
8726 }
8727
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008728 /**
chen xub4baa772019-04-03 10:23:41 -07008729 * Get whether making changes to modem configurations will trigger reboot.
8730 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008731 */
8732 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008733 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8734 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008736 mApp, subId, callingPackage, callingFeatureId,
8737 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008738 return false;
8739 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008740 final long identity = Binder.clearCallingIdentity();
8741 try {
8742 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8743 } finally {
8744 Binder.restoreCallingIdentity(identity);
8745 }
8746 }
8747
Nathan Harold29f5f052019-02-15 13:41:57 -08008748 private void updateModemStateMetrics() {
8749 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8750 // TODO: check the state for each modem if the api is ready.
8751 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8752 }
8753
Pengquan Meng3889a572019-01-23 11:16:29 -08008754 @Override
8755 public int[] getSlotsMapping() {
8756 enforceReadPrivilegedPermission("getSlotsMapping");
8757
8758 final long identity = Binder.clearCallingIdentity();
8759 try {
8760 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8761 // All logical slots should have a mapping to a physical slot.
8762 int[] logicalSlotsMapping = new int[phoneCount];
8763 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8764 for (int i = 0; i < slotInfos.length; i++) {
8765 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8766 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8767 }
8768 }
8769 return logicalSlotsMapping;
8770 } finally {
8771 Binder.restoreCallingIdentity(identity);
8772 }
8773 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008774
8775 /**
8776 * Get the IRadio HAL Version
8777 */
8778 @Override
8779 public int getRadioHalVersion() {
8780 Phone phone = getDefaultPhone();
8781 if (phone == null) return -1;
8782 HalVersion hv = phone.getHalVersion();
8783 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8784 return hv.major * 100 + hv.minor;
8785 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008786
8787 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008788 * Get the current calling package name.
8789 * @return the current calling package name
8790 */
8791 @Override
8792 public String getCurrentPackageName() {
8793 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8794 }
8795
8796 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008797 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8798 * corresponding network requests on a subId.
8799 *
8800 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008801 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008802 * 2) APN is un-metered for this subscription, or
8803 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
Hall Liub48cf452020-09-25 11:13:49 -07008804 * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008805 *
8806 * @return whether data is allowed for a apn type.
8807 *
8808 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008809 */
8810 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008811 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008812 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8813 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008814
8815 // Now that all security checks passes, perform the operation as ourselves.
8816 final long identity = Binder.clearCallingIdentity();
8817 try {
8818 Phone phone = getPhone(subId);
8819 if (phone == null) return false;
8820
Jack Yu41407ee2019-05-13 16:54:09 -07008821 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008822 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8823 } finally {
8824 Binder.restoreCallingIdentity(identity);
8825 }
8826 }
8827
8828 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008829 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008830 enforceReadPrivilegedPermission("isApnMetered");
8831
8832 // Now that all security checks passes, perform the operation as ourselves.
8833 final long identity = Binder.clearCallingIdentity();
8834 try {
8835 Phone phone = getPhone(subId);
8836 if (phone == null) return true; // By default return true.
8837
Jack Yu41407ee2019-05-13 16:54:09 -07008838 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008839 } finally {
8840 Binder.restoreCallingIdentity(identity);
8841 }
8842 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008843
8844 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008845 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8846 int subscriptionId, IBooleanConsumer resultCallback) {
8847 enforceModifyPermission();
8848 long token = Binder.clearCallingIdentity();
8849 try {
8850 Phone phone = getPhone(subscriptionId);
8851 if (phone == null) {
8852 try {
8853 if (resultCallback != null) {
8854 resultCallback.accept(false);
8855 }
8856 } catch (RemoteException e) {
8857 // ignore
8858 }
8859 return;
8860 }
8861 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8862 Pair.create(specifiers, (x) -> {
8863 try {
8864 if (resultCallback != null) {
8865 resultCallback.accept(x);
8866 }
8867 } catch (RemoteException e) {
8868 // ignore
8869 }
8870 });
8871 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8872 } finally {
8873 Binder.restoreCallingIdentity(token);
8874 }
8875 }
8876
8877 @Override
Sarah Chincc055732020-11-18 13:39:35 -08008878 public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) {
8879 TelephonyPermissions
8880 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
8881 mApp, subId, "getSystemSelectionChannels");
8882 WorkSource workSource = getWorkSource(Binder.getCallingUid());
8883 final long identity = Binder.clearCallingIdentity();
8884 try {
8885 List<RadioAccessSpecifier> specifiers =
8886 (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS,
8887 null, subId, workSource);
8888 if (DBG) log("getSystemSelectionChannels: " + specifiers);
8889 return specifiers;
8890 } finally {
8891 Binder.restoreCallingIdentity(identity);
8892 }
8893 }
8894
8895 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008896 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008897 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008898 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8899 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8900 if (iccRecords == null) {
8901 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8902 return false;
8903 }
8904 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8905 }
8906
8907 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008908 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8909 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008910 if (callingPackage == null) {
8911 callingPackage = getCurrentPackageName();
8912 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008913 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8914 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008915 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8916 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008917 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8918 }
8919 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8920 Intent intent = new Intent();
8921 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8922 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8923 // Bring up choose default SMS subscription dialog right now
8924 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8925 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8926 mApp.startActivity(intent);
8927 }
chen xud5ca2d52019-05-28 15:20:57 -07008928
8929 @Override
8930 public String getMmsUAProfUrl(int subId) {
8931 //TODO investigate if this API should require proper permission check in R b/133791609
8932 final long identity = Binder.clearCallingIdentity();
8933 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008934 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8935 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8936 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8937 return carrierUAProfUrl;
8938 }
chen xud5ca2d52019-05-28 15:20:57 -07008939 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8940 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8941 } finally {
8942 Binder.restoreCallingIdentity(identity);
8943 }
8944 }
8945
8946 @Override
8947 public String getMmsUserAgent(int subId) {
8948 //TODO investigate if this API should require proper permission check in R b/133791609
8949 final long identity = Binder.clearCallingIdentity();
8950 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008951 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8952 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8953 if (!TextUtils.isEmpty(carrierUserAgent)) {
8954 return carrierUserAgent;
8955 }
chen xud5ca2d52019-05-28 15:20:57 -07008956 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8957 .getString(com.android.internal.R.string.config_mms_user_agent);
8958 } finally {
8959 Binder.restoreCallingIdentity(identity);
8960 }
8961 }
Jack Yub07d4972019-05-28 16:12:25 -07008962
8963 @Override
Hall Liuc041a552020-09-25 10:42:19 -07008964 public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) {
8965 enforceReadPrivilegedPermission("isMobileDataPolicyEnabled");
8966
8967 final long identity = Binder.clearCallingIdentity();
8968 try {
8969 Phone phone = getPhone(subscriptionId);
8970 if (phone == null) return false;
8971
8972 switch (policy) {
8973 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8974 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8975 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
8976 return phone.getDataEnabledSettings().isMmsAlwaysAllowed();
8977 default:
8978 throw new IllegalArgumentException(policy + " is not a valid policy");
8979 }
8980 } finally {
8981 Binder.restoreCallingIdentity(identity);
8982 }
8983 }
8984
8985 @Override
8986 public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy,
8987 boolean enabled) {
8988 enforceModifyPermission();
8989
8990 final long identity = Binder.clearCallingIdentity();
8991 try {
8992 Phone phone = getPhone(subscriptionId);
8993 if (phone == null) return;
8994
8995 switch (policy) {
8996 case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL:
8997 phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled);
8998 break;
8999 case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED:
9000 phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled);
9001 break;
9002 default:
9003 throw new IllegalArgumentException(policy + " is not a valid policy");
9004 }
9005 } finally {
9006 Binder.restoreCallingIdentity(identity);
9007 }
9008 }
9009
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009010 /**
Hall Liub48cf452020-09-25 11:13:49 -07009011 * Updates whether conference event package handling is enabled.
Tyler Gunn7bcdc742019-10-04 15:56:59 -07009012 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
9013 * otherwise.
9014 */
9015 @Override
9016 public void setCepEnabled(boolean isCepEnabled) {
9017 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
9018
9019 final long identity = Binder.clearCallingIdentity();
9020 try {
9021 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
9022 for (Phone phone : PhoneFactory.getPhones()) {
9023 Phone defaultPhone = phone.getImsPhone();
9024 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
9025 ImsPhone imsPhone = (ImsPhone) defaultPhone;
9026 ImsPhoneCallTracker imsPhoneCallTracker =
9027 (ImsPhoneCallTracker) imsPhone.getCallTracker();
9028 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
9029 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
9030 + imsPhone.getMsisdn());
9031 }
9032 }
9033 } finally {
9034 Binder.restoreCallingIdentity(identity);
9035 }
9036 }
allenwtsu46dcc572020-01-08 18:24:03 +08009037
9038 /**
9039 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
9040 *
9041 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
9042 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
9043 * before being read.
9044 */
9045 @Override
9046 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
9047 isCompressed) {
9048 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9049 mApp, subId, "notifyRcsAutoConfigurationReceived");
Hui Wang068ab862020-10-31 05:12:53 +00009050 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9051 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9052 }
9053 if (!isImsAvailableOnDevice()) {
9054 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9055 "IMS not available on device.");
9056 }
9057
9058 final long identity = Binder.clearCallingIdentity();
allenwtsu46dcc572020-01-08 18:24:03 +08009059 try {
Hui Wang068ab862020-10-31 05:12:53 +00009060 RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed);
9061 } finally {
9062 Binder.restoreCallingIdentity(identity);
allenwtsu46dcc572020-01-08 18:24:03 +08009063 }
9064 }
zoey chenf95ca592019-12-30 16:11:23 +08009065
9066 @Override
9067 public boolean isIccLockEnabled(int subId) {
9068 enforceReadPrivilegedPermission("isIccLockEnabled");
9069
9070 // Now that all security checks passes, perform the operation as ourselves.
9071 final long identity = Binder.clearCallingIdentity();
9072 try {
9073 Phone phone = getPhone(subId);
9074 if (phone != null && phone.getIccCard() != null) {
9075 return phone.getIccCard().getIccLockEnabled();
9076 } else {
9077 return false;
9078 }
9079 } finally {
9080 Binder.restoreCallingIdentity(identity);
9081 }
9082 }
9083
9084 /**
zoey chene02881a2019-12-30 16:11:23 +08009085 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08009086 *
zoey chene02881a2019-12-30 16:11:23 +08009087 * @return an integer representing the status of IccLock enabled or disabled in the following
9088 * three cases:
9089 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
9090 * successfully.
9091 * - Positive number and zero for remaining password attempts.
9092 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009093 *
9094 */
9095 @Override
9096 public int setIccLockEnabled(int subId, boolean enabled, String password) {
9097 enforceModifyPermission();
9098
9099 Phone phone = getPhone(subId);
9100 if (phone == null) {
9101 return 0;
9102 }
9103 // Now that all security checks passes, perform the operation as ourselves.
9104 final long identity = Binder.clearCallingIdentity();
9105 try {
9106 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
9107 new Pair<Boolean, String>(enabled, password), phone, null);
9108 return attemptsRemaining;
9109
9110 } catch (Exception e) {
9111 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
9112 } finally {
9113 Binder.restoreCallingIdentity(identity);
9114 }
9115 return 0;
9116 }
9117
9118 /**
9119 * Change the ICC password used in ICC pin lock.
9120 *
zoey chene02881a2019-12-30 16:11:23 +08009121 * @return an integer representing the status of IccLock changed in the following three cases:
9122 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
9123 * - Positive number and zero for remaining password attempts.
9124 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08009125 *
9126 */
9127 @Override
9128 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
9129 enforceModifyPermission();
9130
9131 Phone phone = getPhone(subId);
9132 if (phone == null) {
9133 return 0;
9134 }
9135 // Now that all security checks passes, perform the operation as ourselves.
9136 final long identity = Binder.clearCallingIdentity();
9137 try {
9138 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
9139 new Pair<String, String>(oldPassword, newPassword), phone, null);
9140 return attemptsRemaining;
9141
9142 } catch (Exception e) {
9143 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
9144 } finally {
9145 Binder.restoreCallingIdentity(identity);
9146 }
9147 return 0;
9148 }
Malcolm Chen884180b2020-04-13 11:59:40 -07009149
Peter Wangdafb9ac2020-01-15 14:13:38 -08009150 /**
9151 * Request for receiving user activity notification
9152 */
9153 @Override
9154 public void requestUserActivityNotification() {
9155 if (!mNotifyUserActivity.get()
9156 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
9157 mNotifyUserActivity.set(true);
9158 }
9159 }
9160
9161 /**
9162 * Called when userActivity is signalled in the power manager.
9163 * This is safe to call from any thread, with any window manager locks held or not.
9164 */
9165 @Override
9166 public void userActivity() {
9167 // ***************************************
9168 // * Inherited from PhoneWindowManager *
9169 // ***************************************
9170 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
9171 // WITH ITS LOCKS HELD.
9172 //
9173 // This code must be VERY careful about the locks
9174 // it acquires.
9175 // In fact, the current code acquires way too many,
9176 // and probably has lurking deadlocks.
9177
9178 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
9179 throw new SecurityException("Only the OS may call notifyUserActivity()");
9180 }
9181
9182 if (mNotifyUserActivity.getAndSet(false)) {
9183 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
9184 USER_ACTIVITY_NOTIFICATION_DELAY);
9185 }
9186 }
Malcolm Chen4639c562020-04-13 11:59:40 -07009187
Malcolm Chen884180b2020-04-13 11:59:40 -07009188 @Override
9189 public boolean canConnectTo5GInDsdsMode() {
9190 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
9191 }
Jack Yud10cdd42020-09-28 20:28:01 -07009192
9193 @Override
9194 public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage,
9195 String callingFeatureId) {
9196 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
9197 mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) {
9198 throw new SecurityException("Requires READ_PHONE_STATE permission.");
9199 }
9200
9201 Phone phone = getPhone(subId);
9202 if (phone == null) {
9203 throw new RuntimeException("phone is not available");
9204 }
9205 // Now that all security checks passes, perform the operation as ourselves.
9206 final long identity = Binder.clearCallingIdentity();
9207 try {
9208 return phone.getEquivalentHomePlmns();
9209 } finally {
9210 Binder.restoreCallingIdentity(identity);
9211 }
9212 }
Jack Nudelman24d51a52020-11-24 12:08:04 -08009213
Hui Wang0866fcc2020-10-12 12:14:23 -07009214 @Override
9215 public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl,
9216 UaSecurityProtocolIdentifier securityProtocol,
9217 boolean forceBootStrapping, IBootstrapAuthenticationCallback callback)
9218 throws RemoteException {
9219 enforceModifyPermission();
9220 if (DBG) {
9221 log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:"
9222 + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol
9223 + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback);
9224 }
9225
9226 if (!SubscriptionManager.isValidSubscriptionId(subId)
9227 || appType < TelephonyManager.APPTYPE_UNKNOWN
9228 || appType > TelephonyManager.APPTYPE_ISIM
9229 || nafUrl == null || securityProtocol == null || callback == null) {
9230 Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters");
9231 if (callback != null) {
9232 try {
9233 callback.onAuthenticationFailure(
9234 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED);
9235 } catch (RemoteException exception) {
9236 log("Fail to notify onAuthenticationFailure due to " + exception);
9237 }
9238 return;
9239 }
9240 }
9241
9242 final long token = Binder.clearCallingIdentity();
9243 try {
9244 getGbaManager(subId).bootstrapAuthenticationRequest(
9245 new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(),
9246 forceBootStrapping, callback));
9247 } finally {
9248 Binder.restoreCallingIdentity(token);
9249 }
9250 }
9251
Jack Nudelman24d51a52020-11-24 12:08:04 -08009252 /**
9253 * Attempts to set the radio power state for thermal reason. This does not guarantee that the
9254 * requested radio power state will actually be set. See {@link
9255 * PhoneInternalInterface#setRadioPowerForReason} for more details.
9256 *
9257 * @param subId the subscription ID of the phone requesting to set the radio power state.
9258 * @param enable {@code true} if trying to turn radio on.
9259 * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code
9260 * false}.
9261 */
9262 private boolean setRadioPowerForThermal(int subId, boolean enable) {
9263 Phone phone = getPhone(subId);
9264 if (phone != null) {
9265 phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL);
9266 return true;
9267 }
9268 return false;
9269 }
9270
9271 private int handleDataThrottlingRequest(int subId,
9272 DataThrottlingRequest dataThrottlingRequest) {
9273 // Ensure that radio is on. If not able to power on due to phone being unavailable, return
9274 // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9275 if (!setRadioPowerForThermal(subId, true)) {
9276 return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9277 }
9278
9279 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true);
9280
9281 int thermalMitigationResult =
9282 (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId);
9283 if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) {
9284 throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS");
9285 }
9286 return thermalMitigationResult;
9287 }
9288
9289 /**
9290 * Thermal mitigation request to control functionalities at modem.
9291 *
9292 * @param subId the id of the subscription.
9293 * @param thermalMitigationRequest holds all necessary information to be passed down to modem.
9294 *
9295 * @return thermalMitigationResult enum as defined in android.telephony.Annotation.
9296 */
9297 @Override
9298 @ThermalMitigationResult
9299 public int sendThermalMitigationRequest(
9300 int subId,
9301 ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException {
9302 enforceModifyPermission();
9303
9304 WorkSource workSource = getWorkSource(Binder.getCallingUid());
9305 final long identity = Binder.clearCallingIdentity();
9306
9307 int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR;
9308 try {
9309 int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction();
9310 switch (thermalMitigationAction) {
9311 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING:
9312 thermalMitigationResult =
9313 handleDataThrottlingRequest(subId,
9314 thermalMitigationRequest.getDataThrottlingRequest());
9315 break;
9316 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY:
9317 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9318 throw new IllegalArgumentException("dataThrottlingRequest must be null for "
9319 + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY");
9320 }
9321
9322 // Ensure that radio is on. If not able to power on due to phone being
9323 // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9324 if (!setRadioPowerForThermal(subId, true)) {
9325 thermalMitigationResult =
9326 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9327 break;
9328 }
9329
9330 setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL,
9331 false);
9332 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9333 break;
9334 case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF:
9335 if (thermalMitigationRequest.getDataThrottlingRequest() != null) {
9336 throw new IllegalArgumentException("dataThrottlingRequest must be null for"
9337 + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF");
9338 }
9339
9340 TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null);
9341 if (registry != null) {
9342 TelephonyConnectionService service =
9343 registry.getTelephonyConnectionService();
9344 Phone phone = getPhone(subId);
9345 if (phone == null) {
9346 thermalMitigationResult =
9347 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9348 break;
9349 }
9350
9351 if (PhoneConstantConversions.convertCallState(phone.getState())
9352 != TelephonyManager.CALL_STATE_IDLE
9353 || phone.isInEmergencySmsMode() || phone.isInEcm()
9354 || (service != null && service.isEmergencyCallPending())) {
9355 String errorMessage = "Phone state is not valid. call state = "
9356 + PhoneConstantConversions.convertCallState(phone.getState())
9357 + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode()
9358 + " isInEmergencyCallbackMode = " + phone.isInEcm();
9359 errorMessage += service == null
9360 ? " TelephonyConnectionService is null"
9361 : " isEmergencyCallPending = "
9362 + service.isEmergencyCallPending();
9363 Log.e(LOG_TAG, errorMessage);
9364 thermalMitigationResult =
9365 TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE;
9366 break;
9367 }
9368 } else {
9369 thermalMitigationResult =
9370 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9371 break;
9372 }
9373
9374 // Turn radio off. If not able to power off due to phone being unavailable,
9375 // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE.
9376 if (!setRadioPowerForThermal(subId, false)) {
9377 thermalMitigationResult =
9378 TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE;
9379 break;
9380 }
9381 thermalMitigationResult =
9382 TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS;
9383 break;
9384 default:
9385 throw new IllegalArgumentException("the requested thermalMitigationAction does "
9386 + "not exist. Requested action: " + thermalMitigationAction);
9387 }
9388 } catch (IllegalArgumentException e) {
9389 throw e;
9390 } catch (Exception e) {
9391 Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e);
9392 thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR;
9393 } finally {
9394 Binder.restoreCallingIdentity(identity);
9395 }
9396
9397 if (DBG) {
9398 log("thermalMitigationRequest returning with thermalMitigationResult: "
9399 + thermalMitigationResult);
9400 }
9401
9402 return thermalMitigationResult;
9403 }
Hui Wang0866fcc2020-10-12 12:14:23 -07009404
9405 /**
9406 * Set the GbaService Package Name that Telephony will bind to.
9407 *
9408 * @param subId The sim that the GbaService is associated with.
9409 * @param packageName The name of the package to be replaced with.
9410 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9411 */
9412 @Override
9413 public boolean setBoundGbaServiceOverride(int subId, String packageName) {
9414 enforceModifyPermission();
9415
9416 final long identity = Binder.clearCallingIdentity();
9417 try {
9418 return getGbaManager(subId).overrideServicePackage(packageName);
9419 } finally {
9420 Binder.restoreCallingIdentity(identity);
9421 }
9422 }
9423
9424 /**
9425 * Return the package name of the currently bound GbaService.
9426 *
9427 * @param subId The sim that the GbaService is associated with.
9428 * @return the package name of the GbaService configuration, null if GBA is not supported.
9429 */
9430 @Override
9431 public String getBoundGbaService(int subId) {
9432 enforceReadPrivilegedPermission("getBoundGbaServicePackage");
9433
9434 final long identity = Binder.clearCallingIdentity();
9435 try {
9436 return getGbaManager(subId).getServicePackage();
9437 } finally {
9438 Binder.restoreCallingIdentity(identity);
9439 }
9440 }
9441
9442 /**
9443 * Set the release time for telephony to unbind GbaService.
9444 *
9445 * @param subId The sim that the GbaService is associated with.
9446 * @param interval The release time to unbind GbaService by millisecond.
9447 * @return true if setting the GbaService to bind to succeeded, false if it did not.
9448 */
9449 @Override
9450 public boolean setGbaReleaseTimeOverride(int subId, int interval) {
9451 enforceModifyPermission();
9452
9453 final long identity = Binder.clearCallingIdentity();
9454 try {
9455 return getGbaManager(subId).overrideReleaseTime(interval);
9456 } finally {
9457 Binder.restoreCallingIdentity(identity);
9458 }
9459 }
9460
9461 /**
9462 * Return the release time for telephony to unbind GbaService.
9463 *
9464 * @param subId The sim that the GbaService is associated with.
9465 * @return The release time to unbind GbaService by millisecond.
9466 */
9467 @Override
9468 public int getGbaReleaseTime(int subId) {
9469 enforceReadPrivilegedPermission("getGbaReleaseTime");
9470
9471 final long identity = Binder.clearCallingIdentity();
9472 try {
9473 return getGbaManager(subId).getReleaseTime();
9474 } finally {
9475 Binder.restoreCallingIdentity(identity);
9476 }
9477 }
9478
9479 private GbaManager getGbaManager(int subId) {
9480 GbaManager instance = GbaManager.getInstance(subId);
9481 if (instance == null) {
9482 String packageName = mApp.getResources().getString(R.string.config_gba_package);
9483 int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time);
9484 instance = GbaManager.make(mApp, subId, packageName, releaseTime);
9485 }
9486 return instance;
9487 }
Hui Wang068ab862020-10-31 05:12:53 +00009488
9489 /**
9490 * indicate whether the device and the carrier can support
9491 * RCS VoLTE single registration.
9492 */
9493 @Override
9494 public boolean isRcsVolteSingleRegistrationCapable(int subId) {
9495 enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable");
9496
9497 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9498 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9499 }
9500
9501 final long identity = Binder.clearCallingIdentity();
9502 try {
9503 RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance();
9504 if (rpm != null) {
9505 return rpm.isRcsVolteSingleRegistrationEnabled(subId);
9506 }
9507 return false;
9508 } finally {
9509 Binder.restoreCallingIdentity(identity);
9510 }
9511 }
9512
9513 /**
9514 * Register RCS provisioning callback.
9515 */
9516 @Override
9517 public void registerRcsProvisioningChangedCallback(int subId,
9518 IRcsConfigCallback callback) {
9519 enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback");
9520
9521 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9522 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9523 }
9524 if (!isImsAvailableOnDevice()) {
9525 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9526 "IMS not available on device.");
9527 }
9528
9529 final long identity = Binder.clearCallingIdentity();
9530 try {
9531 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9532 .addRcsProvisioningCallbackForSubscription(callback, subId);
9533 } catch (ImsException e) {
9534 throw new ServiceSpecificException(e.getCode());
9535 } finally {
9536 Binder.restoreCallingIdentity(identity);
9537 }
9538 }
9539
9540 /**
9541 * Unregister RCS provisioning callback.
9542 */
9543 @Override
9544 public void unregisterRcsProvisioningChangedCallback(int subId,
9545 IRcsConfigCallback callback) {
9546 enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback");
9547
9548 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9549 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9550 }
9551 if (!isImsAvailableOnDevice()) {
9552 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9553 "IMS not available on device.");
9554 }
9555
9556 final long identity = Binder.clearCallingIdentity();
9557 try {
9558 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
9559 .removeRcsProvisioningCallbackForSubscription(callback, subId);
9560 } catch (ImsException e) {
9561 Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId
9562 + "is inactive, ignoring unregister.");
9563 } finally {
9564 Binder.restoreCallingIdentity(identity);
9565 }
9566 }
9567
9568 /**
9569 * trigger RCS reconfiguration.
9570 */
9571 public void triggerRcsReconfiguration(int subId) {
9572 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9573 mApp, subId, "triggerRcsReconfiguration");
9574
9575 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9576 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9577 }
9578 if (!isImsAvailableOnDevice()) {
9579 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9580 "IMS not available on device.");
9581 }
9582
9583 final long identity = Binder.clearCallingIdentity();
9584 try {
9585 RcsProvisioningMonitor.getInstance().requestReconfig(subId);
9586 } finally {
9587 Binder.restoreCallingIdentity(identity);
9588 }
9589 }
9590
9591 /**
9592 * Provide the client configuration parameters of the RCS application.
9593 */
9594 public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) {
9595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
9596 mApp, subId, "setRcsClientConfiguration");
9597
9598 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
9599 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
9600 }
9601 if (!isImsAvailableOnDevice()) {
9602 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
9603 "IMS not available on device.");
9604 }
9605
9606 final long identity = Binder.clearCallingIdentity();
9607
9608 try {
9609 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
9610 if (configBinder == null) {
9611 Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration");
9612 } else {
9613 configBinder.setRcsClientConfiguration(rcc);
9614 }
9615 } catch (RemoteException e) {
9616 Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage());
9617 } finally {
9618 Binder.restoreCallingIdentity(identity);
9619 }
9620 }
9621
9622 /**
9623 * Overrides the config of RCS VoLTE single registration enabled for the device.
9624 */
9625 @Override
9626 public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) {
9627 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9628 "setDeviceSingleRegistrationEnabledOverride");
9629 enforceModifyPermission();
9630
9631 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9632 : Boolean.parseBoolean(enabledStr);
9633 RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled);
9634 }
9635
9636 /**
9637 * Gets the config of RCS VoLTE single registration enabled for the device.
9638 */
9639 @Override
9640 public boolean getDeviceSingleRegistrationEnabled() {
9641 enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled");
9642 return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled();
9643 }
9644
9645 /**
9646 * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription.
9647 */
9648 @Override
9649 public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) {
9650 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
9651 "setCarrierSingleRegistrationEnabledOverride");
9652 enforceModifyPermission();
9653
9654 Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null
9655 : Boolean.parseBoolean(enabledStr);
9656 return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled(
9657 subId, enabled);
9658 }
9659
9660 /**
9661 * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription.
9662 */
9663 @Override
9664 public boolean getCarrierSingleRegistrationEnabled(int subId) {
9665 enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled");
9666 return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId);
9667 }
Chiachang Wangd6d34772020-12-22 11:38:27 +08009668
9669 /**
9670 * Get the mobile provisioning url that is used to launch a browser to allow users to manage
9671 * their mobile plan.
9672 */
9673 @Override
9674 public String getMobileProvisioningUrl() {
9675 enforceReadPrivilegedPermission("getMobileProvisioningUrl");
9676 final long identity = Binder.clearCallingIdentity();
9677 try {
9678 return getDefaultPhone().getMobileProvisioningUrl();
9679 } finally {
9680 Binder.restoreCallingIdentity(identity);
9681 }
9682 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009683}