blob: cae99f48942b5c2e1e3d2f618ce82a1e710b0125 [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;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070054import android.os.ServiceManager;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070055import android.os.ServiceSpecificException;
Brad Ebingerdac2f002018-04-03 15:17:52 -070056import android.os.ShellCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070079import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070080import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080081import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070084import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080085import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080086import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070087import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070093import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070094import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080095import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080096import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000097import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070098import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070099import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800100import android.telephony.data.ApnSetting;
101import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700102import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800103import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700104import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700105import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800106import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700107import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800108import android.telephony.ims.aidl.IImsMmTelFeature;
109import android.telephony.ims.aidl.IImsRcsFeature;
110import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700111import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700112import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800113import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800114import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800115import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800116import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800118import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700119import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700120import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800121import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800122
Andrew Lee312e8172014-10-23 17:01:36 -0700123import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800124import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liua39e6c12020-03-04 13:59:23 -0800125import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800126import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700128import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700129import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800130import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800133import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800135import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800136import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700137import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800138import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700139import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800140import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700141import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700142import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700143import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700144import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700145import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800146import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700147import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700148import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700149import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700150import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700151import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700152import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700153import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700154import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800155import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800156import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700157import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800158import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700159import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800160import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700161import com.android.internal.telephony.imsphone.ImsPhone;
162import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800163import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900164import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700165import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800166import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800168import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700169import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800170import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700171import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800172import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000173import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800174import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700175import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800176import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700177import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700178import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800179import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700180import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700181import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800182import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800183
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700184import java.io.FileDescriptor;
185import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700186import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800187import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800188import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800189import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800190import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100191import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800192import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700193import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800194import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800283 private static final int CMD_GET_CALL_FORWARDING = 83;
284 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
285 private static final int CMD_SET_CALL_FORWARDING = 85;
286 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
287 private static final int CMD_GET_CALL_WAITING = 87;
288 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
289 private static final int CMD_SET_CALL_WAITING = 89;
290 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700291
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800292 // Parameters of select command.
293 private static final int SELECT_COMMAND = 0xA4;
294 private static final int SELECT_P1 = 0x04;
295 private static final int SELECT_P2 = 0;
296 private static final int SELECT_P3 = 0x10;
297
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700298 /** The singleton instance. */
299 private static PhoneInterfaceManager sInstance;
300
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800303 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700304 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private AppOpsManager mAppOps;
306 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800307 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800308 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700309 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700310
Derek Tan97ebb422014-09-05 16:55:38 -0700311 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
312 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800313 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800314 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700315
Michelecea4cf22018-12-21 15:00:11 -0800316 // String to store multi SIM allowed
317 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
318
Derek Tan740e1672017-06-27 14:56:27 -0700319 // The AID of ISD-R.
320 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
321
yinxub1bed742017-04-17 11:45:04 -0700322 private NetworkScanRequestTracker mNetworkScanRequestTracker;
323
David Kelly5e06a7f2018-03-12 14:10:59 +0000324 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
325 private static final int MANUFACTURER_CODE_LENGTH = 8;
326
Derek Tan89e89d42014-07-08 17:00:10 -0700327 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700328 * Experiment flag to enable erase modem config on reset network, default value is false
329 */
330 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
331 "reset_network_erase_modem_config_enabled";
332
333 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700334 * A request object to use for transmitting data to an ICC.
335 */
336 private static final class IccAPDUArgument {
337 public int channel, cla, command, p1, p2, p3;
338 public String data;
339
340 public IccAPDUArgument(int channel, int cla, int command,
341 int p1, int p2, int p3, String data) {
342 this.channel = channel;
343 this.cla = cla;
344 this.command = command;
345 this.p1 = p1;
346 this.p2 = p2;
347 this.p3 = p3;
348 this.data = data;
349 }
350 }
351
352 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700353 * A request object to use for transmitting data to an ICC.
354 */
355 private static final class ManualNetworkSelectionArgument {
356 public OperatorInfo operatorInfo;
357 public boolean persistSelection;
358
359 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
360 this.operatorInfo = operatorInfo;
361 this.persistSelection = persistSelection;
362 }
363 }
364
365 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700366 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
367 * request after sending. The main thread will notify the request when it is complete.
368 */
369 private static final class MainThreadRequest {
370 /** The argument to use for the request */
371 public Object argument;
372 /** The result of the request that is run on the main thread */
373 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800374 // The subscriber id that this request applies to. Defaults to
375 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
376 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700377
Nathan Harold92bed182018-10-12 18:16:49 -0700378 // In cases where subId is unavailable, the caller needs to specify the phone.
379 public Phone phone;
380
vagdeviaf9a5b92018-08-15 16:01:53 -0700381 public WorkSource workSource;
382
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700383 public MainThreadRequest(Object argument) {
384 this.argument = argument;
385 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800386
Nathan Harold92bed182018-10-12 18:16:49 -0700387 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
388 this.argument = argument;
389 if (phone != null) {
390 this.phone = phone;
391 }
392 this.workSource = workSource;
393 }
394
vagdeviaf9a5b92018-08-15 16:01:53 -0700395 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800396 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800397 if (subId != null) {
398 this.subId = subId;
399 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700402 }
403
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800404 private static final class IncomingThirdPartyCallArgs {
405 public final ComponentName component;
406 public final String callId;
407 public final String callerDisplayName;
408
409 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
410 String callerDisplayName) {
411 this.component = component;
412 this.callId = callId;
413 this.callerDisplayName = callerDisplayName;
414 }
415 }
416
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700417 /**
418 * A handler that processes messages on the main thread in the phone process. Since many
419 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
420 * inbound binder threads to the main thread in the phone process. The Binder thread
421 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
422 * on, which will be notified when the operation completes and will contain the result of the
423 * request.
424 *
425 * <p>If a MainThreadRequest object is provided in the msg.obj field,
426 * note that request.result must be set to something non-null for the calling thread to
427 * unblock.
428 */
429 private final class MainThreadHandler extends Handler {
430 @Override
431 public void handleMessage(Message msg) {
432 MainThreadRequest request;
433 Message onCompleted;
434 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800435 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700436 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800437 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700438
439 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700440 case CMD_HANDLE_USSD_REQUEST: {
441 request = (MainThreadRequest) msg.obj;
442 final Phone phone = getPhoneFromRequest(request);
443 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
444 String ussdRequest = ussdObject.first;
445 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700446
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 if (!isUssdApiAllowed(request.subId)) {
448 // Carrier does not support use of this API, return failure.
449 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
450 UssdResponse response = new UssdResponse(ussdRequest, null);
451 Bundle returnData = new Bundle();
452 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
453 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700454
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 request.result = true;
456 notifyRequester(request);
457 return;
458 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 try {
461 request.result = phone != null
462 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
463 } catch (CallStateException cse) {
464 request.result = false;
465 }
466 // Wake up the requesting thread
467 notifyRequester(request);
468 break;
pkanwar32d516d2016-10-14 19:37:38 -0700469 }
470
Yorke Lee716f67e2015-06-17 15:39:16 -0700471 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700472 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700473 final Phone phone = getPhoneFromRequest(request);
474 request.result = phone != null ?
475 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
476 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700478 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700481
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700482 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700483 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700484 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800485 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700486 if (uiccCard == null) {
487 loge("iccTransmitApduLogicalChannel: No UICC");
488 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700489 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700490 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
492 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 iccArgument.channel, iccArgument.cla, iccArgument.command,
495 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700496 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700498 break;
499
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700500 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 ar = (AsyncResult) msg.obj;
502 request = (MainThreadRequest) ar.userObj;
503 if (ar.exception == null && ar.result != null) {
504 request.result = ar.result;
505 } else {
506 request.result = new IccIoResult(0x6F, 0, (byte[])null);
507 if (ar.result == null) {
508 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800509 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700510 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800511 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700512 } else {
513 loge("iccTransmitApduLogicalChannel: Unknown exception");
514 }
515 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700516 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 break;
518
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700519 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
520 request = (MainThreadRequest) msg.obj;
521 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800522 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700523 if (uiccCard == null) {
524 loge("iccTransmitApduBasicChannel: No UICC");
525 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700526 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 } else {
528 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
529 request);
530 uiccCard.iccTransmitApduBasicChannel(
531 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
532 iccArgument.p3, iccArgument.data, onCompleted);
533 }
534 break;
535
536 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
537 ar = (AsyncResult) msg.obj;
538 request = (MainThreadRequest) ar.userObj;
539 if (ar.exception == null && ar.result != null) {
540 request.result = ar.result;
541 } else {
542 request.result = new IccIoResult(0x6F, 0, (byte[])null);
543 if (ar.result == null) {
544 loge("iccTransmitApduBasicChannel: Empty response");
545 } else if (ar.exception instanceof CommandException) {
546 loge("iccTransmitApduBasicChannel: CommandException: " +
547 ar.exception);
548 } else {
549 loge("iccTransmitApduBasicChannel: Unknown exception");
550 }
551 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700552 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700553 break;
554
555 case CMD_EXCHANGE_SIM_IO:
556 request = (MainThreadRequest) msg.obj;
557 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800558 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700559 if (uiccCard == null) {
560 loge("iccExchangeSimIO: No UICC");
561 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700562 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700563 } else {
564 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
565 request);
566 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
567 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
568 iccArgument.data, onCompleted);
569 }
570 break;
571
572 case EVENT_EXCHANGE_SIM_IO_DONE:
573 ar = (AsyncResult) msg.obj;
574 request = (MainThreadRequest) ar.userObj;
575 if (ar.exception == null && ar.result != null) {
576 request.result = ar.result;
577 } else {
578 request.result = new IccIoResult(0x6f, 0, (byte[])null);
579 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700580 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700581 break;
582
Derek Tan4d5e5c12014-02-04 11:54:58 -0800583 case CMD_SEND_ENVELOPE:
584 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800585 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700586 if (uiccCard == null) {
587 loge("sendEnvelopeWithStatus: No UICC");
588 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700589 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700590 } else {
591 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
592 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
593 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800594 break;
595
596 case EVENT_SEND_ENVELOPE_DONE:
597 ar = (AsyncResult) msg.obj;
598 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700599 if (ar.exception == null && ar.result != null) {
600 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700602 request.result = new IccIoResult(0x6F, 0, (byte[])null);
603 if (ar.result == null) {
604 loge("sendEnvelopeWithStatus: Empty response");
605 } else if (ar.exception instanceof CommandException) {
606 loge("sendEnvelopeWithStatus: CommandException: " +
607 ar.exception);
608 } else {
609 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
610 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800611 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700612 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800613 break;
614
Shishir Agrawal566b7612013-10-28 14:41:00 -0700615 case CMD_OPEN_CHANNEL:
616 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800617 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800618 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700619 if (uiccCard == null) {
620 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800621 request.result = new IccOpenLogicalChannelResponse(-1,
622 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700623 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 } else {
625 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800626 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
627 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700628 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700629 break;
630
631 case EVENT_OPEN_CHANNEL_DONE:
632 ar = (AsyncResult) msg.obj;
633 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700634 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700635 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700636 int[] result = (int[]) ar.result;
637 int channelId = result[0];
638 byte[] selectResponse = null;
639 if (result.length > 1) {
640 selectResponse = new byte[result.length - 1];
641 for (int i = 1; i < result.length; ++i) {
642 selectResponse[i - 1] = (byte) result[i];
643 }
644 }
645 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700646 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700648 if (ar.result == null) {
649 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700651 if (ar.exception != null) {
652 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
653 }
654
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700655 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700656 if (ar.exception instanceof CommandException) {
657 CommandException.Error error =
658 ((CommandException) (ar.exception)).getCommandError();
659 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700661 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700663 }
664 }
665 openChannelResp = new IccOpenLogicalChannelResponse(
666 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700667 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700668 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700669 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 break;
671
672 case CMD_CLOSE_CHANNEL:
673 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800674 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700675 if (uiccCard == null) {
676 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900677 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700678 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700679 } else {
680 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
681 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
682 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700683 break;
684
685 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800686 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
687 break;
688
689 case CMD_NV_READ_ITEM:
690 request = (MainThreadRequest) msg.obj;
691 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800692 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
693 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800694 break;
695
696 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700697 ar = (AsyncResult) msg.obj;
698 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800699 if (ar.exception == null && ar.result != null) {
700 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700701 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800702 request.result = "";
703 if (ar.result == null) {
704 loge("nvReadItem: Empty response");
705 } else if (ar.exception instanceof CommandException) {
706 loge("nvReadItem: CommandException: " +
707 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700710 }
711 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700712 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 break;
714
Jake Hambye994d462014-02-03 13:10:13 -0800715 case CMD_NV_WRITE_ITEM:
716 request = (MainThreadRequest) msg.obj;
717 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
718 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800719 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700720 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800721 break;
722
723 case EVENT_NV_WRITE_ITEM_DONE:
724 handleNullReturnEvent(msg, "nvWriteItem");
725 break;
726
727 case CMD_NV_WRITE_CDMA_PRL:
728 request = (MainThreadRequest) msg.obj;
729 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800730 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800731 break;
732
733 case EVENT_NV_WRITE_CDMA_PRL_DONE:
734 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
735 break;
736
chen xu6dac5ab2018-10-26 17:39:23 -0700737 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800738 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700739 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800740 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800741 break;
742
chen xu6dac5ab2018-10-26 17:39:23 -0700743 case EVENT_RESET_MODEM_CONFIG_DONE:
744 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800745 break;
746
Jake Hamby7c27be32014-03-03 13:25:59 -0800747 case CMD_GET_PREFERRED_NETWORK_TYPE:
748 request = (MainThreadRequest) msg.obj;
749 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700750 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800751 break;
752
753 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
754 ar = (AsyncResult) msg.obj;
755 request = (MainThreadRequest) ar.userObj;
756 if (ar.exception == null && ar.result != null) {
757 request.result = ar.result; // Integer
758 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530759 // request.result must be set to something non-null
760 // for the calling thread to unblock
761 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800762 if (ar.result == null) {
763 loge("getPreferredNetworkType: Empty response");
764 } else if (ar.exception instanceof CommandException) {
765 loge("getPreferredNetworkType: CommandException: " +
766 ar.exception);
767 } else {
768 loge("getPreferredNetworkType: Unknown exception");
769 }
770 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700771 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800772 break;
773
774 case CMD_SET_PREFERRED_NETWORK_TYPE:
775 request = (MainThreadRequest) msg.obj;
776 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
777 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700778 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800779 break;
780
781 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
782 handleNullReturnEvent(msg, "setPreferredNetworkType");
783 break;
784
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000785 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
786 request = (MainThreadRequest)msg.obj;
787 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800788 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000789 break;
790
791 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
792 ar = (AsyncResult)msg.obj;
793 request = (MainThreadRequest)ar.userObj;
794 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700795 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000796 break;
797
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800798 case CMD_SET_VOICEMAIL_NUMBER:
799 request = (MainThreadRequest) msg.obj;
800 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
801 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800802 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
803 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800804 break;
805
806 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
807 handleNullReturnEvent(msg, "setVoicemailNumber");
808 break;
809
Stuart Scott54788802015-03-30 13:18:01 -0700810 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
811 request = (MainThreadRequest) msg.obj;
812 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
813 request);
814 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
815 break;
816
817 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
818 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
819 break;
820
Shishir Agrawal302c8692015-06-19 13:49:39 -0700821 case CMD_PERFORM_NETWORK_SCAN:
822 request = (MainThreadRequest) msg.obj;
823 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
824 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
825 break;
826
sqian80370722020-01-29 15:02:51 -0800827 case CMD_GET_CALL_FORWARDING:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
830 int callForwardingReason = (Integer) request.argument;
831 getPhoneFromRequest(request).getCallForwardingOption(
832 callForwardingReason, onCompleted);
833 break;
834
835 case EVENT_GET_CALL_FORWARDING_DONE:
836 ar = (AsyncResult) msg.obj;
837 request = (MainThreadRequest) ar.userObj;
838 CallForwardingInfo callForwardingInfo = null;
839 if (ar.exception == null && ar.result != null) {
840 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
841 for (CallForwardInfo callForwardInfo : callForwardInfos) {
842 // Service Class is a bit mask per 3gpp 27.007. Search for
843 // any service for voice call.
844 if ((callForwardInfo.serviceClass
845 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
846 callForwardingInfo = new CallForwardingInfo(
847 callForwardInfo.serviceClass, callForwardInfo.reason,
848 callForwardInfo.number,
849 callForwardInfo.timeSeconds);
850 break;
851 }
852 }
853 // Didn't find a call forward info for voice call.
854 if (callForwardingInfo == null) {
855 callForwardingInfo = new CallForwardingInfo(
856 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
857 0 /* reason */, null /* number */, 0 /* timeout */);
858 }
859 } else {
860 if (ar.result == null) {
861 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
862 }
863 if (ar.exception != null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
865 }
866 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
867 if (ar.exception instanceof CommandException) {
868 CommandException.Error error =
869 ((CommandException) (ar.exception)).getCommandError();
870 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
871 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
872 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
873 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
874 }
875 }
876 callForwardingInfo = new CallForwardingInfo(
877 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
878 }
879 request.result = callForwardingInfo;
880 notifyRequester(request);
881 break;
882
883 case CMD_SET_CALL_FORWARDING:
884 request = (MainThreadRequest) msg.obj;
885 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
886 CallForwardingInfo callForwardingInfoToSet =
887 (CallForwardingInfo) request.argument;
888 getPhoneFromRequest(request).setCallForwardingOption(
889 callForwardingInfoToSet.getStatus(),
890 callForwardingInfoToSet.getReason(),
891 callForwardingInfoToSet.getNumber(),
892 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
893 break;
894
895 case EVENT_SET_CALL_FORWARDING_DONE:
896 ar = (AsyncResult) msg.obj;
897 request = (MainThreadRequest) ar.userObj;
898 if (ar.exception == null) {
899 request.result = true;
900 } else {
901 request.result = false;
902 loge("setCallForwarding exception: " + ar.exception);
903 }
904 notifyRequester(request);
905 break;
906
907 case CMD_GET_CALL_WAITING:
908 request = (MainThreadRequest) msg.obj;
909 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
910 getPhoneFromRequest(request).getCallWaiting(onCompleted);
911 break;
912
913 case EVENT_GET_CALL_WAITING_DONE:
914 ar = (AsyncResult) msg.obj;
915 request = (MainThreadRequest) ar.userObj;
916 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
917 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800918 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800919 // Service Class is a bit mask per 3gpp 27.007.
920 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 if (callForwardResults.length > 1
922 && ((callForwardResults[1]
923 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
924 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800925 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
926 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
927 } else {
928 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
929 }
930 } else {
931 if (ar.result == null) {
932 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
933 }
934 if (ar.exception != null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
936 }
937 if (ar.exception instanceof CommandException) {
938 CommandException.Error error =
939 ((CommandException) (ar.exception)).getCommandError();
940 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
941 callForwardingStatus =
942 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
943 }
944 }
945 }
946 request.result = callForwardingStatus;
947 notifyRequester(request);
948 break;
949
950 case CMD_SET_CALL_WAITING:
951 request = (MainThreadRequest) msg.obj;
952 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
953 boolean isEnable = (Boolean) request.argument;
954 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
955 break;
956
957 case EVENT_SET_CALL_WAITING_DONE:
958 ar = (AsyncResult) msg.obj;
959 request = (MainThreadRequest) ar.userObj;
960 if (ar.exception == null) {
961 request.result = true;
962 } else {
963 request.result = false;
964 loge("setCallWaiting exception: " + ar.exception);
965 }
966 notifyRequester(request);
967 break;
968
Shishir Agrawal302c8692015-06-19 13:49:39 -0700969 case EVENT_PERFORM_NETWORK_SCAN_DONE:
970 ar = (AsyncResult) msg.obj;
971 request = (MainThreadRequest) ar.userObj;
972 CellNetworkScanResult cellScanResult;
973 if (ar.exception == null && ar.result != null) {
974 cellScanResult = new CellNetworkScanResult(
975 CellNetworkScanResult.STATUS_SUCCESS,
976 (List<OperatorInfo>) ar.result);
977 } else {
978 if (ar.result == null) {
979 loge("getCellNetworkScanResults: Empty response");
980 }
981 if (ar.exception != null) {
982 loge("getCellNetworkScanResults: Exception: " + ar.exception);
983 }
984 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
985 if (ar.exception instanceof CommandException) {
986 CommandException.Error error =
987 ((CommandException) (ar.exception)).getCommandError();
988 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
989 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
990 } else if (error == CommandException.Error.GENERIC_FAILURE) {
991 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
992 }
993 }
994 cellScanResult = new CellNetworkScanResult(errorCode, null);
995 }
996 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700997 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700998 break;
999
1000 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1001 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001002 ManualNetworkSelectionArgument selArg =
1003 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001004 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1005 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001006 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1007 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001008 break;
1009
1010 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001011 ar = (AsyncResult) msg.obj;
1012 request = (MainThreadRequest) ar.userObj;
1013 if (ar.exception == null) {
1014 request.result = true;
1015 } else {
1016 request.result = false;
1017 loge("setNetworkSelectionModeManual " + ar.exception);
1018 }
1019 notifyRequester(request);
1020 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001021 break;
1022
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001023 case CMD_GET_MODEM_ACTIVITY_INFO:
1024 request = (MainThreadRequest) msg.obj;
1025 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001026 if (defaultPhone != null) {
1027 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001028 } else {
1029 ResultReceiver result = (ResultReceiver) request.argument;
1030 Bundle bundle = new Bundle();
1031 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1032 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1033 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001034 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001035 break;
1036
1037 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1038 ar = (AsyncResult) msg.obj;
1039 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001040 ResultReceiver result = (ResultReceiver) request.argument;
1041
1042 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001043 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001044 // Update the last modem activity info and the result of the request.
1045 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1046 if (isModemActivityInfoValid(info)) {
1047 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1048 int[] txTimeMs = info.getTransmitTimeMillis();
1049 int[] lastModemTxTimeMs = mLastModemActivityInfo
1050 .getTransmitTimeMillis();
1051 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1052 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1053 }
1054 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1055 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1056 + mLastModemActivityInfo.getSleepTimeMillis());
1057 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1058 + mLastModemActivityInfo.getIdleTimeMillis());
1059 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1060 mLastModemActivityInfo.setReceiveTimeMillis(
1061 info.getReceiveTimeMillis()
1062 + mLastModemActivityInfo.getReceiveTimeMillis());
1063 }
1064 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1065 mLastModemActivityInfo.getSleepTimeMillis(),
1066 mLastModemActivityInfo.getIdleTimeMillis(),
1067 mLastModemActivityInfo.getTransmitTimeMillis(),
1068 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001069 } else {
1070 if (ar.result == null) {
1071 loge("queryModemActivityInfo: Empty response");
1072 } else if (ar.exception instanceof CommandException) {
1073 loge("queryModemActivityInfo: CommandException: " +
1074 ar.exception);
1075 } else {
1076 loge("queryModemActivityInfo: Unknown exception");
1077 }
1078 }
sqian1a1be542020-03-05 11:37:28 -08001079 Bundle bundle = new Bundle();
1080 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1081 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001082 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001083 break;
1084
Meng Wang1a7c35a2016-05-05 20:56:15 -07001085 case CMD_SET_ALLOWED_CARRIERS:
1086 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001087 CarrierRestrictionRules argument =
1088 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001089 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001090 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001091 break;
1092
1093 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1094 ar = (AsyncResult) msg.obj;
1095 request = (MainThreadRequest) ar.userObj;
1096 if (ar.exception == null && ar.result != null) {
1097 request.result = ar.result;
1098 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001099 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1100 if (ar.exception instanceof CommandException) {
1101 loge("setAllowedCarriers: CommandException: " + ar.exception);
1102 CommandException.Error error =
1103 ((CommandException) (ar.exception)).getCommandError();
1104 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1105 request.result =
1106 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1107 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001108 } else {
1109 loge("setAllowedCarriers: Unknown exception");
1110 }
1111 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001112 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001113 break;
1114
1115 case CMD_GET_ALLOWED_CARRIERS:
1116 request = (MainThreadRequest) msg.obj;
1117 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001118 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001119 break;
1120
1121 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1122 ar = (AsyncResult) msg.obj;
1123 request = (MainThreadRequest) ar.userObj;
1124 if (ar.exception == null && ar.result != null) {
1125 request.result = ar.result;
1126 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001127 request.result = new IllegalStateException(
1128 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001129 if (ar.result == null) {
1130 loge("getAllowedCarriers: Empty response");
1131 } else if (ar.exception instanceof CommandException) {
1132 loge("getAllowedCarriers: CommandException: " +
1133 ar.exception);
1134 } else {
1135 loge("getAllowedCarriers: Unknown exception");
1136 }
1137 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001138 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001139 break;
1140
Nathan Haroldb3014052017-01-25 15:57:32 -08001141 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1142 ar = (AsyncResult) msg.obj;
1143 request = (MainThreadRequest) ar.userObj;
1144 if (ar.exception == null && ar.result != null) {
1145 request.result = ar.result;
1146 } else {
1147 request.result = new IllegalArgumentException(
1148 "Failed to retrieve Forbidden Plmns");
1149 if (ar.result == null) {
1150 loge("getForbiddenPlmns: Empty response");
1151 } else {
1152 loge("getForbiddenPlmns: Unknown exception");
1153 }
1154 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001155 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001156 break;
1157
1158 case CMD_GET_FORBIDDEN_PLMNS:
1159 request = (MainThreadRequest) msg.obj;
1160 uiccCard = getUiccCardFromRequest(request);
1161 if (uiccCard == null) {
1162 loge("getForbiddenPlmns() UiccCard is null");
1163 request.result = new IllegalArgumentException(
1164 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001165 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001166 break;
1167 }
1168 Integer appType = (Integer) request.argument;
1169 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1170 if (uiccApp == null) {
1171 loge("getForbiddenPlmns() no app with specified type -- "
1172 + appType);
1173 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001174 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001175 break;
1176 } else {
1177 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1178 + " specified type -- " + appType);
1179 }
1180 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1181 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1182 onCompleted);
1183 break;
1184
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001185 case CMD_SWITCH_SLOTS:
1186 request = (MainThreadRequest) msg.obj;
1187 int[] physicalSlots = (int[]) request.argument;
1188 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1189 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1190 break;
1191
1192 case EVENT_SWITCH_SLOTS_DONE:
1193 ar = (AsyncResult) msg.obj;
1194 request = (MainThreadRequest) ar.userObj;
1195 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001196 notifyRequester(request);
1197 break;
1198 case CMD_GET_NETWORK_SELECTION_MODE:
1199 request = (MainThreadRequest) msg.obj;
1200 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1201 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1202 break;
1203
1204 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1205 ar = (AsyncResult) msg.obj;
1206 request = (MainThreadRequest) ar.userObj;
1207 if (ar.exception != null) {
1208 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1209 } else {
1210 int mode = ((int[]) ar.result)[0];
1211 if (mode == 0) {
1212 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1213 } else {
1214 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1215 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001216 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001217 notifyRequester(request);
1218 break;
1219 case CMD_GET_CDMA_ROAMING_MODE:
1220 request = (MainThreadRequest) msg.obj;
1221 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1222 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1223 break;
1224 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1225 ar = (AsyncResult) msg.obj;
1226 request = (MainThreadRequest) ar.userObj;
1227 if (ar.exception != null) {
1228 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1229 } else {
1230 request.result = ((int[]) ar.result)[0];
1231 }
1232 notifyRequester(request);
1233 break;
1234 case CMD_SET_CDMA_ROAMING_MODE:
1235 request = (MainThreadRequest) msg.obj;
1236 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1237 int mode = (int) request.argument;
1238 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1239 break;
1240 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1241 ar = (AsyncResult) msg.obj;
1242 request = (MainThreadRequest) ar.userObj;
1243 request.result = ar.exception == null;
1244 notifyRequester(request);
1245 break;
1246 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1247 request = (MainThreadRequest) msg.obj;
1248 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1249 int subscriptionMode = (int) request.argument;
1250 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1251 break;
1252 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1253 ar = (AsyncResult) msg.obj;
1254 request = (MainThreadRequest) ar.userObj;
1255 request.result = ar.exception == null;
1256 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001257 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001258 case CMD_GET_ALL_CELL_INFO:
1259 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001260 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001261 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 case EVENT_GET_ALL_CELL_INFO_DONE:
1264 ar = (AsyncResult) msg.obj;
1265 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001266 // If a timeout occurs, the response will be null
1267 request.result = (ar.exception == null && ar.result != null)
1268 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001269 synchronized (request) {
1270 request.notifyAll();
1271 }
1272 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001273 case CMD_REQUEST_CELL_INFO_UPDATE:
1274 request = (MainThreadRequest) msg.obj;
1275 request.phone.requestCellInfoUpdate(request.workSource,
1276 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1277 break;
1278 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1279 ar = (AsyncResult) msg.obj;
1280 request = (MainThreadRequest) ar.userObj;
1281 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1282 try {
1283 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001284 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001285 cb.onError(
1286 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1287 ar.exception.getClass().getName(),
1288 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001291 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else {
1293 // use the result as returned
1294 cb.onCellInfo((List<CellInfo>) ar.result);
1295 }
1296 } catch (RemoteException re) {
1297 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1298 }
1299 break;
1300 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001301 request = (MainThreadRequest) msg.obj;
1302 WorkSource ws = (WorkSource) request.argument;
1303 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001304 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001305 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001306 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 ar = (AsyncResult) msg.obj;
1308 request = (MainThreadRequest) ar.userObj;
1309 if (ar.exception == null) {
1310 request.result = ar.result;
1311 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001312 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001313 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001314 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001315 }
1316
1317 synchronized (request) {
1318 request.notifyAll();
1319 }
1320 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001321 case CMD_MODEM_REBOOT:
1322 request = (MainThreadRequest) msg.obj;
1323 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001324 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001325 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001326 case EVENT_CMD_MODEM_REBOOT_DONE:
1327 handleNullReturnEvent(msg, "rebootModem");
1328 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001329 case CMD_REQUEST_ENABLE_MODEM:
1330 request = (MainThreadRequest) msg.obj;
1331 boolean enable = (boolean) request.argument;
1332 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001333 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001334 PhoneConfigurationManager.getInstance()
1335 .enablePhone(request.phone, enable, onCompleted);
1336 break;
1337 case EVENT_ENABLE_MODEM_DONE:
1338 ar = (AsyncResult) msg.obj;
1339 request = (MainThreadRequest) ar.userObj;
1340 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001341 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001342 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001343 if ((boolean) request.result) {
1344 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1345 updateModemStateMetrics();
1346 } else {
1347 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1348 + ar.exception);
1349 }
1350 notifyRequester(request);
1351 break;
1352 case CMD_GET_MODEM_STATUS:
1353 request = (MainThreadRequest) msg.obj;
1354 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1355 PhoneConfigurationManager.getInstance()
1356 .getPhoneStatusFromModem(request.phone, onCompleted);
1357 break;
1358 case EVENT_GET_MODEM_STATUS_DONE:
1359 ar = (AsyncResult) msg.obj;
1360 request = (MainThreadRequest) ar.userObj;
1361 int id = request.phone.getPhoneId();
1362 if (ar.exception == null && ar.result != null) {
1363 request.result = ar.result;
1364 //update the cache as modem status has changed
1365 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1366 (boolean) request.result);
1367 } else {
1368 // Return true if modem status cannot be retrieved. For most cases,
1369 // modem status is on. And for older version modems, GET_MODEM_STATUS
1370 // and disable modem are not supported. Modem is always on.
1371 // TODO: this should be fixed in R to support a third
1372 // status UNKNOWN b/131631629
1373 request.result = true;
1374 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1375 + ar.exception);
1376 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001377 notifyRequester(request);
1378 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001379 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1380 request = (MainThreadRequest) msg.obj;
1381 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1382 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1383 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1384 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1385 break;
1386 }
1387 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1388 ar = (AsyncResult) msg.obj;
1389 request = (MainThreadRequest) ar.userObj;
1390 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1391 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1392 args.second.accept(ar.exception == null);
1393 notifyRequester(request);
1394 break;
1395 }
yincheng zhaod698b842019-09-06 17:06:54 -07001396 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1397 ar = (AsyncResult) msg.obj;
1398 request = (MainThreadRequest) ar.userObj;
1399 if (ar.exception == null && ar.result != null) {
1400 request.result = ar.result;
1401 } else {
1402 request.result = -1;
1403 loge("Failed to set Forbidden Plmns");
1404 if (ar.result == null) {
1405 loge("setForbidenPlmns: Empty response");
1406 } else if (ar.exception != null) {
1407 loge("setForbiddenPlmns: Exception: " + ar.exception);
1408 request.result = -1;
1409 } else {
1410 loge("setForbiddenPlmns: Unknown exception");
1411 }
1412 }
1413 notifyRequester(request);
1414 break;
1415 case CMD_SET_FORBIDDEN_PLMNS:
1416 request = (MainThreadRequest) msg.obj;
1417 uiccCard = getUiccCardFromRequest(request);
1418 if (uiccCard == null) {
1419 loge("setForbiddenPlmns: UiccCard is null");
1420 request.result = -1;
1421 notifyRequester(request);
1422 break;
1423 }
1424 Pair<Integer, List<String>> setFplmnsArgs =
1425 (Pair<Integer, List<String>>) request.argument;
1426 appType = setFplmnsArgs.first;
1427 List<String> fplmns = setFplmnsArgs.second;
1428 uiccApp = uiccCard.getApplicationByType(appType);
1429 if (uiccApp == null) {
1430 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1431 request.result = -1;
1432 loge("Failed to get UICC App");
1433 notifyRequester(request);
1434 } else {
1435 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1436 ((SIMRecords) uiccApp.getIccRecords())
1437 .setForbiddenPlmns(onCompleted, fplmns);
1438 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001439 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001440 case CMD_ERASE_MODEM_CONFIG:
1441 request = (MainThreadRequest) msg.obj;
1442 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1443 defaultPhone.eraseModemConfig(onCompleted);
1444 break;
1445 case EVENT_ERASE_MODEM_CONFIG_DONE:
1446 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001447 break;
zoey chenf95ca592019-12-30 16:11:23 +08001448
1449 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1450 request = (MainThreadRequest) msg.obj;
1451 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1452 Pair<String, String> changed = (Pair<String, String>) request.argument;
1453 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1454 changed.first, changed.second, onCompleted);
1455 break;
1456 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1457 ar = (AsyncResult) msg.obj;
1458 request = (MainThreadRequest) ar.userObj;
1459 if (ar.exception == null) {
1460 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1461 } else {
1462 request.result = msg.arg1;
1463 }
1464 notifyRequester(request);
1465 break;
1466
1467 case CMD_SET_ICC_LOCK_ENABLED:
1468 request = (MainThreadRequest) msg.obj;
1469 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1470 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1471 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1472 enabled.first, enabled.second, onCompleted);
1473 break;
1474 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1475 ar = (AsyncResult) msg.obj;
1476 request = (MainThreadRequest) ar.userObj;
1477 if (ar.exception == null) {
1478 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1479 } else {
1480 request.result = msg.arg1;
1481 }
1482 notifyRequester(request);
1483 break;
1484
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001485 default:
1486 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1487 break;
1488 }
1489 }
Jake Hambye994d462014-02-03 13:10:13 -08001490
Pengquan Menga1bb6272018-09-06 09:59:22 -07001491 private void notifyRequester(MainThreadRequest request) {
1492 synchronized (request) {
1493 request.notifyAll();
1494 }
1495 }
1496
Jake Hambye994d462014-02-03 13:10:13 -08001497 private void handleNullReturnEvent(Message msg, String command) {
1498 AsyncResult ar = (AsyncResult) msg.obj;
1499 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1500 if (ar.exception == null) {
1501 request.result = true;
1502 } else {
1503 request.result = false;
1504 if (ar.exception instanceof CommandException) {
1505 loge(command + ": CommandException: " + ar.exception);
1506 } else {
1507 loge(command + ": Unknown exception");
1508 }
1509 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001510 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001511 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001512 }
1513
1514 /**
1515 * Posts the specified command to be executed on the main thread,
1516 * waits for the request to complete, and returns the result.
1517 * @see #sendRequestAsync
1518 */
1519 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001520 return sendRequest(
1521 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1530 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001531 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001539 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001540 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001541 }
1542
1543 /**
1544 * Posts the specified command to be executed on the main thread,
1545 * waits for the request to complete, and returns the result.
1546 * @see #sendRequestAsync
1547 */
Nathan Harold92bed182018-10-12 18:16:49 -07001548 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1549 return sendRequest(command, argument, subId, null, workSource);
1550 }
1551
1552 /**
1553 * Posts the specified command to be executed on the main thread,
1554 * waits for the request to complete, and returns the result.
1555 * @see #sendRequestAsync
1556 */
1557 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1558 return sendRequest(
1559 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(
1568 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001569 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1570 throw new RuntimeException("This method will deadlock if called from the main thread.");
1571 }
1572
Nathan Harold92bed182018-10-12 18:16:49 -07001573 MainThreadRequest request = null;
1574 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1575 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1576 } else if (phone != null) {
1577 request = new MainThreadRequest(argument, phone, workSource);
1578 } else {
1579 request = new MainThreadRequest(argument, subId, workSource);
1580 }
1581
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 Message msg = mMainThreadHandler.obtainMessage(command, request);
1583 msg.sendToTarget();
1584
1585 // Wait for the request to complete
1586 synchronized (request) {
1587 while (request.result == null) {
1588 try {
1589 request.wait();
1590 } catch (InterruptedException e) {
1591 // Do nothing, go back and wait until the request is complete
1592 }
1593 }
1594 }
1595 return request.result;
1596 }
1597
1598 /**
1599 * Asynchronous ("fire and forget") version of sendRequest():
1600 * Posts the specified command to be executed on the main thread, and
1601 * returns immediately.
1602 * @see #sendRequest
1603 */
1604 private void sendRequestAsync(int command) {
1605 mMainThreadHandler.sendEmptyMessage(command);
1606 }
1607
1608 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001609 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001610 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001611 */
1612 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001613 sendRequestAsync(command, argument, null, null);
1614 }
1615
1616 /**
1617 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1618 * @see {@link #sendRequest(int,Object)}
1619 */
1620 private void sendRequestAsync(
1621 int command, Object argument, Phone phone, WorkSource workSource) {
1622 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001623 Message msg = mMainThreadHandler.obtainMessage(command, request);
1624 msg.sendToTarget();
1625 }
1626
1627 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001628 * Initialize the singleton PhoneInterfaceManager instance.
1629 * This is only done once, at startup, from PhoneApp.onCreate().
1630 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001631 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001632 synchronized (PhoneInterfaceManager.class) {
1633 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001634 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001635 } else {
1636 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1637 }
1638 return sInstance;
1639 }
1640 }
1641
1642 /** Private constructor; @see init() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001643 @VisibleForTesting
1644 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001646 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001647 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001648 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001649 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1650 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001651 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001652 mTelephonySharedPreferences =
1653 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001654 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001655 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001656
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 publish();
1658 }
1659
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001660 private Phone getDefaultPhone() {
1661 Phone thePhone = getPhone(getDefaultSubscription());
1662 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1663 }
1664
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001665 private void publish() {
1666 if (DBG) log("publish: " + this);
1667
1668 ServiceManager.addService("phone", this);
1669 }
1670
Stuart Scott584921c2015-01-15 17:10:34 -08001671 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001672 if (request.phone != null) {
1673 return request.phone;
1674 } else {
1675 return getPhoneFromSubId(request.subId);
1676 }
1677 }
1678
1679 private Phone getPhoneFromSubId(int subId) {
1680 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1681 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001682 }
1683
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001684 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1685 Phone phone = getPhoneFromRequest(request);
1686 return phone == null ? null :
1687 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1688 }
1689
Wink Saville36469e72014-06-11 15:17:00 -07001690 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001691 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001692 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001693 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001694
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001695 private void sendEraseModemConfig(Phone phone) {
1696 if (phone != null) {
1697 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1698 mApp, phone.getSubId(), "eraseModemConfig");
1699 final long identity = Binder.clearCallingIdentity();
1700 try {
1701 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1702 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1703 } finally {
1704 Binder.restoreCallingIdentity(identity);
1705 }
1706 }
1707 }
1708
Peter Wang050bb052020-01-13 23:33:09 -08001709 private boolean isImsAvailableOnDevice() {
1710 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1711 if (pm == null) {
1712 // For some reason package manger is not available.. This will fail internally anyway,
1713 // so do not throw error and allow.
1714 return true;
1715 }
1716 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1717 }
1718
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001719 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001720 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001721 }
1722
Wink Savilleb564aae2014-10-23 10:18:09 -07001723 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001724 if (DBG) log("dial: " + number);
1725 // No permission check needed here: This is just a wrapper around the
1726 // ACTION_DIAL intent, which is available to any app since it puts up
1727 // the UI before it does anything.
1728
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001729 final long identity = Binder.clearCallingIdentity();
1730 try {
1731 String url = createTelUrl(number);
1732 if (url == null) {
1733 return;
1734 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001736 // PENDING: should we just silently fail if phone is offhook or ringing?
1737 PhoneConstants.State state = mCM.getState(subId);
1738 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1739 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1740 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1741 mApp.startActivity(intent);
1742 }
1743 } finally {
1744 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001745 }
1746 }
1747
1748 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001749 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001750 }
1751
Wink Savilleb564aae2014-10-23 10:18:09 -07001752 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001753 if (DBG) log("call: " + number);
1754
1755 // This is just a wrapper around the ACTION_CALL intent, but we still
1756 // need to do a permission check since we're calling startActivity()
1757 // from the context of the phone app.
1758 enforceCallPermission();
1759
Jordan Liu1617b712019-07-10 15:06:26 -07001760 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 != AppOpsManager.MODE_ALLOWED) {
1762 return;
1763 }
1764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001765 final long identity = Binder.clearCallingIdentity();
1766 try {
1767 String url = createTelUrl(number);
1768 if (url == null) {
1769 return;
1770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001772 boolean isValid = false;
1773 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1774 if (slist != null) {
1775 for (SubscriptionInfo subInfoRecord : slist) {
1776 if (subInfoRecord.getSubscriptionId() == subId) {
1777 isValid = true;
1778 break;
1779 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001780 }
Wink Saville08874612014-08-31 19:19:58 -07001781 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001782 if (!isValid) {
1783 return;
1784 }
Wink Saville08874612014-08-31 19:19:58 -07001785
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001786 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1787 intent.putExtra(SUBSCRIPTION_KEY, subId);
1788 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1789 mApp.startActivity(intent);
1790 } finally {
1791 Binder.restoreCallingIdentity(identity);
1792 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001793 }
1794
Wink Savilleb564aae2014-10-23 10:18:09 -07001795 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001796 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001797 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1798 }
1799
Wink Savilleb564aae2014-10-23 10:18:09 -07001800 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001801 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001802 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1803 }
1804
Wink Savilleb564aae2014-10-23 10:18:09 -07001805 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001807
1808 final long identity = Binder.clearCallingIdentity();
1809 try {
1810 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1811 checkSimPin.start();
1812 return checkSimPin.unlockSim(null, pin);
1813 } finally {
1814 Binder.restoreCallingIdentity(identity);
1815 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001816 }
1817
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820
1821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1824 checkSimPuk.start();
1825 return checkSimPuk.unlockSim(puk, pin);
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
1831 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001832 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001833 * a synchronous one.
1834 */
1835 private static class UnlockSim extends Thread {
1836
1837 private final IccCard mSimCard;
1838
1839 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001840 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1841 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842
1843 // For replies from SimCard interface
1844 private Handler mHandler;
1845
1846 // For async handler to identify request type
1847 private static final int SUPPLY_PIN_COMPLETE = 100;
1848
1849 public UnlockSim(IccCard simCard) {
1850 mSimCard = simCard;
1851 }
1852
1853 @Override
1854 public void run() {
1855 Looper.prepare();
1856 synchronized (UnlockSim.this) {
1857 mHandler = new Handler() {
1858 @Override
1859 public void handleMessage(Message msg) {
1860 AsyncResult ar = (AsyncResult) msg.obj;
1861 switch (msg.what) {
1862 case SUPPLY_PIN_COMPLETE:
1863 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1864 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001865 mRetryCount = msg.arg1;
1866 if (ar.exception != null) {
1867 if (ar.exception instanceof CommandException &&
1868 ((CommandException)(ar.exception)).getCommandError()
1869 == CommandException.Error.PASSWORD_INCORRECT) {
1870 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001871 } //When UiccCardApp dispose,handle message and return exception
1872 else if (ar.exception instanceof CommandException &&
1873 ((CommandException) (ar.exception)).getCommandError()
1874 == CommandException.Error.ABORTED) {
1875 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001876 } else {
1877 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1878 }
1879 } else {
1880 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1881 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001882 mDone = true;
1883 UnlockSim.this.notifyAll();
1884 }
1885 break;
1886 }
1887 }
1888 };
1889 UnlockSim.this.notifyAll();
1890 }
1891 Looper.loop();
1892 }
1893
1894 /*
1895 * Use PIN or PUK to unlock SIM card
1896 *
1897 * If PUK is null, unlock SIM card with PIN
1898 *
1899 * If PUK is not null, unlock SIM card with PUK and set PIN code
1900 */
Wink Saville9de0f752013-10-22 19:04:03 -07001901 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001902
1903 while (mHandler == null) {
1904 try {
1905 wait();
1906 } catch (InterruptedException e) {
1907 Thread.currentThread().interrupt();
1908 }
1909 }
1910 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1911
1912 if (puk == null) {
1913 mSimCard.supplyPin(pin, callback);
1914 } else {
1915 mSimCard.supplyPuk(puk, pin, callback);
1916 }
1917
1918 while (!mDone) {
1919 try {
1920 Log.d(LOG_TAG, "wait for done");
1921 wait();
1922 } catch (InterruptedException e) {
1923 // Restore the interrupted status
1924 Thread.currentThread().interrupt();
1925 }
1926 }
1927 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001928 int[] resultArray = new int[2];
1929 resultArray[0] = mResult;
1930 resultArray[1] = mRetryCount;
1931 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001932 }
1933 }
1934
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001935 /**
1936 * This method has been removed due to privacy and stability concerns.
1937 */
1938 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001939 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001940 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1941 return;
Wink Saville36469e72014-06-11 15:17:00 -07001942 }
1943
Nathan Harold1f889d82020-06-04 17:05:26 -07001944 @Override
1945 public void updateServiceLocationWithPackageName(String callingPackage) {
1946 mApp.getSystemService(AppOpsManager.class)
1947 .checkPackage(Binder.getCallingUid(), callingPackage);
1948
1949 final int targetSdk = getTargetSdk(callingPackage);
1950 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1951 // Callers targeting S have no business invoking this method.
1952 return;
1953 }
1954
1955 LocationAccessPolicy.LocationPermissionResult locationResult =
1956 LocationAccessPolicy.checkLocationPermission(mApp,
1957 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1958 .setCallingPackage(callingPackage)
1959 .setCallingFeatureId(null)
1960 .setCallingPid(Binder.getCallingPid())
1961 .setCallingUid(Binder.getCallingUid())
1962 .setMethod("updateServiceLocation")
1963 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1964 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1965 .build());
1966 // Apps that lack location permission have no business calling this method;
1967 // however, because no permission was declared in the public API, denials must
1968 // all be "soft".
1969 switch (locationResult) {
1970 case DENIED_HARD: /* fall through */
1971 case DENIED_SOFT:
1972 return;
1973 }
1974
1975 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001976 final long identity = Binder.clearCallingIdentity();
1977 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001978 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001979 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001980 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001981 }
1982 } finally {
1983 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001984 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001985 }
1986
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001987 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001988 @Override
1989 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001990 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001991 }
1992
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001993 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001994 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1995 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1996 callingFeatureId);
1997 }
1998
1999 @Deprecated
2000 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002001 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002002 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2003 }
2004
2005 @Override
2006 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2007 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002008 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002009 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002010 return false;
2011 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002012
2013 final long identity = Binder.clearCallingIdentity();
2014 try {
2015 return isRadioOnForSubscriber(subId);
2016 } finally {
2017 Binder.restoreCallingIdentity(identity);
2018 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002019 }
2020
2021 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 final Phone phone = getPhone(subId);
2025 if (phone != null) {
2026 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2027 } else {
2028 return false;
2029 }
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002032 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002033 }
2034
2035 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002036 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002037 }
Wink Saville36469e72014-06-11 15:17:00 -07002038
Wink Savilleb564aae2014-10-23 10:18:09 -07002039 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002040 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002041
2042 final long identity = Binder.clearCallingIdentity();
2043 try {
2044 final Phone phone = getPhone(subId);
2045 if (phone != null) {
2046 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2047 }
2048 } finally {
2049 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002050 }
Wink Saville36469e72014-06-11 15:17:00 -07002051 }
2052
2053 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002054 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002055 }
2056
Wink Savilleb564aae2014-10-23 10:18:09 -07002057 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002058 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002059
2060 final long identity = Binder.clearCallingIdentity();
2061 try {
2062 final Phone phone = getPhone(subId);
2063 if (phone == null) {
2064 return false;
2065 }
2066 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2067 toggleRadioOnOffForSubscriber(subId);
2068 }
2069 return true;
2070 } finally {
2071 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002072 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002073 }
Wink Saville36469e72014-06-11 15:17:00 -07002074
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002076 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002077 /*
2078 * If any of the Radios are available, it will need to be
2079 * shutdown. So return true if any Radio is available.
2080 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002081 final long identity = Binder.clearCallingIdentity();
2082 try {
2083 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2084 Phone phone = PhoneFactory.getPhone(i);
2085 if (phone != null && phone.isRadioAvailable()) return true;
2086 }
2087 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2088 return false;
2089 } finally {
2090 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002091 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002092 }
2093
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002094 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002095 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002096 enforceModifyPermission();
2097
2098 final long identity = Binder.clearCallingIdentity();
2099 try {
2100 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2101 logv("Shutting down Phone " + i);
2102 shutdownRadioUsingPhoneId(i);
2103 }
2104 } finally {
2105 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002106 }
2107 }
2108
2109 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002110 Phone phone = PhoneFactory.getPhone(phoneId);
2111 if (phone != null && phone.isRadioAvailable()) {
2112 phone.shutdownRadio();
2113 }
2114 }
2115
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002116 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002117 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002118
2119 final long identity = Binder.clearCallingIdentity();
2120 try {
2121 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2122 if (defaultPhone != null) {
2123 defaultPhone.setRadioPower(turnOn);
2124 return true;
2125 } else {
2126 loge("There's no default phone.");
2127 return false;
2128 }
2129 } finally {
2130 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002131 }
Wink Saville36469e72014-06-11 15:17:00 -07002132 }
2133
Wink Savilleb564aae2014-10-23 10:18:09 -07002134 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002135 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002136
2137 final long identity = Binder.clearCallingIdentity();
2138 try {
2139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
2141 phone.setRadioPower(turnOn);
2142 return true;
2143 } else {
2144 return false;
2145 }
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
Wink Saville36469e72014-06-11 15:17:00 -07002151 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 public boolean enableDataConnectivity() {
2154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 int subId = mSubscriptionController.getDefaultDataSubId();
2159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002161 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 return true;
2163 } else {
2164 return false;
2165 }
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Wink Saville36469e72014-06-11 15:17:00 -07002171 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002172 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002173 public boolean disableDataConnectivity() {
2174 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002175
2176 final long identity = Binder.clearCallingIdentity();
2177 try {
2178 int subId = mSubscriptionController.getDefaultDataSubId();
2179 final Phone phone = getPhone(subId);
2180 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002181 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002182 return true;
2183 } else {
2184 return false;
2185 }
2186 } finally {
2187 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 }
2190
Sanket Padawe356d7632015-06-22 14:03:32 -07002191 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002192 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002197 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198 } else {
2199 return false;
2200 }
2201 } finally {
2202 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002203 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002204 }
2205
2206 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002207 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002208 }
2209
pkanwarae03a6b2016-11-06 20:37:09 -08002210 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002211 enforceCallPermission();
2212
2213 final long identity = Binder.clearCallingIdentity();
2214 try {
2215 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2216 return;
2217 }
2218 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2219 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
2222 }
pkanwar32d516d2016-10-14 19:37:38 -07002223 };
2224
Wink Savilleb564aae2014-10-23 10:18:09 -07002225 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002226 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227
2228 final long identity = Binder.clearCallingIdentity();
2229 try {
2230 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2231 return false;
2232 }
2233 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002236 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002237 }
2238
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002239 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002240 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002241 }
2242
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002243 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 Phone phone = PhoneFactory.getPhone(slotIndex);
2247 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2248 PhoneConstantConversions.convertCallState(phone.getState());
2249 } finally {
2250 Binder.restoreCallingIdentity(identity);
2251 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002252 }
2253
Sanket Padawe356d7632015-06-22 14:03:32 -07002254 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002255 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002256 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2257 }
2258
2259 @Override
2260 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002261 final long identity = Binder.clearCallingIdentity();
2262 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002263 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002264 if (phone != null) {
2265 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2266 } else {
2267 return PhoneConstantConversions.convertDataState(
2268 PhoneConstants.DataState.DISCONNECTED);
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
Sanket Padawe356d7632015-06-22 14:03:32 -07002275 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002276 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002277 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2278 }
2279
2280 @Override
2281 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002282 final long identity = Binder.clearCallingIdentity();
2283 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002284 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002285 if (phone != null) {
2286 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2287 } else {
2288 return TelephonyManager.DATA_ACTIVITY_NONE;
2289 }
2290 } finally {
2291 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002292 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002293 }
2294
2295 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002296 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002297 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002298 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002299
2300 LocationAccessPolicy.LocationPermissionResult locationResult =
2301 LocationAccessPolicy.checkLocationPermission(mApp,
2302 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2303 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002304 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002305 .setCallingPid(Binder.getCallingPid())
2306 .setCallingUid(Binder.getCallingUid())
2307 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002308 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002309 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2310 .build());
2311 switch (locationResult) {
2312 case DENIED_HARD:
2313 throw new SecurityException("Not allowed to access cell location");
2314 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002315 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2316 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002317 }
2318
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002319 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002320 final long identity = Binder.clearCallingIdentity();
2321 try {
2322 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002323 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002324 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002325 } finally {
2326 Binder.restoreCallingIdentity(identity);
2327 }
Svetoslav64fad262015-04-14 14:35:21 -07002328 }
2329
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002330 @Override
Jack Yu01425032020-02-22 19:38:58 -08002331 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002332 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2333 // registered cell info, so return a NULL country instead.
2334 final long identity = Binder.clearCallingIdentity();
2335 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002336 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2337 // Get default phone in this case.
2338 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2339 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002340 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002342 if (phone == null) return "";
2343 ServiceStateTracker sst = phone.getServiceStateTracker();
2344 if (sst == null) return "";
2345 LocaleTracker lt = sst.getLocaleTracker();
2346 if (lt == null) return "";
2347 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2348 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2349 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002350 } finally {
2351 Binder.restoreCallingIdentity(identity);
2352 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002353 }
2354
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002355 /**
2356 * This method was removed due to potential issues caused by performing partial
2357 * updates of service state, and lack of a credible use case.
2358 *
2359 * This has the ability to break the telephony implementation by disabling notification of
2360 * changes in device connectivity. DO NOT USE THIS!
2361 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002362 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 public void enableLocationUpdates() {
2364 mApp.enforceCallingOrSelfPermission(
2365 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002366 }
2367
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002368 /**
2369 * This method was removed due to potential issues caused by performing partial
2370 * updates of service state, and lack of a credible use case.
2371 *
2372 * This has the ability to break the telephony implementation by disabling notification of
2373 * changes in device connectivity. DO NOT USE THIS!
2374 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 @Override
2376 public void disableLocationUpdates() {
2377 mApp.enforceCallingOrSelfPermission(
2378 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 }
2380
Nathan Harold31d7ff32018-10-15 20:20:30 -07002381 /**
2382 * Returns the target SDK version number for a given package name.
2383 *
Nathan Haroldec184742019-07-10 17:04:16 -07002384 * This call MUST be invoked before clearing the calling UID.
2385 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002386 * @return target SDK if the package is found or INT_MAX.
2387 */
2388 private int getTargetSdk(String packageName) {
2389 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002390 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002391 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002392 if (ai != null) return ai.targetSdkVersion;
2393 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002394 loge("Failed to get package info for pkg="
2395 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002396 }
2397 return Integer.MAX_VALUE;
2398 }
2399
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002400 @Override
2401 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002402 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2403 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002404 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002405 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2406 throw new SecurityException(
2407 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2408 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002409
Jordan Liu1617b712019-07-10 15:06:26 -07002410 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002411 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2412 return null;
2413 }
Svetoslav64fad262015-04-14 14:35:21 -07002414
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002415 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002417 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002418 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002419
Nathan Haroldf180aac2018-06-01 18:43:55 -07002420 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2421 for (CellInfo ci : info) {
2422 if (ci instanceof CellInfoGsm) {
2423 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2424 } else if (ci instanceof CellInfoWcdma) {
2425 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2426 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002428 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
2430
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002431 private List<CellInfo> getCachedCellInfo() {
2432 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2433 for (Phone phone : PhoneFactory.getPhones()) {
2434 List<CellInfo> info = phone.getAllCellInfo();
2435 if (info != null) cellInfos.addAll(info);
2436 }
2437 return cellInfos;
2438 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002439
2440 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002441 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002442 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002443 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002444
2445 LocationAccessPolicy.LocationPermissionResult locationResult =
2446 LocationAccessPolicy.checkLocationPermission(mApp,
2447 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2448 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002449 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002450 .setCallingPid(Binder.getCallingPid())
2451 .setCallingUid(Binder.getCallingUid())
2452 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002453 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002454 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2455 .build());
2456 switch (locationResult) {
2457 case DENIED_HARD:
2458 throw new SecurityException("Not allowed to access cell info");
2459 case DENIED_SOFT:
2460 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002461 }
2462
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002463 final int targetSdk = getTargetSdk(callingPackage);
2464 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2465 return getCachedCellInfo();
2466 }
2467
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002468 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002469 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002470 final long identity = Binder.clearCallingIdentity();
2471 try {
2472 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2473 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002474 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002475 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002476 if (info != null) cellInfos.addAll(info);
2477 }
2478 return cellInfos;
2479 } finally {
2480 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002481 }
2482 }
2483
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002484 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002485 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2486 String callingFeatureId) {
2487 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2488 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002489 }
2490
2491 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002492 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2493 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002494 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002495 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002496 }
2497
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002498 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2499 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002500 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002501 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002502
2503 LocationAccessPolicy.LocationPermissionResult locationResult =
2504 LocationAccessPolicy.checkLocationPermission(mApp,
2505 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2506 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002507 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002508 .setCallingPid(Binder.getCallingPid())
2509 .setCallingUid(Binder.getCallingUid())
2510 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002511 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2512 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002513 .build());
2514 switch (locationResult) {
2515 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002516 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2517 // Safetynet logging for b/154934934
2518 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2519 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002520 throw new SecurityException("Not allowed to access cell info");
2521 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002522 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2523 // Safetynet logging for b/154934934
2524 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2525 }
Nathan Harold5320c422019-05-09 10:26:08 -07002526 try {
2527 cb.onCellInfo(new ArrayList<CellInfo>());
2528 } catch (RemoteException re) {
2529 // Drop without consequences
2530 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002531 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002532 }
2533
Nathan Harolda939a962019-05-09 10:13:47 -07002534
2535 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002536 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2537
2538 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2539 }
2540
2541 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002543 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002544 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545
2546 final long identity = Binder.clearCallingIdentity();
2547 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002548 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002549 } finally {
2550 Binder.restoreCallingIdentity(identity);
2551 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002552 }
2553
Shishir Agrawala9f32182016-04-12 12:00:16 -07002554 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002555 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 Phone phone = PhoneFactory.getPhone(slotIndex);
2557 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002558 return null;
2559 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002560 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002561 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002562 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002563 return null;
2564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565
2566 final long identity = Binder.clearCallingIdentity();
2567 try {
2568 return phone.getImei();
2569 } finally {
2570 Binder.restoreCallingIdentity(identity);
2571 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002572 }
2573
2574 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002575 public String getTypeAllocationCodeForSlot(int slotIndex) {
2576 Phone phone = PhoneFactory.getPhone(slotIndex);
2577 String tac = null;
2578 if (phone != null) {
2579 String imei = phone.getImei();
2580 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2581 }
2582 return tac;
2583 }
2584
2585 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002586 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002587 Phone phone = PhoneFactory.getPhone(slotIndex);
2588 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002589 return null;
2590 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002591
Jeff Davidson913390f2018-02-23 17:11:49 -08002592 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002593 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002594 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002595 return null;
2596 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002597
2598 final long identity = Binder.clearCallingIdentity();
2599 try {
2600 return phone.getMeid();
2601 } finally {
2602 Binder.restoreCallingIdentity(identity);
2603 }
Jack Yu2af8d712017-03-15 17:14:14 -07002604 }
2605
2606 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002607 public String getManufacturerCodeForSlot(int slotIndex) {
2608 Phone phone = PhoneFactory.getPhone(slotIndex);
2609 String manufacturerCode = null;
2610 if (phone != null) {
2611 String meid = phone.getMeid();
2612 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2613 }
2614 return manufacturerCode;
2615 }
2616
2617 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002618 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2619 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002620 Phone phone = PhoneFactory.getPhone(slotIndex);
2621 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002622 return null;
2623 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002624 int subId = phone.getSubId();
2625 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002626 mApp, subId, callingPackage, callingFeatureId,
2627 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002628 return null;
2629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002630
2631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 return phone.getDeviceSvn();
2634 } finally {
2635 Binder.restoreCallingIdentity(identity);
2636 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002637 }
2638
fionaxu43304da2017-11-27 22:51:16 -08002639 @Override
2640 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002641 final long identity = Binder.clearCallingIdentity();
2642 try {
2643 final Phone phone = getPhone(subId);
2644 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2645 } finally {
2646 Binder.restoreCallingIdentity(identity);
2647 }
fionaxu43304da2017-11-27 22:51:16 -08002648 }
2649
2650 @Override
2651 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002652 final long identity = Binder.clearCallingIdentity();
2653 try {
2654 final Phone phone = getPhone(subId);
2655 return phone == null ? null : phone.getCarrierName();
2656 } finally {
2657 Binder.restoreCallingIdentity(identity);
2658 }
fionaxu43304da2017-11-27 22:51:16 -08002659 }
2660
calvinpanffe225e2018-11-01 19:43:06 +08002661 @Override
chen xu0026ca62019-03-06 15:28:50 -08002662 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002663 final long identity = Binder.clearCallingIdentity();
2664 try {
2665 final Phone phone = getPhone(subId);
2666 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002667 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002668 } finally {
2669 Binder.restoreCallingIdentity(identity);
2670 }
2671 }
2672
2673 @Override
chen xu0026ca62019-03-06 15:28:50 -08002674 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002675 final long identity = Binder.clearCallingIdentity();
2676 try {
2677 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002678 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002679 } finally {
2680 Binder.restoreCallingIdentity(identity);
2681 }
2682 }
2683
chen xu651eec72018-11-11 19:03:44 -08002684 @Override
chen xu864e11c2018-12-06 22:10:03 -08002685 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2686 if (!isSubscriptionMccMnc) {
2687 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2688 }
chen xu651eec72018-11-11 19:03:44 -08002689 final Phone phone = PhoneFactory.getPhone(slotIndex);
2690 if (phone == null) {
2691 return TelephonyManager.UNKNOWN_CARRIER_ID;
2692 }
2693 final long identity = Binder.clearCallingIdentity();
2694 try {
2695 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2696 } finally {
2697 Binder.restoreCallingIdentity(identity);
2698 }
2699 }
2700
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002701 //
2702 // Internal helper methods.
2703 //
2704
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002705 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002706 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2707 *
2708 * @throws SecurityException if the caller does not have the required permission
2709 */
2710 private void enforceModifyPermission() {
2711 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2712 }
2713
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002714 /**
2715 * Make sure the caller is system.
2716 *
2717 * @throws SecurityException if the caller is not system.
2718 */
2719 private void enforceSystemCaller() {
2720 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2721 throw new SecurityException("Caller must be system");
2722 }
2723 }
2724
Shuo Qianf2b2df42019-11-13 17:43:31 -08002725 private void enforceActiveEmergencySessionPermission() {
2726 mApp.enforceCallingOrSelfPermission(
2727 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2728 }
2729
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002730 /**
2731 * Make sure the caller has the CALL_PHONE permission.
2732 *
2733 * @throws SecurityException if the caller does not have the required permission
2734 */
2735 private void enforceCallPermission() {
2736 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2737 }
2738
paulhu423b5f22019-08-23 19:17:33 +08002739 private void enforceSettingsPermission() {
2740 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002741 }
2742
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002743 private String createTelUrl(String number) {
2744 if (TextUtils.isEmpty(number)) {
2745 return null;
2746 }
2747
Jake Hambye994d462014-02-03 13:10:13 -08002748 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002749 }
2750
Ihab Awadf9e92732013-12-05 18:02:52 -08002751 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002752 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2753 }
2754
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002755 private static void logv(String msg) {
2756 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2757 }
2758
Ihab Awadf9e92732013-12-05 18:02:52 -08002759 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2761 }
2762
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002763 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002764 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002765 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002766 }
2767
Sanket Padawe356d7632015-06-22 14:03:32 -07002768 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002769 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002770 final long identity = Binder.clearCallingIdentity();
2771 try {
2772 final Phone phone = PhoneFactory.getPhone(slotIndex);
2773 if (phone == null) {
2774 return PhoneConstants.PHONE_TYPE_NONE;
2775 } else {
2776 return phone.getPhoneType();
2777 }
2778 } finally {
2779 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002780 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002781 }
2782
2783 /**
2784 * Returns the CDMA ERI icon index to display
2785 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002786 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002787 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2788 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2789 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002790 }
2791
Sanket Padawe356d7632015-06-22 14:03:32 -07002792 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002793 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2794 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002795 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002796 mApp, subId, callingPackage, callingFeatureId,
2797 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002798 return -1;
2799 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002800
2801 final long identity = Binder.clearCallingIdentity();
2802 try {
2803 final Phone phone = getPhone(subId);
2804 if (phone != null) {
2805 return phone.getCdmaEriIconIndex();
2806 } else {
2807 return -1;
2808 }
2809 } finally {
2810 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002811 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002812 }
2813
2814 /**
2815 * Returns the CDMA ERI icon mode,
2816 * 0 - ON
2817 * 1 - FLASHING
2818 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002819 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002820 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2821 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2822 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002823 }
2824
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002826 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2827 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002828 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002829 mApp, subId, callingPackage, callingFeatureId,
2830 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002831 return -1;
2832 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002833
2834 final long identity = Binder.clearCallingIdentity();
2835 try {
2836 final Phone phone = getPhone(subId);
2837 if (phone != null) {
2838 return phone.getCdmaEriIconMode();
2839 } else {
2840 return -1;
2841 }
2842 } finally {
2843 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002845 }
2846
2847 /**
2848 * Returns the CDMA ERI text,
2849 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002850 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002851 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2852 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2853 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002854 }
2855
Sanket Padawe356d7632015-06-22 14:03:32 -07002856 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002857 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2858 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002859 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002860 mApp, subId, callingPackage, callingFeatureId,
2861 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002862 return null;
2863 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002864
2865 final long identity = Binder.clearCallingIdentity();
2866 try {
2867 final Phone phone = getPhone(subId);
2868 if (phone != null) {
2869 return phone.getCdmaEriText();
2870 } else {
2871 return null;
2872 }
2873 } finally {
2874 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002875 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002876 }
2877
2878 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002879 * Returns the CDMA MDN.
2880 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002881 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002882 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002883 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2884 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002885
2886 final long identity = Binder.clearCallingIdentity();
2887 try {
2888 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002889 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002890 return phone.getLine1Number();
2891 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002892 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002893 return null;
2894 }
2895 } finally {
2896 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002897 }
2898 }
2899
2900 /**
2901 * Returns the CDMA MIN.
2902 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002903 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002904 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002905 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2906 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907
2908 final long identity = Binder.clearCallingIdentity();
2909 try {
2910 final Phone phone = getPhone(subId);
2911 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2912 return phone.getCdmaMin();
2913 } else {
2914 return null;
2915 }
2916 } finally {
2917 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002918 }
2919 }
2920
Hall Liud892bec2018-11-30 14:51:45 -08002921 @Override
2922 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2923 INumberVerificationCallback callback, String callingPackage) {
2924 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2925 != PERMISSION_GRANTED) {
2926 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2927 }
2928 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2929
2930 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2931 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2932 throw new SecurityException("Calling package must be configured in the device config");
2933 }
2934
2935 if (range == null) {
2936 throw new NullPointerException("Range must be non-null");
2937 }
2938
2939 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002940 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002941
2942 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2943 }
2944
Junda Liuca05d5d2014-08-14 22:36:34 -07002945 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002946 * Returns true if CDMA provisioning needs to run.
2947 */
2948 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002949 final long identity = Binder.clearCallingIdentity();
2950 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002951 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002952 } finally {
2953 Binder.restoreCallingIdentity(identity);
2954 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002955 }
2956
2957 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002958 * Sets the voice mail number of a given subId.
2959 */
2960 @Override
2961 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002962 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2963 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002964
2965 final long identity = Binder.clearCallingIdentity();
2966 try {
2967 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2968 new Pair<String, String>(alphaTag, number), new Integer(subId));
2969 return success;
2970 } finally {
2971 Binder.restoreCallingIdentity(identity);
2972 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002973 }
2974
Ta-wei Yen87c49842016-05-13 21:19:52 -07002975 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002976 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2977 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002978 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2979 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002980 if (!TextUtils.equals(callingPackage, systemDialer)) {
2981 throw new SecurityException("caller must be system dialer");
2982 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002983
2984 final long identity = Binder.clearCallingIdentity();
2985 try {
2986 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2987 if (phoneAccountHandle == null) {
2988 return null;
2989 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002990 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002991 } finally {
2992 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002993 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002994 }
2995
2996 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002997 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2998 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002999 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003001 mApp, subId, callingPackage, callingFeatureId,
3002 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003003 return null;
3004 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003006 final long identity = Binder.clearCallingIdentity();
3007 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003008 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003009 } finally {
3010 Binder.restoreCallingIdentity(identity);
3011 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003012 }
3013
3014 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003015 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3016 VisualVoicemailSmsFilterSettings settings) {
3017 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003018
3019 final long identity = Binder.clearCallingIdentity();
3020 try {
3021 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003026 }
3027
3028 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003029 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3030 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003031
3032 final long identity = Binder.clearCallingIdentity();
3033 try {
3034 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003035 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003036 } finally {
3037 Binder.restoreCallingIdentity(identity);
3038 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003039 }
3040
3041 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003042 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3043 String callingPackage, int subId) {
3044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003053 }
3054
3055 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003056 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003057 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003058
3059 final long identity = Binder.clearCallingIdentity();
3060 try {
3061 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003062 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003063 } finally {
3064 Binder.restoreCallingIdentity(identity);
3065 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003066 }
3067
3068 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003069 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3070 String callingAttributionTag, int subId, String number, int port, String text,
3071 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003072 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003073 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003074 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003075 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003076 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3077 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003078 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003079
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003080 /**
fionaxu0152e512016-11-14 13:36:14 -08003081 * Sets the voice activation state of a given subId.
3082 */
3083 @Override
3084 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003085 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3086 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003087
3088 final long identity = Binder.clearCallingIdentity();
3089 try {
3090 final Phone phone = getPhone(subId);
3091 if (phone != null) {
3092 phone.setVoiceActivationState(activationState);
3093 } else {
3094 loge("setVoiceActivationState fails with invalid subId: " + subId);
3095 }
3096 } finally {
3097 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003098 }
3099 }
3100
3101 /**
3102 * Sets the data activation state of a given subId.
3103 */
3104 @Override
3105 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003106 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3107 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003108
3109 final long identity = Binder.clearCallingIdentity();
3110 try {
3111 final Phone phone = getPhone(subId);
3112 if (phone != null) {
3113 phone.setDataActivationState(activationState);
3114 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003115 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003116 }
3117 } finally {
3118 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003119 }
3120 }
3121
3122 /**
3123 * Returns the voice activation state of a given subId.
3124 */
3125 @Override
3126 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003127 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003128
fionaxu0152e512016-11-14 13:36:14 -08003129 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 final long identity = Binder.clearCallingIdentity();
3131 try {
3132 if (phone != null) {
3133 return phone.getVoiceActivationState();
3134 } else {
3135 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3136 }
3137 } finally {
3138 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003139 }
3140 }
3141
3142 /**
3143 * Returns the data activation state of a given subId.
3144 */
3145 @Override
3146 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003147 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003148
fionaxu0152e512016-11-14 13:36:14 -08003149 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150 final long identity = Binder.clearCallingIdentity();
3151 try {
3152 if (phone != null) {
3153 return phone.getDataActivationState();
3154 } else {
3155 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3156 }
3157 } finally {
3158 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003159 }
3160 }
3161
3162 /**
Wink Saville36469e72014-06-11 15:17:00 -07003163 * Returns the unread count of voicemails for a subId
3164 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003165 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003166 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3167 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003168 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003169 mApp, subId, callingPackage, callingFeatureId,
3170 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003171 return 0;
3172 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003173 final long identity = Binder.clearCallingIdentity();
3174 try {
3175 final Phone phone = getPhone(subId);
3176 if (phone != null) {
3177 return phone.getVoiceMessageCount();
3178 } else {
3179 return 0;
3180 }
3181 } finally {
3182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003184 }
3185
3186 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003187 * returns true, if the device is in a state where both voice and data
3188 * are supported simultaneously. This can change based on location or network condition.
3189 */
3190 @Override
3191 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003192 final long identity = Binder.clearCallingIdentity();
3193 try {
3194 final Phone phone = getPhone(subId);
3195 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3196 } finally {
3197 Binder.restoreCallingIdentity(identity);
3198 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003199 }
3200
3201 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003202 * Send the dialer code if called from the current default dialer or the caller has
3203 * carrier privilege.
3204 * @param inputCode The dialer code to send
3205 */
3206 @Override
3207 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003208 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003209 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003210 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3211 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003212 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003213 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003214 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216
3217 final long identity = Binder.clearCallingIdentity();
3218 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003219 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003220 } finally {
3221 Binder.restoreCallingIdentity(identity);
3222 }
fionaxu235cc5e2017-03-06 22:25:57 -08003223 }
3224
Pengquan Menga1bb6272018-09-06 09:59:22 -07003225 @Override
3226 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003227 TelephonyPermissions
3228 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3229 mApp, subId, "getNetworkSelectionMode");
3230 final long identity = Binder.clearCallingIdentity();
3231 try {
3232 if (!isActiveSubscription(subId)) {
3233 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3234 }
3235 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3236 } finally {
3237 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003238 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003239 }
3240
Brad Ebinger35c841c2018-10-01 10:40:55 -07003241 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003242 public boolean isInEmergencySmsMode() {
3243 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 for (Phone phone : PhoneFactory.getPhones()) {
3247 if (phone.isInEmergencySmsMode()) {
3248 return true;
3249 }
3250 }
3251 } finally {
3252 Binder.restoreCallingIdentity(identity);
3253 }
3254 return false;
3255 }
3256
shilu366312e2019-12-17 09:28:10 -08003257 /**
3258 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3259 * @param subId The subscription to use to check the configuration.
3260 * @param c The callback that will be used to send the result.
3261 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003262 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003263 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3264 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003265 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3266 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003267
Brad Ebinger77b832e2019-10-17 17:03:22 -07003268 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3269 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3270 "IMS not available on device.");
3271 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 final long token = Binder.clearCallingIdentity();
3273 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003274 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003275 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003276 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003277 } catch (ImsException e) {
3278 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 } finally {
3280 Binder.restoreCallingIdentity(token);
3281 }
3282 }
3283
shilu366312e2019-12-17 09:28:10 -08003284 /**
3285 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3286 * @param subId The subscription to use to check the configuration.
3287 * @param c The callback that will be used to send the result.
3288 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003289 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003290 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003291 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3292 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003293 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3294 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3295 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003296 final long token = Binder.clearCallingIdentity();
3297 try {
3298 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3299 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3300 .removeRegistrationCallbackForSubscription(c, subId);
3301 } catch (ImsException e) {
3302 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3303 + "is inactive, ignoring unregister.");
3304 // If the subscription is no longer active, just return, since the callback
3305 // will already have been removed internally.
3306 } finally {
3307 Binder.restoreCallingIdentity(token);
3308 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003309 }
3310
Brad Ebinger774ba362019-10-22 17:36:18 -07003311 /**
3312 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3313 */
3314 @Override
3315 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3316 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3317 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3318 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3319 "IMS not available on device.");
3320 }
3321 final long token = Binder.clearCallingIdentity();
3322 try {
3323 Phone phone = getPhone(subId);
3324 if (phone == null) {
3325 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3326 + subId + "'");
3327 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3328 }
3329 phone.getImsRegistrationState(regState -> {
3330 try {
3331 consumer.accept((regState == null)
3332 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3333 } catch (RemoteException e) {
3334 // Ignore if the remote process is no longer available to call back.
3335 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3336 }
3337 });
3338 } finally {
3339 Binder.restoreCallingIdentity(token);
3340 }
3341 }
3342
3343 /**
3344 * Get the transport type for the IMS service registration state.
3345 */
3346 @Override
3347 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003348 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3349 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003350 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3351 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3352 "IMS not available on device.");
3353 }
3354 final long token = Binder.clearCallingIdentity();
3355 try {
3356 Phone phone = getPhone(subId);
3357 if (phone == null) {
3358 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3359 + subId + "'");
3360 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3361 }
3362 phone.getImsRegistrationTech(regTech -> {
3363 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3364 int regTechConverted = (regTech == null)
3365 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3366 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3367 regTechConverted);
3368 try {
3369 consumer.accept(regTechConverted);
3370 } catch (RemoteException e) {
3371 // Ignore if the remote process is no longer available to call back.
3372 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3373 }
3374 });
3375 } finally {
3376 Binder.restoreCallingIdentity(token);
3377 }
3378 }
3379
shilu366312e2019-12-17 09:28:10 -08003380 /**
3381 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3382 * @param subId The subscription to use to check the configuration.
3383 * @param c The callback that will be used to send the result.
3384 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003385 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003386 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3387 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003388 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3389 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003390 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3391 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3392 "IMS not available on device.");
3393 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3395 final long token = Binder.clearCallingIdentity();
3396 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003397 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003398 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003399 } catch (ImsException e) {
3400 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 } finally {
3402 Binder.restoreCallingIdentity(token);
3403 }
3404 }
3405
shilu366312e2019-12-17 09:28:10 -08003406 /**
3407 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3408 * @param subId The subscription to use to check the configuration.
3409 * @param c The callback that will be used to send the result.
3410 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003411 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003412 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003413 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3414 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003415 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3416 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3417 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003418
3419 final long token = Binder.clearCallingIdentity();
3420 try {
3421 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3422 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003423 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003424 } catch (ImsException e) {
3425 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3426 + "is inactive, ignoring unregister.");
3427 // If the subscription is no longer active, just return, since the callback
3428 // will already have been removed internally.
3429 } finally {
3430 Binder.restoreCallingIdentity(token);
3431 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003432 }
3433
3434 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003435 public boolean isCapable(int subId, int capability, int regTech) {
3436 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3438 final long token = Binder.clearCallingIdentity();
3439 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003440 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003441 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003442 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3444 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003445 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003446 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3447 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 } finally {
3449 Binder.restoreCallingIdentity(token);
3450 }
3451 }
3452
3453 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003454 public boolean isAvailable(int subId, int capability, int regTech) {
3455 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003456 final long token = Binder.clearCallingIdentity();
3457 try {
3458 Phone phone = getPhone(subId);
3459 if (phone == null) return false;
3460 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003461 } catch (com.android.ims.ImsException e) {
3462 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3463 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 } finally {
3465 Binder.restoreCallingIdentity(token);
3466 }
3467 }
3468
Brad Ebinger77b832e2019-10-17 17:03:22 -07003469 /**
3470 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3471 * subscription.
3472 * @param subId The subscription to use to check the configuration.
3473 * @param callback The callback that will be used to send the result.
3474 * @param capability The MmTelFeature capability that will be used to send the result.
3475 * @param transportType The transport type of the MmTelFeature capability.
3476 */
3477 @Override
3478 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3479 int transportType) {
3480 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3481 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3482 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3483 "IMS not available on device.");
3484 }
3485 final long token = Binder.clearCallingIdentity();
3486 try {
3487 int slotId = getSlotIndex(subId);
3488 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3489 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3490 + subId + "'");
3491 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3492 }
3493 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3494 transportType, aBoolean -> {
3495 try {
3496 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3497 } catch (RemoteException e) {
3498 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3499 + "running. Ignore");
3500 }
3501 });
3502 } finally {
3503 Binder.restoreCallingIdentity(token);
3504 }
3505 }
3506
shilu366312e2019-12-17 09:28:10 -08003507 /**
3508 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3509 * @param subId The subscription to use to check the configuration.
3510 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003511 @Override
3512 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003513 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3514 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003515
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3517 final long token = Binder.clearCallingIdentity();
3518 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003519 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003521 } catch (ImsException e) {
3522 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003523 } finally {
3524 Binder.restoreCallingIdentity(token);
3525 }
3526 }
3527
3528 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003529 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003531 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 final long identity = Binder.clearCallingIdentity();
3533 try {
3534 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
3538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 } finally {
3540 Binder.restoreCallingIdentity(identity);
3541 }
3542 }
3543
shilu366312e2019-12-17 09:28:10 -08003544 /**
3545 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3546 * @param subId The subscription to use to check the configuration.
3547 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003549 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003550 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3551 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 final long identity = Binder.clearCallingIdentity();
3553 try {
3554 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003555 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3556 } catch (ImsException e) {
3557 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003558 } finally {
3559 Binder.restoreCallingIdentity(identity);
3560 }
3561 }
3562
3563 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003564 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003565 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003566 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 final long identity = Binder.clearCallingIdentity();
3568 try {
3569 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003570 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 } catch (ImsException e) {
3572 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003573 } finally {
3574 Binder.restoreCallingIdentity(identity);
3575 }
3576 }
3577
shilu366312e2019-12-17 09:28:10 -08003578 /**
3579 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3580 * @param subId The subscription to use to check the configuration.
3581 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 @Override
3583 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003584 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3585 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 final long identity = Binder.clearCallingIdentity();
3587 try {
3588 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003589 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003591 } catch (ImsException e) {
3592 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003593 } finally {
3594 Binder.restoreCallingIdentity(identity);
3595 }
3596 }
3597
3598 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003599 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003601 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003606 } catch (ImsException e) {
3607 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003608 } finally {
3609 Binder.restoreCallingIdentity(identity);
3610 }
3611 }
3612
shilu366312e2019-12-17 09:28:10 -08003613 /**
3614 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3615 * @param subId The subscription to use to check the configuration.
3616 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 @Override
3618 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003619 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3620 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 final long identity = Binder.clearCallingIdentity();
3622 try {
3623 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003624 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003626 } catch (ImsException e) {
3627 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003628 } finally {
3629 Binder.restoreCallingIdentity(identity);
3630 }
3631 }
3632
3633 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003634 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003636 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003642 } catch (ImsException e) {
3643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
3647 }
3648
3649 @Override
3650 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3652 "setVoWiFiNonPersistent");
3653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003657 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003658 } catch (ImsException e) {
3659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
3663 }
3664
shilu366312e2019-12-17 09:28:10 -08003665 /**
3666 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3667 * @param subId The subscription to use to check the configuration.
3668 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 @Override
3670 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003671 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3672 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 final long identity = Binder.clearCallingIdentity();
3674 try {
3675 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003676 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003677 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003678 } catch (ImsException e) {
3679 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003680 } finally {
3681 Binder.restoreCallingIdentity(identity);
3682 }
3683 }
3684
3685 @Override
3686 public void setVoWiFiModeSetting(int subId, int mode) {
3687 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3688 "setVoWiFiModeSetting");
3689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public int getVoWiFiRoamingModeSetting(int subId) {
3703 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3704 final long identity = Binder.clearCallingIdentity();
3705 try {
3706 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003707 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003708 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003709 } catch (ImsException e) {
3710 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003711 } finally {
3712 Binder.restoreCallingIdentity(identity);
3713 }
3714 }
3715
3716 @Override
3717 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3718 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3719 "setVoWiFiRoamingModeSetting");
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3735 "setRttCapabilityEnabled");
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003739 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3740 } catch (ImsException e) {
3741 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003742 } finally {
3743 Binder.restoreCallingIdentity(identity);
3744 }
3745 }
3746
shilu366312e2019-12-17 09:28:10 -08003747 /**
3748 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3749 * @param subId The subscription to use to check the configuration.
3750 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 @Override
3752 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003753 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3754 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 final long identity = Binder.clearCallingIdentity();
3756 try {
3757 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003758 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003759 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003760 } catch (ImsException e) {
3761 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003762 } finally {
3763 Binder.restoreCallingIdentity(identity);
3764 }
3765 }
3766
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003767 @Override
3768 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3769 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3770 final long identity = Binder.clearCallingIdentity();
3771 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003772 if (!isImsAvailableOnDevice()) {
3773 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3774 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003775 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003776 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003777 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003778 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003779 } catch (ImsException e) {
3780 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003781 } finally {
3782 Binder.restoreCallingIdentity(identity);
3783 }
3784 }
3785
3786 @Override
3787 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3788 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3789 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003790 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3791 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3792 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003793 try {
3794 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003795 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003796 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003797 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003798 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3799 + "is inactive, ignoring unregister.");
3800 // If the subscription is no longer active, just return, since the callback will already
3801 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003802 } finally {
3803 Binder.restoreCallingIdentity(identity);
3804 }
3805 }
3806
allenwtsu99c623b2020-01-03 18:24:23 +08003807
3808 private void checkModifyPhoneStatePermission(int subId, String message) {
3809 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3810 message);
3811 }
3812
3813 private boolean isImsProvisioningRequired(int subId, int capability,
3814 boolean isMmtelCapability) {
3815 Phone phone = getPhone(subId);
3816 if (phone == null) {
3817 loge("phone instance null for subid " + subId);
3818 return false;
3819 }
3820 if (isMmtelCapability) {
3821 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3822 return false;
3823 }
3824 } else {
3825 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3826 return false;
3827 }
3828 }
3829 return true;
3830 }
3831
3832 @Override
3833 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3834 boolean isProvisioned) {
3835 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3836
3837 final long identity = Binder.clearCallingIdentity();
3838 try {
3839 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3840 if (!isImsProvisioningRequired(subId, capability, false)) {
3841 return;
3842 }
3843
3844 // this capability requires provisioning, route to the correct API.
3845 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3846 switch (capability) {
3847 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3848 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3849 ims.setEabProvisioned(isProvisioned);
3850 break;
3851 default: {
3852 throw new IllegalArgumentException("Tried to set provisioning for "
3853 + "rcs capability '" + capability + "', which does not require "
3854 + "provisioning.");
3855 }
3856 }
3857 } finally {
3858 Binder.restoreCallingIdentity(identity);
3859 }
3860
3861 }
3862
3863
3864 @Override
3865 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3866 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3867 final long identity = Binder.clearCallingIdentity();
3868 try {
3869 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3870 if (!isImsProvisioningRequired(subId, capability, false)) {
3871 return true;
3872 }
3873
3874 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3875 switch (capability) {
3876 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3877 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3878 return ims.isEabProvisionedOnDevice();
3879
3880 default: {
3881 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3882 + "capability '" + capability + "', which does not require "
3883 + "provisioning.");
3884 }
3885 }
3886
3887 } finally {
3888 Binder.restoreCallingIdentity(identity);
3889 }
3890 }
3891
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003892 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003893 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3894 boolean isProvisioned) {
3895 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3896 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3897 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3898 }
allenwtsu99c623b2020-01-03 18:24:23 +08003899 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003900 final long identity = Binder.clearCallingIdentity();
3901 try {
3902 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003903 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003904 return;
3905 }
3906
3907 // this capability requires provisioning, route to the correct API.
3908 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3909 switch (capability) {
3910 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3911 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3912 ims.setVolteProvisioned(isProvisioned);
3913 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3914 ims.setWfcProvisioned(isProvisioned);
3915 }
3916 break;
3917 }
3918 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3919 // There is currently no difference in VT provisioning type.
3920 ims.setVtProvisioned(isProvisioned);
3921 break;
3922 }
3923 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3924 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3925 // change the capability of the feature instead if needed.
3926 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3927 == isProvisioned) {
3928 // No change in provisioning.
3929 return;
3930 }
3931 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3932 try {
3933 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003934 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003935 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3936 + ", Exception" + e.getMessage());
3937 }
3938 break;
3939 }
3940 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003941 throw new IllegalArgumentException("Tried to set provisioning for "
3942 + "MmTel capability '" + capability + "', which does not require "
3943 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003944 }
3945 }
3946
3947 } finally {
3948 Binder.restoreCallingIdentity(identity);
3949 }
3950 }
3951
3952 @Override
3953 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3954 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3955 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3956 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3957 }
3958 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3959 final long identity = Binder.clearCallingIdentity();
3960 try {
3961 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003962 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003963 return true;
3964 }
3965
3966 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3967 switch (capability) {
3968 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3969 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3970 return ims.isVolteProvisionedOnDevice();
3971 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3972 return ims.isWfcProvisionedOnDevice();
3973 }
3974 // This should never happen, since we are checking tech above to make sure it
3975 // is either LTE or IWLAN.
3976 throw new IllegalArgumentException("Invalid radio technology for voice "
3977 + "capability.");
3978 }
3979 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3980 // There is currently no difference in VT provisioning type.
3981 return ims.isVtProvisionedOnDevice();
3982 }
3983 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3984 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3985 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3986 }
3987 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003988 throw new IllegalArgumentException(
3989 "Tried to get provisioning for MmTel capability '" + capability
3990 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003991 }
3992 }
3993
3994 } finally {
3995 Binder.restoreCallingIdentity(identity);
3996 }
3997 }
3998
3999 @Override
4000 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4001 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4002 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4003 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4004 }
4005 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4006 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4007 return (provisionedBits & capability) > 0;
4008 }
4009
4010 @Override
4011 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4012 boolean isProvisioned) {
4013 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4014 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4015 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4016 }
4017 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4018 "setProvisioningStatusForCapability");
4019 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4020 // If the current provisioning status for capability already matches isProvisioned,
4021 // do nothing.
4022 if (((provisionedBits & capability) > 0) == isProvisioned) {
4023 return;
4024 }
4025 if (isProvisioned) {
4026 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4027 } else {
4028 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4029 }
4030 }
4031
4032 /**
4033 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4034 * technology. The bitfield should mirror the bitfield defined by
4035 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4036 */
4037 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4038 String key = getMmTelProvisioningKey(subId, tech);
4039 // Default is no capabilities are provisioned.
4040 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4041 }
4042
4043 /**
4044 * Sets the MmTel capability provisioning bitfield (defined by
4045 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4046 * technology specified.
4047 *
4048 * Note: This is a synchronous command and should not be called on UI thread.
4049 */
4050 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4051 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4052 String key = getMmTelProvisioningKey(subId, tech);
4053 editor.putInt(key, newField);
4054 editor.commit();
4055 }
4056
4057 private static String getMmTelProvisioningKey(int subId, int tech) {
4058 // resulting key is provision_ims_mmtel_{subId}_{tech}
4059 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4060 }
4061
4062 /**
4063 * Query CarrierConfig to see if the specified capability requires provisioning for the
4064 * carrier associated with the subscription id.
4065 */
4066 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4067 int capability) {
4068 CarrierConfigManager configManager = new CarrierConfigManager(context);
4069 PersistableBundle c = configManager.getConfigForSubId(subId);
4070 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004071 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004072 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4073 false);
4074 boolean requireVoiceVtProvisioning = c.getBoolean(
4075 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4076
4077 // First check to make sure that the capability requires provisioning.
4078 switch (capability) {
4079 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4080 // intentional fallthrough
4081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4082 if (requireVoiceVtProvisioning) {
4083 // Voice and Video requires provisioning
4084 return true;
4085 }
4086 break;
4087 }
4088 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4089 if (requireUtProvisioning) {
4090 // UT requires provisioning
4091 return true;
4092 }
4093 break;
4094 }
4095 }
4096 return false;
4097 }
4098
allenwtsu99c623b2020-01-03 18:24:23 +08004099 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4100 int capability) {
4101 CarrierConfigManager configManager = new CarrierConfigManager(context);
4102 PersistableBundle c = configManager.getConfigForSubId(subId);
4103
4104 boolean requireRcsProvisioning = c.getBoolean(
4105 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4106
4107 // First check to make sure that the capability requires provisioning.
4108 switch (capability) {
4109 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4110 // intentional fallthrough
4111 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4112 if (requireRcsProvisioning) {
4113 // OPTION or PRESENCE requires provisioning
4114 return true;
4115 }
4116 break;
4117 }
4118 }
4119 return false;
4120 }
4121
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004122 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004123 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4125 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4126 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004127 enforceReadPrivilegedPermission("getImsProvisioningInt");
4128 final long identity = Binder.clearCallingIdentity();
4129 try {
4130 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004131 int slotId = getSlotIndex(subId);
4132 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4133 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4134 + subId + "' for key:" + key);
4135 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4136 }
4137 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004138 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4140 + subId + "' for key:" + key);
4141 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004142 } finally {
4143 Binder.restoreCallingIdentity(identity);
4144 }
4145 }
4146
4147 @Override
4148 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004149 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4150 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4151 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004152 enforceReadPrivilegedPermission("getImsProvisioningString");
4153 final long identity = Binder.clearCallingIdentity();
4154 try {
4155 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004156 int slotId = getSlotIndex(subId);
4157 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4158 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4159 + subId + "' for key:" + key);
4160 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4161 }
4162 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004163 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004164 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4165 + subId + "' for key:" + key);
4166 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004167 } finally {
4168 Binder.restoreCallingIdentity(identity);
4169 }
4170 }
4171
4172 @Override
4173 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004174 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4175 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4176 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004177 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4178 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004179 final long identity = Binder.clearCallingIdentity();
4180 try {
4181 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004182 int slotId = getSlotIndex(subId);
4183 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4184 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4185 + subId + "' for key:" + key);
4186 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4187 }
4188 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004189 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4191 + "' for key:" + key);
4192 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 } finally {
4194 Binder.restoreCallingIdentity(identity);
4195 }
4196 }
4197
4198 @Override
4199 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004200 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4201 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4202 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4204 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004205 final long identity = Binder.clearCallingIdentity();
4206 try {
4207 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004208 int slotId = getSlotIndex(subId);
4209 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4210 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4211 + subId + "' for key:" + key);
4212 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4213 }
4214 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004215 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4217 + "' for key:" + key);
4218 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 } finally {
4220 Binder.restoreCallingIdentity(identity);
4221 }
4222 }
4223
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004224 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 int slotId = SubscriptionManager.getSlotIndex(subId);
4226 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004227 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4228 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004229 }
4230 return slotId;
4231 }
4232
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004233 private int getSlotIndex(int subId) {
4234 int slotId = SubscriptionManager.getSlotIndex(subId);
4235 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4236 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4237 }
4238 return slotId;
4239 }
4240
Wink Saville36469e72014-06-11 15:17:00 -07004241 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004242 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004243 */
4244 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004245 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4246 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004247 final int targetSdk = getTargetSdk(callingPackage);
4248 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004249 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004250 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004251 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004252 mApp, subId, callingPackage, callingFeatureId,
4253 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004254 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4255 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004256
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004257 final long identity = Binder.clearCallingIdentity();
4258 try {
4259 final Phone phone = getPhone(subId);
4260 if (phone != null) {
4261 return phone.getServiceState().getDataNetworkType();
4262 } else {
4263 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4264 }
4265 } finally {
4266 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004268 }
4269
4270 /**
4271 * Returns the data network type
4272 */
4273 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004274 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4275 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4276 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004277 }
4278
4279 /**
4280 * Returns the data network type for a subId
4281 */
4282 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004283 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4284 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004285 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004286 mApp, subId, callingPackage, callingFeatureId,
4287 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004288 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4289 }
4290
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004291 final long identity = Binder.clearCallingIdentity();
4292 try {
4293 final Phone phone = getPhone(subId);
4294 if (phone != null) {
4295 return phone.getServiceState().getDataNetworkType();
4296 } else {
4297 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4298 }
4299 } finally {
4300 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004301 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004302 }
4303
4304 /**
Wink Saville36469e72014-06-11 15:17:00 -07004305 * Returns the Voice network type for a subId
4306 */
4307 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004308 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4309 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004310 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004311 mApp, subId, callingPackage, callingFeatureId,
4312 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004313 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4314 }
4315
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004316 final long identity = Binder.clearCallingIdentity();
4317 try {
4318 final Phone phone = getPhone(subId);
4319 if (phone != null) {
4320 return phone.getServiceState().getVoiceNetworkType();
4321 } else {
4322 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4323 }
4324 } finally {
4325 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004326 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004327 }
4328
4329 /**
4330 * @return true if a ICC card is present
4331 */
4332 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004333 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004334 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4335 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004336 }
4337
4338 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004339 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004340 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004341 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004342 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004343 final long identity = Binder.clearCallingIdentity();
4344 try {
4345 final Phone phone = PhoneFactory.getPhone(slotIndex);
4346 if (phone != null) {
4347 return phone.getIccCard().hasIccCard();
4348 } else {
4349 return false;
4350 }
4351 } finally {
4352 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004354 }
4355
4356 /**
4357 * Return if the current radio is LTE on CDMA. This
4358 * is a tri-state return value as for a period of time
4359 * the mode may be unknown.
4360 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004361 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004362 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004363 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004364 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004365 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004366 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4367 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4368 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004369 }
4370
Sanket Padawe356d7632015-06-22 14:03:32 -07004371 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004372 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4373 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004374 try {
4375 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4376 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004377 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4378 }
4379
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004380 final long identity = Binder.clearCallingIdentity();
4381 try {
4382 final Phone phone = getPhone(subId);
4383 if (phone == null) {
4384 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4385 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004386 return TelephonyProperties.lte_on_cdma_device()
4387 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004388 }
4389 } finally {
4390 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004391 }
Wink Saville36469e72014-06-11 15:17:00 -07004392 }
4393
Wink Saville36469e72014-06-11 15:17:00 -07004394 /**
4395 * {@hide}
4396 * Returns Default subId, 0 in the case of single standby.
4397 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004398 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004399 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004400 }
4401
Shishir Agrawala9f32182016-04-12 12:00:16 -07004402 private int getSlotForDefaultSubscription() {
4403 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4404 }
4405
Wink Savilleb564aae2014-10-23 10:18:09 -07004406 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004407 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004408 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004409
Pengquan Menge92a50d2018-09-21 15:54:48 -07004410 private boolean isActiveSubscription(int subId) {
4411 return mSubscriptionController.isActiveSubId(subId);
4412 }
4413
Ihab Awadf2177b72013-11-25 13:33:23 -08004414 /**
4415 * @see android.telephony.TelephonyManager.WifiCallingChoices
4416 */
4417 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004418 final long identity = Binder.clearCallingIdentity();
4419 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004420 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004421 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4422 getWhenToMakeWifiCallsDefaultPreference());
4423 } finally {
4424 Binder.restoreCallingIdentity(identity);
4425 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004426 }
4427
4428 /**
4429 * @see android.telephony.TelephonyManager.WifiCallingChoices
4430 */
4431 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 final long identity = Binder.clearCallingIdentity();
4433 try {
4434 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004435 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004436 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004440 }
4441
Sailesh Nepald1e68152013-12-12 19:08:02 -08004442 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004443 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004444 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004445 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004446
Jordan Liu4c733742019-02-28 12:03:40 -08004447 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4448 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4449 if (phoneId == -1) {
4450 throw new IllegalArgumentException("Given slot index: " + slotIndex
4451 + " does not correspond to an active phone");
4452 }
4453 return PhoneFactory.getPhone(phoneId);
4454 }
4455
Shishir Agrawal566b7612013-10-28 14:41:00 -07004456 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004457 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4458 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004459 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4460 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004461 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004462 if (DBG) {
4463 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4464 }
4465 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4466 p2);
4467 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004468
Jordan Liu4c733742019-02-28 12:03:40 -08004469
4470 @Override
4471 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4472 int slotIndex, String callingPackage, String aid, int p2) {
4473 enforceModifyPermission();
4474 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4475 if (DBG) {
4476 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4477 }
4478 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4479 callingPackage, aid, p2);
4480 }
4481
4482 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4483 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004484 final long identity = Binder.clearCallingIdentity();
4485 try {
4486 if (TextUtils.equals(ISDR_AID, aid)) {
4487 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004488 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4489 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004490 if (bestComponent == null
4491 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4492 loge("The calling package is not allowed to access ISD-R.");
4493 throw new SecurityException(
4494 "The calling package is not allowed to access ISD-R.");
4495 }
Derek Tan740e1672017-06-27 14:56:27 -07004496 }
Derek Tan740e1672017-06-27 14:56:27 -07004497
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004499 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4500 null /* workSource */);
4501 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004502 return response;
4503 } finally {
4504 Binder.restoreCallingIdentity(identity);
4505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004506 }
4507
4508 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004509 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004510 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4511 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004512 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4513 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4514 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004515
Jordan Liu4c733742019-02-28 12:03:40 -08004516 @Override
4517 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4518 enforceModifyPermission();
4519 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4520 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4521 channel);
4522 }
4523
4524 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004525 final long identity = Binder.clearCallingIdentity();
4526 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004527 if (channel < 0) {
4528 return false;
4529 }
Jordan Liu4c733742019-02-28 12:03:40 -08004530 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4531 null /* workSource */);
4532 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004533 return success;
4534 } finally {
4535 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004537 }
4538
4539 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004540 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004541 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004542 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4543 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004544 if (DBG) {
4545 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4546 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4547 + p3 + " data=" + data);
4548 }
4549 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4550 command, p1, p2, p3, data);
4551 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004552
Jordan Liu4c733742019-02-28 12:03:40 -08004553 @Override
4554 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4555 int command, int p1, int p2, int p3, String data) {
4556 enforceModifyPermission();
4557 if (DBG) {
4558 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4559 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4560 + p3 + " data=" + data);
4561 }
4562 return iccTransmitApduLogicalChannelWithPermission(
4563 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4564 data);
4565 }
4566
4567 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4568 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004569 final long identity = Binder.clearCallingIdentity();
4570 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004571 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004572 return "";
4573 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004576 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4577 null /* workSource */);
4578 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004580 // Append the returned status code to the end of the response payload.
4581 String s = Integer.toHexString(
4582 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4583 if (response.payload != null) {
4584 s = IccUtils.bytesToHexString(response.payload) + s;
4585 }
4586 return s;
4587 } finally {
4588 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004590 }
Jake Hambye994d462014-02-03 13:10:13 -08004591
Evan Charltonc66da362014-05-16 14:06:40 -07004592 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004593 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4594 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004595 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4596 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004597 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004598 if (DBG) {
4599 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4600 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4601 }
4602 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4603 cla, command, p1, p2, p3, data);
4604 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004605
Jordan Liu4c733742019-02-28 12:03:40 -08004606 @Override
4607 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4608 int command, int p1, int p2, int p3, String data) {
4609 enforceModifyPermission();
4610 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4611 if (DBG) {
4612 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4613 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4614 + " data=" + data);
4615 }
4616
4617 return iccTransmitApduBasicChannelWithPermission(
4618 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4619 p2, p3, data);
4620 }
4621
4622 // open APDU basic channel assuming the caller has sufficient permissions
4623 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4624 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004625 final long identity = Binder.clearCallingIdentity();
4626 try {
4627 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4628 && TextUtils.equals(ISDR_AID, data)) {
4629 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004630 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4631 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004632 if (bestComponent == null
4633 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4634 loge("The calling package is not allowed to select ISD-R.");
4635 throw new SecurityException(
4636 "The calling package is not allowed to select ISD-R.");
4637 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004638 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004641 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4642 null /* workSource */);
4643 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004644
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004645 // Append the returned status code to the end of the response payload.
4646 String s = Integer.toHexString(
4647 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4648 if (response.payload != null) {
4649 s = IccUtils.bytesToHexString(response.payload) + s;
4650 }
4651 return s;
4652 } finally {
4653 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004654 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004655 }
4656
4657 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004658 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004659 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004660 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4661 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004662
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004663 final long identity = Binder.clearCallingIdentity();
4664 try {
4665 if (DBG) {
4666 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4667 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4668 }
4669
4670 IccIoResult response =
4671 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4672 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4673 subId);
4674
4675 if (DBG) {
4676 log("Exchange SIM_IO [R]" + response);
4677 }
4678
4679 byte[] result = null;
4680 int length = 2;
4681 if (response.payload != null) {
4682 length = 2 + response.payload.length;
4683 result = new byte[length];
4684 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4685 } else {
4686 result = new byte[length];
4687 }
4688
4689 result[length - 1] = (byte) response.sw2;
4690 result[length - 2] = (byte) response.sw1;
4691 return result;
4692 } finally {
4693 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004694 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004695 }
4696
Nathan Haroldb3014052017-01-25 15:57:32 -08004697 /**
4698 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4699 * on a particular subscription
4700 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004701 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4702 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004703 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004704 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004705 return null;
4706 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004707
4708 final long identity = Binder.clearCallingIdentity();
4709 try {
4710 if (appType != TelephonyManager.APPTYPE_USIM
4711 && appType != TelephonyManager.APPTYPE_SIM) {
4712 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4713 return null;
4714 }
4715 Object response = sendRequest(
4716 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4717 if (response instanceof String[]) {
4718 return (String[]) response;
4719 }
yincheng zhaod698b842019-09-06 17:06:54 -07004720 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004722 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723 } finally {
4724 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004725 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004726 }
4727
yincheng zhaod698b842019-09-06 17:06:54 -07004728 /**
4729 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4730 * subscription.
4731 *
4732 * @param subId the id of the subscription.
4733 * @param appType the uicc app type, must be USIM or SIM.
4734 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4735 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004736 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004737 * @return number of fplmns that is successfully written to the SIM.
4738 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004739 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4740 String callingFeatureId) {
4741 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4742 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004743 if (DBG) logv("no permissions for setForbiddenplmns");
4744 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4745 }
4746 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4747 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4748 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4749 }
4750 if (fplmns == null) {
4751 throw new IllegalArgumentException("Fplmn List provided is null");
4752 }
4753 for (String fplmn : fplmns) {
4754 if (!CellIdentity.isValidPlmn(fplmn)) {
4755 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4756 }
4757 }
4758 final long identity = Binder.clearCallingIdentity();
4759 try {
4760 Object response = sendRequest(
4761 CMD_SET_FORBIDDEN_PLMNS,
4762 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4763 subId);
4764 return (int) response;
4765 } finally {
4766 Binder.restoreCallingIdentity(identity);
4767 }
4768 }
4769
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004770 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004771 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004772 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4773 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004774
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004775 final long identity = Binder.clearCallingIdentity();
4776 try {
4777 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4778 if (response.payload == null) {
4779 return "";
4780 }
Evan Charltonc66da362014-05-16 14:06:40 -07004781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004782 // Append the returned status code to the end of the response payload.
4783 String s = Integer.toHexString(
4784 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4785 s = IccUtils.bytesToHexString(response.payload) + s;
4786 return s;
4787 } finally {
4788 Binder.restoreCallingIdentity(identity);
4789 }
Evan Charltonc66da362014-05-16 14:06:40 -07004790 }
4791
Jake Hambye994d462014-02-03 13:10:13 -08004792 /**
4793 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4794 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4795 *
4796 * @param itemID the ID of the item to read
4797 * @return the NV item as a String, or null on error.
4798 */
4799 @Override
4800 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004801 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4803 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804
4805 final long identity = Binder.clearCallingIdentity();
4806 try {
4807 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004808 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004809 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4810 return value;
4811 } finally {
4812 Binder.restoreCallingIdentity(identity);
4813 }
Jake Hambye994d462014-02-03 13:10:13 -08004814 }
4815
4816 /**
4817 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4818 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4819 *
4820 * @param itemID the ID of the item to read
4821 * @param itemValue the value to write, as a String
4822 * @return true on success; false on any failure
4823 */
4824 @Override
4825 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004826 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004827 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4828 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004829
4830 final long identity = Binder.clearCallingIdentity();
4831 try {
4832 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4833 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004834 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004835 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4836 return success;
4837 } finally {
4838 Binder.restoreCallingIdentity(identity);
4839 }
Jake Hambye994d462014-02-03 13:10:13 -08004840 }
4841
4842 /**
4843 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4844 * Used for device configuration by some CDMA operators.
4845 *
4846 * @param preferredRoamingList byte array containing the new PRL
4847 * @return true on success; false on any failure
4848 */
4849 @Override
4850 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004851 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4852 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004853
4854 final long identity = Binder.clearCallingIdentity();
4855 try {
4856 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4857 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4858 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4859 return success;
4860 } finally {
4861 Binder.restoreCallingIdentity(identity);
4862 }
Jake Hambye994d462014-02-03 13:10:13 -08004863 }
4864
4865 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004866 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004867 * Used for device configuration by some CDMA operators.
4868 *
chen xu6dac5ab2018-10-26 17:39:23 -07004869 * @param slotIndex - device slot.
4870 *
Jake Hambye994d462014-02-03 13:10:13 -08004871 * @return true on success; false on any failure
4872 */
4873 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004874 public boolean resetModemConfig(int slotIndex) {
4875 Phone phone = PhoneFactory.getPhone(slotIndex);
4876 if (phone != null) {
4877 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4878 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004879
chen xu6dac5ab2018-10-26 17:39:23 -07004880 final long identity = Binder.clearCallingIdentity();
4881 try {
4882 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4883 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4884 return success;
4885 } finally {
4886 Binder.restoreCallingIdentity(identity);
4887 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004888 }
chen xu6dac5ab2018-10-26 17:39:23 -07004889 return false;
4890 }
4891
4892 /**
4893 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4894 *
4895 * @param slotIndex - device slot.
4896 *
4897 * @return true on success; false on any failure
4898 */
4899 @Override
4900 public boolean rebootModem(int slotIndex) {
4901 Phone phone = PhoneFactory.getPhone(slotIndex);
4902 if (phone != null) {
4903 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4904 mApp, phone.getSubId(), "rebootModem");
4905
4906 final long identity = Binder.clearCallingIdentity();
4907 try {
4908 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4909 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4910 return success;
4911 } finally {
4912 Binder.restoreCallingIdentity(identity);
4913 }
4914 }
4915 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004916 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004917
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004918 public String[] getPcscfAddress(String apnType, String callingPackage,
4919 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004920 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004921 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4922 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004923 return new String[0];
4924 }
4925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004926 final long identity = Binder.clearCallingIdentity();
4927 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004928 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004929 } finally {
4930 Binder.restoreCallingIdentity(identity);
4931 }
Wink Saville36469e72014-06-11 15:17:00 -07004932 }
4933
Brad Ebinger51f743a2017-01-23 13:50:20 -08004934 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004935 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4936 * {@link #disableIms(int)}.
4937 * @param slotIndex device slot.
4938 */
4939 public void resetIms(int slotIndex) {
4940 enforceModifyPermission();
4941
4942 final long identity = Binder.clearCallingIdentity();
4943 try {
4944 if (mImsResolver == null) {
4945 // may happen if the does not support IMS.
4946 return;
4947 }
4948 mImsResolver.disableIms(slotIndex);
4949 mImsResolver.enableIms(slotIndex);
4950 } finally {
4951 Binder.restoreCallingIdentity(identity);
4952 }
4953 }
4954
4955 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004956 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4957 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004958 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004959 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004960 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004961
4962 final long identity = Binder.clearCallingIdentity();
4963 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004964 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004965 // may happen if the device does not support IMS.
4966 return;
4967 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004968 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004969 } finally {
4970 Binder.restoreCallingIdentity(identity);
4971 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004972 }
4973
4974 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4976 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004977 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004978 public void disableIms(int slotId) {
4979 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004980
4981 final long identity = Binder.clearCallingIdentity();
4982 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004983 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004984 // may happen if the device does not support IMS.
4985 return;
4986 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004987 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004988 } finally {
4989 Binder.restoreCallingIdentity(identity);
4990 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004991 }
4992
4993 /**
4994 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4995 * feature or {@link null} if the service is not available. If the feature is available, the
4996 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4997 */
4998 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004999 IImsServiceFeatureCallback callback) {
5000 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005001
5002 final long identity = Binder.clearCallingIdentity();
5003 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005004 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005005 // may happen if the device does not support IMS.
5006 return null;
5007 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005008 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005009 } finally {
5010 Binder.restoreCallingIdentity(identity);
5011 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005012 }
5013
5014 /**
5015 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5016 * feature during emergency calling or {@link null} if the service is not available. If the
5017 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5018 * listener for feature updates.
5019 */
5020 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5021 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005022
5023 final long identity = Binder.clearCallingIdentity();
5024 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005025 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005026 // may happen if the device does not support IMS.
5027 return null;
5028 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005029 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005030 } finally {
5031 Binder.restoreCallingIdentity(identity);
5032 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005033 }
5034
Brad Ebinger5f64b052017-12-14 14:26:15 -08005035 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005036 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5037 */
5038 public void unregisterImsFeatureCallback(int slotId, int featureType,
5039 IImsServiceFeatureCallback callback) {
5040 enforceModifyPermission();
5041
5042 final long identity = Binder.clearCallingIdentity();
5043 try {
5044 if (mImsResolver == null) return;
5045 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
5049 }
5050
5051 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005052 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005053 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005054 */
5055 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005060 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005061 // may happen if the device does not support IMS.
5062 return null;
5063 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005064 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005065 } finally {
5066 Binder.restoreCallingIdentity(identity);
5067 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005068 }
5069
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005070 /**
5071 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005072 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005073 */
5074 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5075 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005076
5077 final long identity = Binder.clearCallingIdentity();
5078 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005079 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005080 // may happen if the device does not support IMS.
5081 return null;
5082 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005083 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005084 } finally {
5085 Binder.restoreCallingIdentity(identity);
5086 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005087 }
5088
Brad Ebinger884c07b2018-02-15 16:17:40 -08005089 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005090 * Sets the ImsService Package Name that Telephony will bind to.
5091 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005092 * @param slotIndex the slot ID that the ImsService should bind for.
5093 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005094 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005095 * @param featureTypes An integer array of feature types associated with a packageName.
5096 * @param packageName The name of the package that the current configuration will be replaced
5097 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005098 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005099 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005100 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5101 int[] featureTypes, String packageName) {
5102 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5103 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5105 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005106 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005108 final long identity = Binder.clearCallingIdentity();
5109 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005110 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005111 // may happen if the device does not support IMS.
5112 return false;
5113 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005114 Map<Integer, String> featureConfig = new HashMap<>();
5115 for (int featureType : featureTypes) {
5116 featureConfig.put(featureType, packageName);
5117 }
5118 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5119 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005120 } finally {
5121 Binder.restoreCallingIdentity(identity);
5122 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005123 }
5124
5125 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005126 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005127 *
5128 * @param slotId The slot that the ImsService is associated with.
5129 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5130 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005131 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005132 * @return the package name of the ImsService configuration.
5133 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005134 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5135 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005136 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005137 TelephonyPermissions
5138 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5139 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5140 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005141
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005142 final long identity = Binder.clearCallingIdentity();
5143 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005144 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005145 // may happen if the device does not support IMS.
5146 return "";
5147 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005148 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005149 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5150 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005151 } finally {
5152 Binder.restoreCallingIdentity(identity);
5153 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005154 }
5155
Brad Ebinger77b832e2019-10-17 17:03:22 -07005156 /**
5157 * Get the MmTelFeature state associated with the requested subscription id.
5158 * @param subId The subscription that the MmTelFeature is associated with.
5159 * @param callback A callback with an integer containing the
5160 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5161 */
5162 @Override
5163 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5164 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5165 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5166 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5167 "IMS not available on device.");
5168 }
5169 final long token = Binder.clearCallingIdentity();
5170 try {
5171 int slotId = getSlotIndex(subId);
5172 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5173 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5174 + subId + "'");
5175 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5176 }
5177 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5178 try {
5179 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5180 } catch (RemoteException e) {
5181 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5182 + "Ignore");
5183 }
5184 });
5185 } finally {
5186 Binder.restoreCallingIdentity(token);
5187 }
5188 }
5189
Wink Saville36469e72014-06-11 15:17:00 -07005190 public void setImsRegistrationState(boolean registered) {
5191 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192
5193 final long identity = Binder.clearCallingIdentity();
5194 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005195 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005196 } finally {
5197 Binder.restoreCallingIdentity(identity);
5198 }
Wink Saville36469e72014-06-11 15:17:00 -07005199 }
5200
5201 /**
Stuart Scott54788802015-03-30 13:18:01 -07005202 * Set the network selection mode to automatic.
5203 *
5204 */
5205 @Override
5206 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005207 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5208 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005209
5210 final long identity = Binder.clearCallingIdentity();
5211 try {
shilufc958392020-01-20 11:36:01 -08005212 if (!isActiveSubscription(subId)) {
5213 return;
5214 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005215 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5216 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5217 } finally {
5218 Binder.restoreCallingIdentity(identity);
5219 }
Stuart Scott54788802015-03-30 13:18:01 -07005220 }
5221
Pengquan Mengea84e042018-09-20 14:57:26 -07005222 /**
5223 * Ask the radio to connect to the input network and change selection mode to manual.
5224 *
5225 * @param subId the id of the subscription.
5226 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5227 * the operator to attach to.
5228 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5229 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5230 * normal network selection next time.
5231 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005232 */
5233 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005234 public boolean setNetworkSelectionModeManual(
5235 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005236 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5237 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005238
5239 if (!isActiveSubscription(subId)) {
5240 return false;
5241 }
5242
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005243 final long identity = Binder.clearCallingIdentity();
5244 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005245 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005247 if (DBG) {
5248 log("setNetworkSelectionModeManual: subId: " + subId
5249 + " operator: " + operatorInfo);
5250 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005251 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5252 } finally {
5253 Binder.restoreCallingIdentity(identity);
5254 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005255 }
5256
5257 /**
5258 * Scans for available networks.
5259 */
5260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005261 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5262 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005263 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5264 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005265 LocationAccessPolicy.LocationPermissionResult locationResult =
5266 LocationAccessPolicy.checkLocationPermission(mApp,
5267 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5268 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005269 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005270 .setCallingPid(Binder.getCallingPid())
5271 .setCallingUid(Binder.getCallingUid())
5272 .setMethod("getCellNetworkScanResults")
5273 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5274 .build());
5275 switch (locationResult) {
5276 case DENIED_HARD:
5277 throw new SecurityException("Not allowed to access scan results -- location");
5278 case DENIED_SOFT:
5279 return null;
5280 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005281
Pengquan Menga1bb6272018-09-06 09:59:22 -07005282 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005283 try {
5284 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005285 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005286 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005287 } finally {
5288 Binder.restoreCallingIdentity(identity);
5289 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005290 }
5291
5292 /**
sqian80370722020-01-29 15:02:51 -08005293 * Get the call forwarding info, given the call forwarding reason.
5294 */
5295 @Override
5296 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5297 enforceReadPrivilegedPermission("getCallForwarding");
5298 long identity = Binder.clearCallingIdentity();
5299 try {
5300 if (DBG) {
5301 log("getCallForwarding: subId " + subId
5302 + " callForwardingReason" + callForwardingReason);
5303 }
5304 return (CallForwardingInfo) sendRequest(
5305 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5306 } finally {
5307 Binder.restoreCallingIdentity(identity);
5308 }
5309 }
5310
5311 /**
5312 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5313 * reason, the number to forward, and the timeout before the forwarding is attempted.
5314 */
5315 @Override
5316 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5317 enforceModifyPermission();
5318 long identity = Binder.clearCallingIdentity();
5319 try {
5320 if (DBG) {
5321 log("setCallForwarding: subId " + subId
5322 + " callForwardingInfo" + callForwardingInfo);
5323 }
5324 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5325 } finally {
5326 Binder.restoreCallingIdentity(identity);
5327 }
5328 }
5329
5330 /**
5331 * Get the call forwarding info, given the call forwarding reason.
5332 */
5333 @Override
5334 public int getCallWaitingStatus(int subId) {
5335 enforceReadPrivilegedPermission("getCallForwarding");
5336 long identity = Binder.clearCallingIdentity();
5337 try {
5338 if (DBG) log("getCallWaitingStatus: subId " + subId);
5339 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5340 } finally {
5341 Binder.restoreCallingIdentity(identity);
5342 }
5343 }
5344
5345 /**
5346 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5347 * reason, the number to forward, and the timeout before the forwarding is attempted.
5348 */
5349 @Override
5350 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5351 enforceModifyPermission();
5352 long identity = Binder.clearCallingIdentity();
5353 try {
5354 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5355 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5356 } finally {
5357 Binder.restoreCallingIdentity(identity);
5358 }
5359 }
5360
5361 /**
yinxub1bed742017-04-17 11:45:04 -07005362 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005363 *
yinxub1bed742017-04-17 11:45:04 -07005364 * @param subId id of the subscription
5365 * @param request contains the radio access networks with bands/channels to scan
5366 * @param messenger callback messenger for scan results or errors
5367 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005368 * @return the id of the requested scan which can be used to stop the scan.
5369 */
5370 @Override
5371 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005372 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005373 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5374 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005375 LocationAccessPolicy.LocationPermissionResult locationResult =
5376 LocationAccessPolicy.checkLocationPermission(mApp,
5377 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5378 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005379 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005380 .setCallingPid(Binder.getCallingPid())
5381 .setCallingUid(Binder.getCallingUid())
5382 .setMethod("requestNetworkScan")
5383 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5384 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005385 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005386 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005387 if (e != null) {
5388 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5389 throw e;
5390 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005391 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005392 return TelephonyScanManager.INVALID_SCAN_ID;
5393 }
5394 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005395 }
Hall Liu912dfd32019-04-25 14:02:26 -07005396 int callingUid = Binder.getCallingUid();
5397 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005398 final long identity = Binder.clearCallingIdentity();
5399 try {
5400 return mNetworkScanRequestTracker.startNetworkScan(
5401 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005402 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005403 } finally {
5404 Binder.restoreCallingIdentity(identity);
5405 }
yinxu504e1392017-04-12 16:03:22 -07005406 }
5407
Hall Liub2ac8ef2019-02-28 15:56:23 -08005408 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005409 NetworkScanRequest request, int subId) {
5410 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5411 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5412 boolean hasNetworkScanPermission =
5413 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5414 == PERMISSION_GRANTED;
5415
5416 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5417 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5418 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005419 }
5420
5421 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5422 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005423 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5424 return new SecurityException("Specific channels must not be"
5425 + " scanned without location access.");
5426 }
5427 }
5428 }
5429
Hall Liub2ac8ef2019-02-28 15:56:23 -08005430 return null;
5431 }
5432
yinxu504e1392017-04-12 16:03:22 -07005433 /**
5434 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005435 *
5436 * @param subId id of the subscription
5437 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005438 */
5439 @Override
5440 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005441 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5442 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005443
Hall Liu912dfd32019-04-25 14:02:26 -07005444 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005445 final long identity = Binder.clearCallingIdentity();
5446 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005447 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005448 } finally {
5449 Binder.restoreCallingIdentity(identity);
5450 }
yinxu504e1392017-04-12 16:03:22 -07005451 }
5452
5453 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005454 * Get the calculated preferred network type.
5455 * Used for debugging incorrect network type.
5456 *
5457 * @return the preferred network type, defined in RILConstants.java.
5458 */
5459 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005460 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005461 final Phone defaultPhone = getDefaultPhone();
5462 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005463 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005464 return RILConstants.PREFERRED_NETWORK_MODE;
5465 }
5466
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005467 final long identity = Binder.clearCallingIdentity();
5468 try {
5469 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005470 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 } finally {
5472 Binder.restoreCallingIdentity(identity);
5473 }
Junda Liu84d15a22014-07-02 11:21:04 -07005474 }
5475
5476 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005477 * Get the preferred network type.
5478 * Used for device configuration by some CDMA operators.
5479 *
5480 * @return the preferred network type, defined in RILConstants.java.
5481 */
5482 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005483 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005484 TelephonyPermissions
5485 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5486 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005487
5488 final long identity = Binder.clearCallingIdentity();
5489 try {
5490 if (DBG) log("getPreferredNetworkType");
5491 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5492 int networkType = (result != null ? result[0] : -1);
5493 if (DBG) log("getPreferredNetworkType: " + networkType);
5494 return networkType;
5495 } finally {
5496 Binder.restoreCallingIdentity(identity);
5497 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005498 }
5499
5500 /**
5501 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005502 *
5503 * @param networkType the preferred network type, defined in RILConstants.java.
5504 * @return true on success; false on any failure.
5505 */
5506 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005507 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005508 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5509 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510
5511 final long identity = Binder.clearCallingIdentity();
5512 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005513 Settings.Global.putInt(mApp.getContentResolver(),
5514 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005515
5516 Boolean success = (Boolean) sendRequest(
5517 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5518 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5519 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520 } finally {
5521 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005522 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005523 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005524
5525 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005526 * Get the allowed network types that store in the telephony provider.
5527 *
5528 * @param subId the id of the subscription.
5529 * @return allowedNetworkTypes the allowed network types.
5530 */
5531 @Override
5532 public long getAllowedNetworkTypes(int subId) {
5533 TelephonyPermissions
5534 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5535 mApp, subId, "getAllowedNetworkTypes");
5536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
5539 return SubscriptionManager.getLongSubscriptionProperty(
5540 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
5544 }
5545
5546 /**
5547 * Set the allowed network types.
5548 *
5549 * @param subId the id of the subscription.
5550 * @param allowedNetworkTypes the allowed network types.
5551 * @return true on success; false on any failure.
5552 */
5553 @Override
5554 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5556 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005557
calvinpan089c2a62020-03-12 14:17:55 +08005558 SubscriptionManager.setSubscriptionProperty(subId,
5559 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5560 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005561
calvinpan089c2a62020-03-12 14:17:55 +08005562 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5563 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5564 RILConstants.PREFERRED_NETWORK_MODE);
5565 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005566 }
5567
5568 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005569 * Get the allowed network types for certain reason.
5570 *
5571 * @param subId the id of the subscription.
5572 * @param reason the reason the allowed network type change is taking place
5573 * @return the allowed network types.
5574 */
5575 @Override
5576 public long getAllowedNetworkTypesForReason(int subId,
5577 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5578 TelephonyPermissions
5579 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5580 mApp, subId, "getAllowedNetworkTypesForReason");
5581 final long identity = Binder.clearCallingIdentity();
5582 try {
5583 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5584 } finally {
5585 Binder.restoreCallingIdentity(identity);
5586 }
5587 }
5588
5589 /**
5590 * Get the effective allowed network types on the device.
5591 * This API will return an intersection of allowed network types for all reasons,
5592 * including the configuration done through setAllowedNetworkTypes
5593 *
5594 * @param subId the id of the subscription.
5595 * @return the allowed network types
5596 */
5597 @Override
5598 public long getEffectiveAllowedNetworkTypes(int subId) {
5599 TelephonyPermissions
5600 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5601 mApp, subId, "getEffectiveAllowedNetworkTypes");
5602 final long identity = Binder.clearCallingIdentity();
5603 try {
5604 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5605 } finally {
5606 Binder.restoreCallingIdentity(identity);
5607 }
5608 }
5609
5610 /**
5611 * Set the allowed network types of the device and
5612 * provide the reason triggering the allowed network change.
5613 *
5614 * @param subId the id of the subscription.
5615 * @param reason the reason the allowed network type change is taking place
5616 * @param allowedNetworkTypes the allowed network types.
5617 * @return true on success; false on any failure.
5618 */
5619 @Override
5620 public boolean setAllowedNetworkTypesForReason(int subId,
5621 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5622 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5623 mApp, subId, "setAllowedNetworkTypesForReason");
5624 final long identity = Binder.clearCallingIdentity();
5625 try {
5626 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5627 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5628 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5629 RILConstants.PREFERRED_NETWORK_MODE);
5630 return setPreferredNetworkType(subId, preferredNetworkMode);
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
5634 }
5635
5636 /**
Miaoa84611c2019-03-15 09:21:10 +08005637 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005638 *
Miaoa84611c2019-03-15 09:21:10 +08005639 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005640 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005641 * @hide
5642 */
5643 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005644 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005645 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005646 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005647 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005648 try {
Miaoa84611c2019-03-15 09:21:10 +08005649 if (phone != null) {
5650 return phone.hasMatchedTetherApnSetting();
5651 } else {
5652 return false;
5653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005654 } finally {
5655 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005656 }
Junda Liu475951f2014-11-07 16:45:03 -08005657 }
5658
5659 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005660 * Set mobile data enabled
5661 * Used by the user through settings etc to turn on/off mobile data
5662 *
5663 * @param enable {@code true} turn turn data on, else {@code false}
5664 */
5665 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005666 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5668 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005669
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 int phoneId = mSubscriptionController.getPhoneId(subId);
5673 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5674 Phone phone = PhoneFactory.getPhone(phoneId);
5675 if (phone != null) {
5676 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005677 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005678 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005679 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 }
5681 } finally {
5682 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005683 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005684 }
5685
5686 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005687 * Enable or disable always reporting signal strength changes from radio.
5688 *
5689 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5690 */
5691 @Override
5692 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5693 enforceModifyPermission();
5694 enforceSystemCaller();
5695
5696 final long identity = Binder.clearCallingIdentity();
5697 final Phone phone = getPhone(subId);
5698 try {
5699 if (phone != null) {
5700 if (DBG) {
5701 log("setAlwaysReportSignalStrength: subId=" + subId
5702 + " isEnable=" + isEnable);
5703 }
5704 phone.setAlwaysReportSignalStrength(isEnable);
5705 } else {
5706 loge("setAlwaysReportSignalStrength: no phone found for subId="
5707 + subId);
5708 }
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
5711 }
5712 }
5713
5714 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005715 * Get the user enabled state of Mobile Data.
5716 *
5717 * TODO: remove and use isUserDataEnabled.
5718 * This can't be removed now because some vendor codes
5719 * calls through ITelephony directly while they should
5720 * use TelephonyManager.
5721 *
5722 * @return true on enabled
5723 */
5724 @Override
5725 public boolean getDataEnabled(int subId) {
5726 return isUserDataEnabled(subId);
5727 }
5728
5729 /**
5730 * Get whether mobile data is enabled per user setting.
5731 *
5732 * There are other factors deciding whether mobile data is actually enabled, but they are
5733 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005734 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005735 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005736 *
5737 * @return {@code true} if data is enabled else {@code false}
5738 */
5739 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005740 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005741 try {
5742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5743 null);
5744 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005745 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5746 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005747 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005748
5749 final long identity = Binder.clearCallingIdentity();
5750 try {
5751 int phoneId = mSubscriptionController.getPhoneId(subId);
5752 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5753 Phone phone = PhoneFactory.getPhone(phoneId);
5754 if (phone != null) {
5755 boolean retVal = phone.isUserDataEnabled();
5756 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5757 return retVal;
5758 } else {
5759 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5760 return false;
5761 }
5762 } finally {
5763 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005764 }
5765 }
5766
5767 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005768 * Checks if the device is capable of mobile data by considering whether whether the
5769 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5770 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005771 *
Shuo Qian985d1232020-01-08 14:30:06 -08005772 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005773 */
5774 @Override
5775 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005776 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005777
5778 final long identity = Binder.clearCallingIdentity();
5779 try {
5780 int phoneId = mSubscriptionController.getPhoneId(subId);
5781 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5782 Phone phone = PhoneFactory.getPhone(phoneId);
5783 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005784 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5786 return retVal;
5787 } else {
5788 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5789 return false;
5790 }
5791 } finally {
5792 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005793 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005794 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005795
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005796 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005797 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005798 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5799 // Skip the check if it's one of these special uids
5800 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5801 }
5802
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005803 //load access rules from carrier configs, and check those as well: b/139133814
5804 SubscriptionController subController = SubscriptionController.getInstance();
5805 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5806 || subController == null) return privilegeFromSim;
5807
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005808 PackageManager pkgMgr = phone.getContext().getPackageManager();
5809 String[] packages = pkgMgr.getPackagesForUid(uid);
5810
5811 final long identity = Binder.clearCallingIdentity();
5812 try {
5813 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5814 SubscriptionManager subManager = (SubscriptionManager)
5815 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5816 for (String pkg : packages) {
5817 if (subManager.canManageSubscription(subInfo, pkg)) {
5818 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5819 }
5820 }
5821 return privilegeFromSim;
5822 } finally {
5823 Binder.restoreCallingIdentity(identity);
5824 }
5825 }
5826
5827 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5828 String pkgName) {
5829 //load access rules from carrier configs, and check those as well: b/139133814
5830 SubscriptionController subController = SubscriptionController.getInstance();
5831 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5832 || subController == null) return privilegeFromSim;
5833
5834 final long identity = Binder.clearCallingIdentity();
5835 try {
5836 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5837 SubscriptionManager subManager = (SubscriptionManager)
5838 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5839 return subManager.canManageSubscription(subInfo, pkgName)
5840 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5841 } finally {
5842 Binder.restoreCallingIdentity(identity);
5843 }
5844 }
5845
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005846 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005847 public int getCarrierPrivilegeStatus(int subId) {
5848 final Phone phone = getPhone(subId);
5849 if (phone == null) {
5850 loge("getCarrierPrivilegeStatus: Invalid subId");
5851 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5852 }
5853 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005854 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005855 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005856 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5857 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005858
5859 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5860 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005861 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005862 }
Junda Liu29340342014-07-10 15:23:27 -07005863
5864 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005865 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005866 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005867 final Phone phone = getPhone(subId);
5868 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005869 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005870 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5871 }
5872 UiccProfile profile =
5873 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5874 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005875 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005876 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5877 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005878 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005879 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005880 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005881 }
5882
5883 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005884 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5885 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005886 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005887 }
5888
5889 int phoneId = SubscriptionManager.getPhoneId(subId);
5890 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005891 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005892 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005893 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5894 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005895 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5896 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5897 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005898 }
5899
5900 @Override
5901 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005902 if (TextUtils.isEmpty(pkgName))
5903 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005904 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5905 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5906 UiccCard card = UiccController.getInstance().getUiccCard(i);
5907 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005908 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005909 continue;
5910 }
5911
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005912 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5913 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5914 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005915 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5916 break;
5917 }
5918 }
5919
5920 return result;
Junda Liu29340342014-07-10 15:23:27 -07005921 }
Derek Tan89e89d42014-07-08 17:00:10 -07005922
5923 @Override
Junda Liue64de782015-04-16 17:19:16 -07005924 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5925 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5926 loge("phoneId " + phoneId + " is not valid.");
5927 return null;
5928 }
5929 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005930 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005931 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005932 return null ;
5933 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005934 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005935 }
5936
Amith Yamasani6e118872016-02-19 12:53:51 -08005937 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005938 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005939 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005940 List<String> privilegedPackages = new ArrayList<>();
5941 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005942 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5943 // has UICC in that slot.
5944 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005945 if (card.hasCarrierPrivilegeRules()) {
5946 if (packages == null) {
5947 // Only check packages in user 0 for now
5948 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005949 PackageManager.MATCH_DISABLED_COMPONENTS
5950 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005951 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005952 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005953 }
5954 for (int p = packages.size() - 1; p >= 0; p--) {
5955 PackageInfo pkgInfo = packages.get(p);
5956 if (pkgInfo != null && pkgInfo.packageName != null
5957 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005958 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005959 privilegedPackages.add(pkgInfo.packageName);
5960 }
5961 }
5962 }
5963 }
5964 return privilegedPackages;
5965 }
5966
chen xuf7e9fe82019-05-09 19:31:02 -07005967 @Override
5968 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005969 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5970
5971 final long identity = Binder.clearCallingIdentity();
5972
chen xuf7e9fe82019-05-09 19:31:02 -07005973 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005974 try {
5975 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5976 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5977 }
5978 } finally {
5979 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005980 }
5981 return privilegedPackages;
5982 }
5983
Wink Savilleb564aae2014-10-23 10:18:09 -07005984 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005985 final Phone phone = getPhone(subId);
5986 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005987 if (card == null) {
5988 loge("getIccId: No UICC");
5989 return null;
5990 }
5991 String iccId = card.getIccId();
5992 if (TextUtils.isEmpty(iccId)) {
5993 loge("getIccId: ICC ID is null or empty.");
5994 return null;
5995 }
5996 return iccId;
5997 }
5998
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005999 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006000 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6001 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006002 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006003 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006004
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006005 final long identity = Binder.clearCallingIdentity();
6006 try {
6007 final String iccId = getIccId(subId);
6008 final Phone phone = getPhone(subId);
6009 if (phone == null) {
6010 return false;
6011 }
6012 final String subscriberId = phone.getSubscriberId();
6013
6014 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006015 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006016 + subscriberId + " to " + number);
6017 }
6018
6019 if (TextUtils.isEmpty(iccId)) {
6020 return false;
6021 }
6022
6023 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6024
6025 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6026 if (alphaTag == null) {
6027 editor.remove(alphaTagPrefKey);
6028 } else {
6029 editor.putString(alphaTagPrefKey, alphaTag);
6030 }
6031
6032 // Record both the line number and IMSI for this ICCID, since we need to
6033 // track all merged IMSIs based on line number
6034 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6035 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6036 if (number == null) {
6037 editor.remove(numberPrefKey);
6038 editor.remove(subscriberPrefKey);
6039 } else {
6040 editor.putString(numberPrefKey, number);
6041 editor.putString(subscriberPrefKey, subscriberId);
6042 }
6043
6044 editor.commit();
6045 return true;
6046 } finally {
6047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006048 }
Derek Tan7226c842014-07-02 17:42:23 -07006049 }
6050
6051 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006052 public String getLine1NumberForDisplay(int subId, String callingPackage,
6053 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006054 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006055 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006056 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006057 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006058 return null;
6059 }
Derek Tan97ebb422014-09-05 16:55:38 -07006060
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006061 final long identity = Binder.clearCallingIdentity();
6062 try {
6063 String iccId = getIccId(subId);
6064 if (iccId != null) {
6065 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6066 if (DBG_MERGE) {
6067 log("getLine1NumberForDisplay returning "
6068 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6069 }
6070 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006071 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006072 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6073 return null;
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006076 }
Derek Tan7226c842014-07-02 17:42:23 -07006077 }
6078
6079 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006080 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6081 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006082 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006083 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006084 return null;
6085 }
Derek Tan97ebb422014-09-05 16:55:38 -07006086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 String iccId = getIccId(subId);
6090 if (iccId != null) {
6091 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6092 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6093 }
6094 return null;
6095 } finally {
6096 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006097 }
Derek Tan7226c842014-07-02 17:42:23 -07006098 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006099
6100 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006101 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6102 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006103 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6104 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006106 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006107 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006108 return null;
6109 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006110
Jordan Liub49b04b2019-05-06 14:45:15 -07006111 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6112 // the process, where TelephonyManager was instantiated.
6113 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006114 final long identity = Binder.clearCallingIdentity();
6115 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006116 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006117 final TelephonyManager tele = TelephonyManager.from(context);
6118 final SubscriptionManager sub = SubscriptionManager.from(context);
6119
6120 // Figure out what subscribers are currently active
6121 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006122
Jordan Liub49b04b2019-05-06 14:45:15 -07006123 // Only consider subs which match the current subId
6124 // This logic can be simplified. See b/131189269 for progress.
6125 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006126 activeSubscriberIds.add(tele.getSubscriberId(subId));
6127 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006128
6129 // First pass, find a number override for an active subscriber
6130 String mergeNumber = null;
6131 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6132 for (String key : prefs.keySet()) {
6133 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6134 final String subscriberId = (String) prefs.get(key);
6135 if (activeSubscriberIds.contains(subscriberId)) {
6136 final String iccId = key.substring(
6137 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6138 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6139 mergeNumber = (String) prefs.get(numberKey);
6140 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006141 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006142 + " for active subscriber " + subscriberId);
6143 }
6144 if (!TextUtils.isEmpty(mergeNumber)) {
6145 break;
6146 }
6147 }
6148 }
6149 }
6150
6151 // Shortcut when no active merged subscribers
6152 if (TextUtils.isEmpty(mergeNumber)) {
6153 return null;
6154 }
6155
6156 // Second pass, find all subscribers under that line override
6157 final ArraySet<String> result = new ArraySet<>();
6158 for (String key : prefs.keySet()) {
6159 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6160 final String number = (String) prefs.get(key);
6161 if (mergeNumber.equals(number)) {
6162 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6163 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6164 final String subscriberId = (String) prefs.get(subscriberKey);
6165 if (!TextUtils.isEmpty(subscriberId)) {
6166 result.add(subscriberId);
6167 }
6168 }
6169 }
6170 }
6171
6172 final String[] resultArray = result.toArray(new String[result.size()]);
6173 Arrays.sort(resultArray);
6174 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006175 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006176 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6177 }
6178 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006179 } finally {
6180 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006181 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006182 }
6183
6184 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006185 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6186 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6187
6188 final long identity = Binder.clearCallingIdentity();
6189 try {
6190 final TelephonyManager telephonyManager = mApp.getSystemService(
6191 TelephonyManager.class);
6192 String subscriberId = telephonyManager.getSubscriberId(subId);
6193 if (subscriberId == null) {
6194 if (DBG) {
6195 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6196 + subId);
6197 }
6198 return null;
6199 }
6200
6201 final SubscriptionInfo info = SubscriptionController.getInstance()
6202 .getSubscriptionInfo(subId);
6203 final ParcelUuid groupUuid = info.getGroupUuid();
6204 // If it doesn't belong to any group, return just subscriberId of itself.
6205 if (groupUuid == null) {
6206 return new String[]{subscriberId};
6207 }
6208
6209 // Get all subscriberIds from the group.
6210 final List<String> mergedSubscriberIds = new ArrayList<>();
6211 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006212 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6213 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006214 for (SubscriptionInfo subInfo : groupInfos) {
6215 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6216 if (subscriberId != null) {
6217 mergedSubscriberIds.add(subscriberId);
6218 }
6219 }
6220
6221 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6222 } finally {
6223 Binder.restoreCallingIdentity(identity);
6224
6225 }
6226 }
6227
6228 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006229 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006230 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006231 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006232
6233 final long identity = Binder.clearCallingIdentity();
6234 try {
6235 final Phone phone = getPhone(subId);
6236 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6237 } finally {
6238 Binder.restoreCallingIdentity(identity);
6239 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006240 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006241
6242 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006243 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006244 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6245 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006246 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6247 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006248
6249 final long identity = Binder.clearCallingIdentity();
6250 try {
6251 final Phone phone = getPhone(subId);
6252 if (phone == null) {
6253 return false;
6254 }
6255 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6256 cdmaNonRoamingList);
6257 } finally {
6258 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006259 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006260 }
6261
6262 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006263 @Deprecated
6264 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6265 enforceModifyPermission();
6266
6267 int returnValue = 0;
6268 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006269 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006270 if(result.exception == null) {
6271 if (result.result != null) {
6272 byte[] responseData = (byte[])(result.result);
6273 if(responseData.length > oemResp.length) {
6274 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6275 responseData.length + "bytes. Buffer Size is " +
6276 oemResp.length + "bytes.");
6277 }
6278 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6279 returnValue = responseData.length;
6280 }
6281 } else {
6282 CommandException ex = (CommandException) result.exception;
6283 returnValue = ex.getCommandError().ordinal();
6284 if(returnValue > 0) returnValue *= -1;
6285 }
6286 } catch (RuntimeException e) {
6287 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6288 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6289 if(returnValue > 0) returnValue *= -1;
6290 }
6291
6292 return returnValue;
6293 }
6294
6295 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006296 public void setRadioCapability(RadioAccessFamily[] rafs) {
6297 try {
6298 ProxyController.getInstance().setRadioCapability(rafs);
6299 } catch (RuntimeException e) {
6300 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6301 }
6302 }
6303
6304 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006305 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006306 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006307 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006308 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006309 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006310 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006311 final long identity = Binder.clearCallingIdentity();
6312 try {
chen xub97461a2018-10-26 14:17:57 -07006313 TelephonyPermissions
6314 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6315 mApp, phone.getSubId(), "getRadioAccessFamily");
6316 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317 } finally {
6318 Binder.restoreCallingIdentity(identity);
6319 }
chen xub97461a2018-10-26 14:17:57 -07006320 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006321 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006322
6323 @Override
6324 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006325 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006326 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006327
6328 final long identity = Binder.clearCallingIdentity();
6329 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006330 ImsManager.getInstance(defaultPhone.getContext(),
6331 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006332 } finally {
6333 Binder.restoreCallingIdentity(identity);
6334 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006335 }
6336
6337 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006338 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006339 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006340 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6341 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006342 return false;
6343 }
Svet Ganovb320e182015-04-16 12:30:10 -07006344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 final long identity = Binder.clearCallingIdentity();
6346 try {
6347 // Check the user preference and the system-level IMS setting. Even if the user has
6348 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6349 // In the long run, we may instead need to check if there exists a connection service
6350 // which can support video calling.
6351 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006352 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 return imsManager.isVtEnabledByPlatform()
6354 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6355 && imsManager.isVtEnabledByUser();
6356 } finally {
6357 Binder.restoreCallingIdentity(identity);
6358 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006359 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006360
Andrew Leea1239f22015-03-02 17:44:07 -08006361 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006362 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6363 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006364 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006365 mApp, subId, callingPackage, callingFeatureId,
6366 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 return false;
6368 }
6369
6370 final long identity = Binder.clearCallingIdentity();
6371 try {
6372 CarrierConfigManager configManager =
6373 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006374 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6376 } finally {
6377 Binder.restoreCallingIdentity(identity);
6378 }
Andrew Leea1239f22015-03-02 17:44:07 -08006379 }
6380
6381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006382 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006384 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 return false;
6386 }
6387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
6390 CarrierConfigManager configManager =
6391 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006392 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Andrew Leea1239f22015-03-02 17:44:07 -08006397 }
6398
Andrew Lee9431b832015-03-09 18:46:45 -07006399 @Override
6400 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006401 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006402 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006403 }
6404
6405 @Override
6406 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 final long identity = Binder.clearCallingIdentity();
6408 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006409 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 } finally {
6411 Binder.restoreCallingIdentity(identity);
6412 }
Andrew Lee9431b832015-03-09 18:46:45 -07006413 }
6414
Hall Liuf6668912018-10-31 17:05:23 -07006415 /**
6416 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6417 * support for the feature and device firmware support.
6418 *
6419 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6420 */
6421 @Override
6422 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006424 final Phone phone = getPhone(subscriptionId);
6425 if (phone == null) {
6426 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6427 return false;
6428 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006430 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6432 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006433 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006434 return isCarrierSupported && isDeviceSupported;
6435 } finally {
6436 Binder.restoreCallingIdentity(identity);
6437 }
Hall Liu98187582018-01-22 19:15:32 -08006438 }
6439
Hall Liuf6668912018-10-31 17:05:23 -07006440 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006441 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6442 * RTT setting, will return true if the device and carrier both support RTT.
6443 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006444 */
6445 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 final long identity = Binder.clearCallingIdentity();
6447 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006448 boolean isRttSupported = isRttSupported(subscriptionId);
6449 boolean isUserRttSettingOn = Settings.Secure.getInt(
6450 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6451 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6452 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6453 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006457 }
6458
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006459 @Deprecated
6460 @Override
6461 public String getDeviceId(String callingPackage) {
6462 return getDeviceIdWithFeature(callingPackage, null);
6463 }
6464
Sanket Padawe7310cc72015-01-14 09:53:20 -08006465 /**
6466 * Returns the unique device ID of phone, for example, the IMEI for
6467 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6468 *
6469 * <p>Requires Permission:
6470 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6471 */
6472 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006473 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006474 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006475 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006476 return null;
6477 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006478 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006479 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006480 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006481 return null;
6482 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483
6484 final long identity = Binder.clearCallingIdentity();
6485 try {
6486 return phone.getDeviceId();
6487 } finally {
6488 Binder.restoreCallingIdentity(identity);
6489 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006490 }
6491
Ping Sunc67b7c22016-03-02 19:16:45 +08006492 /**
6493 * {@hide}
6494 * Returns the IMS Registration Status on a particular subid
6495 *
6496 * @param subId
6497 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006498 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006499 Phone phone = getPhone(subId);
6500 if (phone != null) {
6501 return phone.isImsRegistered();
6502 } else {
6503 return false;
6504 }
6505 }
6506
Santos Cordon7a1885b2015-02-03 11:15:19 -08006507 @Override
6508 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509 final long identity = Binder.clearCallingIdentity();
6510 try {
6511 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6512 } finally {
6513 Binder.restoreCallingIdentity(identity);
6514 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006515 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006516
Tyler Gunnf70ed162019-04-03 15:28:53 -07006517 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006518 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006519 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006520 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006521 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006522 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6523 }
6524 final long identity = Binder.clearCallingIdentity();
6525 try {
6526 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6527 } finally {
6528 Binder.restoreCallingIdentity(identity);
6529 }
6530 }
6531
6532 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006533 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006534 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6535 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006536 final long identity = Binder.clearCallingIdentity();
6537 try {
6538 Phone phone = getPhone(subscriptionId);
6539 if (phone == null) {
6540 return null;
6541 }
6542 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6543 } finally {
6544 Binder.restoreCallingIdentity(identity);
6545 }
6546 }
6547
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006548 /**
6549 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006550 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006551 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006552 final long identity = Binder.clearCallingIdentity();
6553 try {
6554 Phone phone = getPhone(subId);
6555 if (phone != null) {
6556 return phone.isWifiCallingEnabled();
6557 } else {
6558 return false;
6559 }
6560 } finally {
6561 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006562 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006563 }
6564
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006565 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006566 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006567 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006568 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 Phone phone = getPhone(subId);
6572 if (phone != null) {
6573 return phone.isVideoEnabled();
6574 } else {
6575 return false;
6576 }
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006579 }
6580 }
6581
6582 /**
6583 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6584 * defined in {@link ImsRegistrationImplBase}.
6585 */
6586 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006587 final long identity = Binder.clearCallingIdentity();
6588 try {
6589 Phone phone = getPhone(subId);
6590 if (phone != null) {
6591 return phone.getImsRegistrationTech();
6592 } else {
6593 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6594 }
6595 } finally {
6596 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006597 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006598 }
6599
Stuart Scott8eef64f2015-04-08 15:13:54 -07006600 @Override
6601 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006602 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006603 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6604 return;
6605 }
6606
Svet Ganovcc087f82015-05-12 20:35:54 -07006607 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006608
Svet Ganovcc087f82015-05-12 20:35:54 -07006609 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006610 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6611 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006612 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006613 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006614 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006615 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6616 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006617 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006618 // There has been issues when Sms raw table somehow stores orphan
6619 // fragments. They lead to garbled message when new fragments come
6620 // in and combined with those stale ones. In case this happens again,
6621 // user can reset all network settings which will clean up this table.
6622 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006623 // Clean up IMS settings as well here.
6624 int slotId = getSlotIndex(subId);
6625 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6626 ImsManager.getInstance(mApp, slotId).factoryReset();
6627 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006628
6629 // Erase modem config if erase modem on network setting is enabled.
6630 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6631 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6632 if (configValue != null && Boolean.parseBoolean(configValue)) {
6633 sendEraseModemConfig(getDefaultPhone());
6634 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006637 }
6638 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006639
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006640 private void cleanUpSmsRawTable(Context context) {
6641 ContentResolver resolver = context.getContentResolver();
6642 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6643 resolver.delete(uri, null, null);
6644 }
6645
Narayan Kamath1c496c22015-04-16 14:40:19 +01006646 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006647 public String getSimLocaleForSubscriber(int subId) {
6648 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6649 final Phone phone = getPhone(subId);
6650 if (phone == null) {
6651 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006652 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006653 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006654 final long identity = Binder.clearCallingIdentity();
6655 try {
chen xu5d3637b2019-01-21 23:31:38 -08006656 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006657 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006658 if (info == null) {
6659 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6660 return null;
6661 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006662 // Try and fetch the locale from the carrier properties or from the SIM language
6663 // preferences (EF-PL and EF-LI)...
6664 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006666 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6667 if (localeFromDefaultSim != null) {
6668 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6669 if (DBG) log("Using locale from subId: " + subId + " locale: "
6670 + localeFromDefaultSim);
6671 return localeFromDefaultSim.toLanguageTag();
6672 } else {
6673 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 }
6675 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006677 // The SIM language preferences only store a language (e.g. fr = French), not an
6678 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6679 // the SIM and carrier preferences does not include a country we add the country
6680 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006681 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006682 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006683 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006684 return mccLocale.toLanguageTag();
6685 }
6686
6687 if (DBG) log("No locale found - returning null");
6688 return null;
6689 } finally {
6690 Binder.restoreCallingIdentity(identity);
6691 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006692 }
6693
6694 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006695 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6696 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006697 }
6698
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 /**
6700 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6701 */
6702 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006703 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6704 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006705 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006706
Chenjie Yu1ba97252018-01-11 18:16:20 -08006707 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006708 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006709
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006710 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006711 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6712 * representing the state of the modem.
6713 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006714 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6715 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006716 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006717 */
6718 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006719 public void requestModemActivityInfo(ResultReceiver result) {
6720 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006721 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006722
6723 final long identity = Binder.clearCallingIdentity();
6724 try {
sqian1a1be542020-03-05 11:37:28 -08006725 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 } finally {
6727 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006728 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006729 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006730
Siddharth Rayb8114062018-06-17 15:02:38 -07006731 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6732 // less than total activity duration.
6733 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6734 if (info == null) {
6735 return false;
6736 }
6737 int activityDurationMs =
6738 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6739 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006740 int[] txTimeMs = info.getTransmitTimeMillis();
6741 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6742 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006743 }
6744 return (info.isValid()
6745 && (info.getSleepTimeMillis() <= activityDurationMs)
6746 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006747 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006748 && (totalTxTimeMs <= activityDurationMs));
6749 }
6750
Jack Yu85bd38a2015-11-09 11:34:32 -08006751 /**
6752 * {@hide}
6753 * Returns the service state information on specified subscription.
6754 */
6755 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006756 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6757 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006758 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006759 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006760 return null;
6761 }
6762
Hall Liuf19c44f2018-11-27 14:38:17 -08006763 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6764 LocationAccessPolicy.checkLocationPermission(mApp,
6765 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6766 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006767 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006768 .setCallingPid(Binder.getCallingPid())
6769 .setCallingUid(Binder.getCallingUid())
6770 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006771 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006772 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6773 .build());
6774
6775 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6776 LocationAccessPolicy.checkLocationPermission(mApp,
6777 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6778 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006779 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006780 .setCallingPid(Binder.getCallingPid())
6781 .setCallingUid(Binder.getCallingUid())
6782 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006783 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006784 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6785 .build());
6786 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6787 boolean hasFinePermission =
6788 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6789 boolean hasCoarsePermission =
6790 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6791
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006792 final long identity = Binder.clearCallingIdentity();
6793 try {
6794 final Phone phone = getPhone(subId);
6795 if (phone == null) {
6796 return null;
6797 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006798
Hall Liuf19c44f2018-11-27 14:38:17 -08006799 ServiceState ss = phone.getServiceState();
6800
6801 // Scrub out the location info in ServiceState depending on what level of access
6802 // the caller has.
6803 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006804 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6805 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006806 } finally {
6807 Binder.restoreCallingIdentity(identity);
6808 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006809 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006810
6811 /**
6812 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6813 *
6814 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6815 * voicemail ringtone.
6816 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6817 * PhoneAccount.
6818 */
6819 @Override
6820 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 final long identity = Binder.clearCallingIdentity();
6822 try {
6823 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6824 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006825 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006827
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006828 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6829 } finally {
6830 Binder.restoreCallingIdentity(identity);
6831 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006832 }
6833
6834 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006835 * Sets the per-account voicemail ringtone.
6836 *
6837 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6838 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6839 *
6840 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6841 * voicemail ringtone.
6842 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6843 * PhoneAccount.
6844 */
6845 @Override
6846 public void setVoicemailRingtoneUri(String callingPackage,
6847 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006848 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006849 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006850 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6851 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6853 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6854 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006855 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006856
6857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6860 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006861 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 }
6863 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6864 } finally {
6865 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006866 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006867 }
6868
6869 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006870 * Returns whether vibration is set for voicemail notification in Phone settings.
6871 *
6872 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6873 * voicemail vibration setting.
6874 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6875 */
6876 @Override
6877 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 final long identity = Binder.clearCallingIdentity();
6879 try {
6880 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6881 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006882 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006883 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006884
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006885 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6886 } finally {
6887 Binder.restoreCallingIdentity(identity);
6888 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006889 }
6890
Youhan Wange64578a2016-05-02 15:32:42 -07006891 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006892 * Sets the per-account voicemail vibration.
6893 *
6894 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6895 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6896 *
6897 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6898 * voicemail vibration setting.
6899 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6900 * specific PhoneAccount.
6901 */
6902 @Override
6903 public void setVoicemailVibrationEnabled(String callingPackage,
6904 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006905 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006906 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006907 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6908 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006909 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6910 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6911 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006912 }
6913
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 final long identity = Binder.clearCallingIdentity();
6915 try {
6916 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6917 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006918 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 }
6920 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6921 } finally {
6922 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006923 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006924 }
6925
6926 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006927 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6928 *
6929 * @throws SecurityException if the caller does not have the required permission
6930 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006931 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006932 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006933 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006934 }
6935
6936 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006937 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6938 * permission.
6939 *
6940 * @throws SecurityException if the caller does not have the required permission
6941 */
6942 private void enforceSendSmsPermission() {
6943 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6944 }
6945
6946 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006947 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006948 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006949 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006950 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006951 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006952 final long identity = Binder.clearCallingIdentity();
6953 try {
6954 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006955 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006956 if (componentName == null) {
6957 throw new SecurityException(
6958 "Caller not current active visual voicemail package[null]");
6959 }
6960 String vvmPackage = componentName.getPackageName();
6961 if (!callingPackage.equals(vvmPackage)) {
6962 throw new SecurityException("Caller not current active visual voicemail package["
6963 + vvmPackage + "]");
6964 }
6965 } finally {
6966 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006967 }
6968 }
6969
6970 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006971 * Return the application ID for the app type.
6972 *
6973 * @param subId the subscription ID that this request applies to.
6974 * @param appType the uicc app type.
6975 * @return Application ID for specificied app type, or null if no uicc.
6976 */
6977 @Override
6978 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006979 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006980 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006981
6982 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006983 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 if (phone == null) {
6985 return null;
6986 }
6987 String aid = null;
6988 try {
6989 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6990 .getApplicationByType(appType).getAid();
6991 } catch (Exception e) {
6992 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6993 }
6994 return aid;
6995 } finally {
6996 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006997 }
Youhan Wange64578a2016-05-02 15:32:42 -07006998 }
6999
Youhan Wang4001d252016-05-11 10:29:41 -07007000 /**
7001 * Return the Electronic Serial Number.
7002 *
7003 * @param subId the subscription ID that this request applies to.
7004 * @return ESN or null if error.
7005 */
7006 @Override
7007 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007008 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007009 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010
7011 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007012 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007013 if (phone == null) {
7014 return null;
7015 }
7016 String esn = null;
7017 try {
7018 esn = phone.getEsn();
7019 } catch (Exception e) {
7020 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7021 }
7022 return esn;
7023 } finally {
7024 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007025 }
Youhan Wang4001d252016-05-11 10:29:41 -07007026 }
7027
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007028 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007029 * Return the Preferred Roaming List Version.
7030 *
7031 * @param subId the subscription ID that this request applies to.
7032 * @return PRLVersion or null if error.
7033 */
7034 @Override
7035 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007036 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007037 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007038
7039 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007040 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007041 if (phone == null) {
7042 return null;
7043 }
7044 String cdmaPrlVersion = null;
7045 try {
7046 cdmaPrlVersion = phone.getCdmaPrlVersion();
7047 } catch (Exception e) {
7048 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7049 }
7050 return cdmaPrlVersion;
7051 } finally {
7052 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007053 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007054 }
7055
7056 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007057 * Get snapshot of Telephony histograms
7058 * @return List of Telephony histograms
7059 * @hide
7060 */
7061 @Override
7062 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007063 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7064 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007065
7066 final long identity = Binder.clearCallingIdentity();
7067 try {
7068 return RIL.getTelephonyRILTimingHistograms();
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
7071 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007072 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007073
7074 /**
7075 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007076 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7077 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007078 * Require system privileges. In the future we may add this to carrier APIs.
7079 *
Michele Berionne482f8202018-11-27 18:57:59 -08007080 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007081 */
7082 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007083 @TelephonyManager.SetCarrierRestrictionResult
7084 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007085 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007086 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007087
Michele Berionne482f8202018-11-27 18:57:59 -08007088 if (carrierRestrictionRules == null) {
7089 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007090 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007091
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007092 final long identity = Binder.clearCallingIdentity();
7093 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007094 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007095 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007096 } finally {
7097 Binder.restoreCallingIdentity(identity);
7098 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007099 }
7100
7101 /**
7102 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007103 * Get the allowed carrier list and the excluded carrier list, including the priority between
7104 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007105 * Require system privileges. In the future we may add this to carrier APIs.
7106 *
Michele Berionne482f8202018-11-27 18:57:59 -08007107 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007108 */
7109 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007110 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007111 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007113
7114 final long identity = Binder.clearCallingIdentity();
7115 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007116 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7117 if (response instanceof CarrierRestrictionRules) {
7118 return (CarrierRestrictionRules) response;
7119 }
7120 // Response is an Exception of some kind,
7121 // which is signalled to the user as a NULL retval
7122 return null;
7123 } catch (Exception e) {
7124 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7125 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007126 } finally {
7127 Binder.restoreCallingIdentity(identity);
7128 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007129 }
7130
fionaxu59545b42016-05-25 15:53:37 -07007131 /**
7132 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7133 * @param subId the subscription ID that this action applies to.
7134 * @param enabled control enable or disable metered apns.
7135 * {@hide}
7136 */
7137 @Override
7138 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7139 enforceModifyPermission();
7140 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141
7142 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007143 if (phone == null) {
7144 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7145 return;
7146 }
7147 try {
7148 phone.carrierActionSetMeteredApnsEnabled(enabled);
7149 } catch (Exception e) {
7150 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007151 } finally {
7152 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007153 }
7154 }
7155
7156 /**
7157 * Action set from carrier signalling broadcast receivers to enable/disable radio
7158 * @param subId the subscription ID that this action applies to.
7159 * @param enabled control enable or disable radio.
7160 * {@hide}
7161 */
7162 @Override
7163 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7164 enforceModifyPermission();
7165 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166
7167 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007168 if (phone == null) {
7169 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7170 return;
7171 }
7172 try {
7173 phone.carrierActionSetRadioEnabled(enabled);
7174 } catch (Exception e) {
7175 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176 } finally {
7177 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007178 }
7179 }
7180
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007181 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007182 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7183 * network status based on which carrier apps could apply actions accordingly,
7184 * enable/disable default url handler for example.
7185 *
7186 * @param subId the subscription ID that this action applies to.
7187 * @param report control start/stop reporting the default network status.
7188 * {@hide}
7189 */
7190 @Override
7191 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7192 enforceModifyPermission();
7193 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194
7195 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007196 if (phone == null) {
7197 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7198 return;
7199 }
7200 try {
7201 phone.carrierActionReportDefaultNetworkStatus(report);
7202 } catch (Exception e) {
7203 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204 } finally {
7205 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007206 }
7207 }
7208
7209 /**
fionaxud9622282017-07-17 17:51:30 -07007210 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7211 * @param subId the subscription ID that this action applies to.
7212 * {@hide}
7213 */
7214 @Override
7215 public void carrierActionResetAll(int subId) {
7216 enforceModifyPermission();
7217 final Phone phone = getPhone(subId);
7218 if (phone == null) {
7219 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7220 return;
7221 }
7222 try {
7223 phone.carrierActionResetAll();
7224 } catch (Exception e) {
7225 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7226 }
7227 }
7228
7229 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007230 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7231 * bug report is being generated.
7232 */
7233 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007234 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007235 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7236 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007237 writer.println("Permission Denial: can't dump Phone from pid="
7238 + Binder.getCallingPid()
7239 + ", uid=" + Binder.getCallingUid()
7240 + "without permission "
7241 + android.Manifest.permission.DUMP);
7242 return;
7243 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007244 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007245 }
Jack Yueb89b242016-06-22 13:27:47 -07007246
Brad Ebingerdac2f002018-04-03 15:17:52 -07007247 @Override
7248 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7249 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7250 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007251 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7252 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007253 }
7254
Jack Yueb89b242016-06-22 13:27:47 -07007255 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007256 * Policy control of data connection. Usually used when data limit is passed.
7257 * @param enabled True if enabling the data, otherwise disabling.
7258 * @param subId Subscription index
7259 * {@hide}
7260 */
7261 @Override
7262 public void setPolicyDataEnabled(boolean enabled, int subId) {
7263 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007264
7265 final long identity = Binder.clearCallingIdentity();
7266 try {
7267 Phone phone = getPhone(subId);
7268 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007269 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007270 }
7271 } finally {
7272 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007273 }
7274 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007275
7276 /**
7277 * Get Client request stats
7278 * @return List of Client Request Stats
7279 * @hide
7280 */
7281 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007282 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7283 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007284 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007285 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007286 return null;
7287 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007288 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007289
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007290 final long identity = Binder.clearCallingIdentity();
7291 try {
7292 if (phone != null) {
7293 return phone.getClientRequestStats();
7294 }
7295
7296 return null;
7297 } finally {
7298 Binder.restoreCallingIdentity(identity);
7299 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007300 }
7301
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007302 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007303 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007304 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007305 }
Jack Yueb4124c2017-02-16 15:32:43 -08007306
7307 /**
Grace Chen70990072017-03-24 17:21:30 -07007308 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007309 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007310 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007311 * @param state State of SIM (power down, power up, pass through)
7312 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7313 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7314 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007315 *
7316 **/
7317 @Override
Grace Chen70990072017-03-24 17:21:30 -07007318 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007319 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007320 Phone phone = PhoneFactory.getPhone(slotIndex);
7321
vagdeviaf9a5b92018-08-15 16:01:53 -07007322 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7323
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007324 final long identity = Binder.clearCallingIdentity();
7325 try {
7326 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007327 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007328 }
7329 } finally {
7330 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007331 }
7332 }
Shuo Qiandd210312017-04-12 22:11:33 +00007333
Tyler Gunn65d45c22017-06-05 11:22:26 -07007334 private boolean isUssdApiAllowed(int subId) {
7335 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007336 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007337 if (configManager == null) {
7338 return false;
7339 }
7340 PersistableBundle pb = configManager.getConfigForSubId(subId);
7341 if (pb == null) {
7342 return false;
7343 }
7344 return pb.getBoolean(
7345 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7346 }
7347
Shuo Qiandd210312017-04-12 22:11:33 +00007348 /**
7349 * Check if phone is in emergency callback mode
7350 * @return true if phone is in emergency callback mode
7351 * @param subId sub id
7352 */
goneil9c5f4872017-12-05 14:07:56 -08007353 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007354 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007355 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007356 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007357
7358 final long identity = Binder.clearCallingIdentity();
7359 try {
7360 if (phone != null) {
7361 return phone.isInEcm();
7362 } else {
7363 return false;
7364 }
7365 } finally {
7366 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007367 }
7368 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007369
7370 /**
7371 * Get the current signal strength information for the given subscription.
7372 * Because this information is not updated when the device is in a low power state
7373 * it should not be relied-upon to be current.
7374 * @param subId Subscription index
7375 * @return the most recent cached signal strength info from the modem
7376 */
7377 @Override
7378 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 Phone p = getPhone(subId);
7382 if (p == null) {
7383 return null;
7384 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007385
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007386 return p.getSignalStrength();
7387 } finally {
7388 Binder.restoreCallingIdentity(identity);
7389 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007390 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007391
Pengquan Meng77b7f132018-08-22 14:49:57 -07007392 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007393 * Get the current modem radio state for the given slot.
7394 * @param slotIndex slot index.
7395 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007396 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007397 * @return the current radio power state from the modem
7398 */
7399 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007400 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007401 Phone phone = PhoneFactory.getPhone(slotIndex);
7402 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007403 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7404 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007405 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7406 }
7407
7408 final long identity = Binder.clearCallingIdentity();
7409 try {
7410 return phone.getRadioPowerState();
7411 } finally {
7412 Binder.restoreCallingIdentity(identity);
7413 }
7414 }
7415 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7416 }
7417
7418 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007419 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7420 *
7421 * <p>Requires one of the following permissions:
7422 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7423 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7424 * privileges.
7425 *
7426 * @param subId subscription id
7427 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7428 * {@code false}.
7429 */
7430 @Override
7431 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007432 try {
7433 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7434 null);
7435 } catch (Exception e) {
7436 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7437 mApp, subId, "isDataRoamingEnabled");
7438 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007439
Pengquan Menga1bb6272018-09-06 09:59:22 -07007440 boolean isEnabled = false;
7441 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007442 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007443 Phone phone = getPhone(subId);
7444 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007445 } finally {
7446 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007447 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007448 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007449 }
7450
7451
7452 /**
7453 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7454 *
7455 * <p> Requires permission:
7456 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7457 * privileges.
7458 *
7459 * @param subId subscription id
7460 * @param isEnabled {@code true} means enable, {@code false} means disable.
7461 */
7462 @Override
7463 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007464 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7465 mApp, subId, "setDataRoamingEnabled");
7466
Pengquan Menga1bb6272018-09-06 09:59:22 -07007467 final long identity = Binder.clearCallingIdentity();
7468 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007469 Phone phone = getPhone(subId);
7470 if (phone != null) {
7471 phone.setDataRoamingEnabled(isEnabled);
7472 }
7473 } finally {
7474 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007475 }
7476 }
7477
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007478 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007479 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007480 TelephonyPermissions
7481 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007482 mApp, subId, "isManualNetworkSelectionAllowed");
7483
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007484 boolean isAllowed = true;
7485 final long identity = Binder.clearCallingIdentity();
7486 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007487 Phone phone = getPhone(subId);
7488 if (phone != null) {
7489 isAllowed = phone.isCspPlmnEnabled();
7490 }
7491 } finally {
7492 Binder.restoreCallingIdentity(identity);
7493 }
7494 return isAllowed;
7495 }
7496
7497 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007498 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007499 // Verify that tha callingPackage belongs to the calling UID
7500 mApp.getSystemService(AppOpsManager.class)
7501 .checkPackage(Binder.getCallingUid(), callingPackage);
7502
Jordan Liu1e142fc2019-04-22 15:10:43 -07007503 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007504 try {
7505 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007506 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007507 } catch (SecurityException e) {
7508 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7509 // has carrier privileges on an active UICC
7510 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7511 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007512 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007513 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007514 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007515
7516 final long identity = Binder.clearCallingIdentity();
7517 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007518 UiccController uiccController = UiccController.getInstance();
7519 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007520 if (hasReadPermission) {
7521 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007522 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007523
7524 // Remove private info if the caller doesn't have access
7525 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7526 for (UiccCardInfo cardInfo : cardInfos) {
7527 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7528 // is available
7529 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7530 if (card == null || card.getUiccProfile() == null) {
7531 // assume no access if the card or profile is unavailable
7532 filteredInfos.add(cardInfo.getUnprivileged());
7533 continue;
7534 }
7535 UiccProfile profile = card.getUiccProfile();
7536 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7537 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7538 filteredInfos.add(cardInfo);
7539 } else {
7540 filteredInfos.add(cardInfo.getUnprivileged());
7541 }
7542 }
7543 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
7547 }
7548
7549 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007550 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007551 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007552
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007553 final long identity = Binder.clearCallingIdentity();
7554 try {
7555 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7556 if (slots == null) {
7557 Rlog.i(LOG_TAG, "slots is null.");
7558 return null;
7559 }
7560
7561 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7562 for (int i = 0; i < slots.length; i++) {
7563 UiccSlot slot = slots[i];
7564 if (slot == null) {
7565 continue;
7566 }
7567
Jordan Liu7be7e652019-05-06 18:55:02 +00007568 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007569 UiccCard card = slot.getUiccCard();
7570 if (card != null) {
7571 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007572 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007573 cardId = slot.getEid();
7574 if (TextUtils.isEmpty(cardId)) {
7575 cardId = slot.getIccId();
7576 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007577 }
7578
Jordan Liu857451f2019-05-09 16:35:35 -07007579 if (cardId != null) {
7580 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7581 // if cardId is an EID, it's all digits so this is fine
7582 cardId = IccUtils.stripTrailingFs(cardId);
7583 }
7584
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007585 int cardState = 0;
7586 switch (slot.getCardState()) {
7587 case CARDSTATE_ABSENT:
7588 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7589 break;
7590 case CARDSTATE_PRESENT:
7591 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7592 break;
7593 case CARDSTATE_ERROR:
7594 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7595 break;
7596 case CARDSTATE_RESTRICTED:
7597 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7598 break;
7599 default:
7600 break;
7601
7602 }
7603
7604 infos[i] = new UiccSlotInfo(
7605 slot.isActive(),
7606 slot.isEuicc(),
7607 cardId,
7608 cardState,
7609 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007610 slot.isExtendedApduSupported(),
7611 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 }
7613 return infos;
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007616 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007617 }
7618
7619 @Override
7620 public boolean switchSlots(int[] physicalSlots) {
7621 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622
7623 final long identity = Binder.clearCallingIdentity();
7624 try {
7625 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7626 } finally {
7627 Binder.restoreCallingIdentity(identity);
7628 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007629 }
Jack Yu4c988042018-02-27 15:30:01 -08007630
7631 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007632 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007633 final long identity = Binder.clearCallingIdentity();
7634 try {
7635 return UiccController.getInstance().getCardIdForDefaultEuicc();
7636 } finally {
7637 Binder.restoreCallingIdentity(identity);
7638 }
7639 }
7640
Pengquan Meng85728fb2018-03-12 16:31:21 -07007641 /**
goneil47ffb6e2018-04-06 15:40:58 -07007642 * A test API to reload the UICC profile.
7643 *
7644 * <p>Requires that the calling app has permission
7645 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7646 * @hide
7647 */
7648 @Override
7649 public void refreshUiccProfile(int subId) {
7650 enforceModifyPermission();
7651
7652 final long identity = Binder.clearCallingIdentity();
7653 try {
7654 Phone phone = getPhone(subId);
7655 if (phone == null) {
7656 return;
7657 }
7658 UiccCard uiccCard = phone.getUiccCard();
7659 if (uiccCard == null) {
7660 return;
7661 }
7662 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7663 if (uiccProfile == null) {
7664 return;
7665 }
7666 uiccProfile.refresh();
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
7669 }
7670 }
7671
7672 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007673 * Returns false if the mobile data is disabled by default, otherwise return true.
7674 */
7675 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007676 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007677 }
7678
7679 /**
7680 * Returns true if the data roaming is enabled by default, i.e the system property
7681 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7682 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7683 */
7684 private boolean getDefaultDataRoamingEnabled(int subId) {
7685 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007686 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007687 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007688 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7689 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7690 return isDataRoamingEnabled;
7691 }
7692
7693 /**
7694 * Returns the default network type for the given {@code subId}, if the default network type is
7695 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7696 */
7697 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007698 List<Integer> list = TelephonyProperties.default_network();
7699 int phoneId = mSubscriptionController.getPhoneId(subId);
7700 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7701 return list.get(phoneId);
7702 }
7703 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007704 }
fionaxua13278b2018-03-21 00:08:13 -07007705
7706 @Override
7707 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007708 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007709 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710
7711 final long identity = Binder.clearCallingIdentity();
7712 try {
7713 final Phone phone = getPhone(subId);
7714 if (phone == null) {
7715 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7716 return;
7717 }
chen xueaba88a2019-03-15 13:15:10 -07007718 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7719 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007720 } finally {
7721 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007722 }
fionaxua13278b2018-03-21 00:08:13 -07007723 }
7724
7725 @Override
7726 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007727 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007728
7729 final long identity = Binder.clearCallingIdentity();
7730 try {
7731 final Phone phone = getPhone(subId);
7732 if (phone == null) {
7733 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7734 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7735 }
7736 return phone.getCarrierIdListVersion();
7737 } finally {
7738 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007739 }
fionaxua13278b2018-03-21 00:08:13 -07007740 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007741
7742 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007743 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7744 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007745 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007746 mApp, subId, callingPackage, callingFeatureId,
7747 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007748 return -1;
7749 }
7750
7751 final long identity = Binder.clearCallingIdentity();
7752 try {
7753 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7754 } finally {
7755 Binder.restoreCallingIdentity(identity);
7756 }
7757 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007758
7759 @Override
7760 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007761 TelephonyPermissions
7762 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007763 mApp, subId, "getCdmaRoamingMode");
7764
7765 final long identity = Binder.clearCallingIdentity();
7766 try {
7767 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7768 } finally {
7769 Binder.restoreCallingIdentity(identity);
7770 }
7771 }
7772
7773 @Override
7774 public boolean setCdmaRoamingMode(int subId, int mode) {
7775 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7776 mApp, subId, "setCdmaRoamingMode");
7777
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
7785
7786 @Override
7787 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7789 mApp, subId, "setCdmaSubscriptionMode");
7790
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
7797 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007798
sqianc5eccab2018-10-19 18:46:41 -07007799 @Override
sqian8c685422019-02-22 15:55:18 -08007800 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007801 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007802 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007803 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7804 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007805 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7806 }
7807 final long identity = Binder.clearCallingIdentity();
7808 try {
sqian854d44b2018-12-12 16:48:18 -08007809 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7810 for (Phone phone: PhoneFactory.getPhones()) {
7811 if (phone.getEmergencyNumberTracker() != null
7812 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7813 emergencyNumberListInternal.put(
7814 phone.getSubId(),
7815 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7816 }
sqian11b7a0e2018-12-05 18:48:28 -08007817 }
sqian854d44b2018-12-12 16:48:18 -08007818 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007819 } finally {
7820 Binder.restoreCallingIdentity(identity);
7821 }
sqianc5eccab2018-10-19 18:46:41 -07007822 }
7823
7824 @Override
sqian8c685422019-02-22 15:55:18 -08007825 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007826 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007827 if (!exactMatch) {
7828 TelephonyPermissions
7829 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007830 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007831 }
7832 final long identity = Binder.clearCallingIdentity();
7833 try {
sqian854d44b2018-12-12 16:48:18 -08007834 for (Phone phone: PhoneFactory.getPhones()) {
7835 if (phone.getEmergencyNumberTracker() != null
7836 && phone.getEmergencyNumberTracker() != null) {
7837 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7838 number, exactMatch)) {
7839 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007840 }
7841 }
sqian11b7a0e2018-12-05 18:48:28 -08007842 }
7843 return false;
7844 } finally {
7845 Binder.restoreCallingIdentity(identity);
7846 }
7847 }
7848
sqianf4ca7ed2019-01-15 18:32:07 -08007849 /**
7850 * Update emergency number list for test mode.
7851 */
7852 @Override
7853 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7854 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7855 "updateEmergencyNumberListTestMode");
7856
7857 final long identity = Binder.clearCallingIdentity();
7858 try {
7859 for (Phone phone: PhoneFactory.getPhones()) {
7860 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7861 if (tracker != null) {
7862 tracker.executeEmergencyNumberTestModeCommand(action, num);
7863 }
7864 }
7865 } finally {
7866 Binder.restoreCallingIdentity(identity);
7867 }
7868 }
7869
7870 /**
7871 * Get the full emergency number list for test mode.
7872 */
7873 @Override
7874 public List<String> getEmergencyNumberListTestMode() {
7875 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7876 "getEmergencyNumberListTestMode");
7877
7878 final long identity = Binder.clearCallingIdentity();
7879 try {
7880 Set<String> emergencyNumbers = new HashSet<>();
7881 for (Phone phone: PhoneFactory.getPhones()) {
7882 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7883 if (tracker != null) {
7884 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7885 emergencyNumbers.add(num.getNumber());
7886 }
7887 }
7888 }
7889 return new ArrayList<>(emergencyNumbers);
7890 } finally {
7891 Binder.restoreCallingIdentity(identity);
7892 }
7893 }
7894
chen xud6b45bd2018-10-30 22:27:10 -07007895 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007896 public int getEmergencyNumberDbVersion(int subId) {
7897 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7898
7899 final long identity = Binder.clearCallingIdentity();
7900 try {
7901 final Phone phone = getPhone(subId);
7902 if (phone == null) {
7903 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7904 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7905 }
7906 return phone.getEmergencyNumberDbVersion();
7907 } finally {
7908 Binder.restoreCallingIdentity(identity);
7909 }
7910 }
7911
7912 @Override
7913 public void notifyOtaEmergencyNumberDbInstalled() {
7914 enforceModifyPermission();
7915
7916 final long identity = Binder.clearCallingIdentity();
7917 try {
7918 for (Phone phone: PhoneFactory.getPhones()) {
7919 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7920 if (tracker != null) {
7921 tracker.updateOtaEmergencyNumberDatabase();
7922 }
7923 }
7924 } finally {
7925 Binder.restoreCallingIdentity(identity);
7926 }
7927 }
7928
7929 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007930 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007931 enforceActiveEmergencySessionPermission();
7932
7933 final long identity = Binder.clearCallingIdentity();
7934 try {
7935 for (Phone phone: PhoneFactory.getPhones()) {
7936 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7937 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007938 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7939 }
7940 }
7941 } finally {
7942 Binder.restoreCallingIdentity(identity);
7943 }
7944 }
7945
7946 @Override
7947 public void resetOtaEmergencyNumberDbFilePath() {
7948 enforceActiveEmergencySessionPermission();
7949
7950 final long identity = Binder.clearCallingIdentity();
7951 try {
7952 for (Phone phone: PhoneFactory.getPhones()) {
7953 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7954 if (tracker != null) {
7955 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007956 }
7957 }
7958 } finally {
7959 Binder.restoreCallingIdentity(identity);
7960 }
7961 }
7962
7963 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007964 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7965 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7966 Phone phone = getPhone(subId);
7967 if (phone == null) {
7968 return null;
7969 }
7970 final long identity = Binder.clearCallingIdentity();
7971 try {
7972 UiccProfile profile = UiccController.getInstance()
7973 .getUiccProfileForPhone(phone.getPhoneId());
7974 if (profile != null) {
7975 return profile.getCertsFromCarrierPrivilegeAccessRules();
7976 }
7977 } finally {
7978 Binder.restoreCallingIdentity(identity);
7979 }
7980 return null;
7981 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007982
7983 /**
7984 * Enable or disable a modem stack.
7985 */
7986 @Override
7987 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7988 enforceModifyPermission();
7989
7990 final long identity = Binder.clearCallingIdentity();
7991 try {
7992 Phone phone = PhoneFactory.getPhone(slotIndex);
7993 if (phone == null) {
7994 return false;
7995 } else {
7996 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7997 }
7998 } finally {
7999 Binder.restoreCallingIdentity(identity);
8000 }
8001 }
Michelecea4cf22018-12-21 15:00:11 -08008002
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008003 /**
8004 * Whether a modem stack is enabled or not.
8005 */
8006 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008007 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8008 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008009 Phone phone = PhoneFactory.getPhone(slotIndex);
8010 if (phone == null) return false;
8011
8012 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008013 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8014 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008015 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8016 }
8017
8018 final long identity = Binder.clearCallingIdentity();
8019 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008020 try {
8021 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8022 } catch (NoSuchElementException ex) {
8023 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8024 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
8028 }
8029
Michelecea4cf22018-12-21 15:00:11 -08008030 @Override
Michele0ea7d782019-03-19 14:58:42 -07008031 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008032 enforceModifyPermission();
8033
8034 final long identity = Binder.clearCallingIdentity();
8035 try {
8036 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008037 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008038 .commit();
8039 } finally {
8040 Binder.restoreCallingIdentity(identity);
8041 }
8042 }
8043
8044 @Override
Michele0ea7d782019-03-19 14:58:42 -07008045 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008046 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008048 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8049 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008050 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008051 }
Michelecea4cf22018-12-21 15:00:11 -08008052
8053 final long identity = Binder.clearCallingIdentity();
8054 try {
Michele0ea7d782019-03-19 14:58:42 -07008055 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
8059 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008060
Michele0ea7d782019-03-19 14:58:42 -07008061 @TelephonyManager.IsMultiSimSupportedResult
8062 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008063 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8064 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8065 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008066 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8067 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008068 }
8069 // Check if the hardware supports multisim functionality. If usage of multisim is not
8070 // supported by the modem, indicate that it is restricted.
8071 PhoneCapability staticCapability =
8072 mPhoneConfigurationManager.getStaticPhoneCapability();
8073 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008074 loge("isMultiSimSupportedInternal: no static configuration available");
8075 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008076 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008077 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008078 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8079 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008080 }
8081 // Check if support of multiple SIMs is restricted by carrier
8082 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008083 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008084 }
8085
Michele0ea7d782019-03-19 14:58:42 -07008086 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008087 }
8088
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008089 /**
8090 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008091 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8092 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8093 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008094 * @param numOfSims number of active sims we want to switch to
8095 */
8096 @Override
8097 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008098 if (numOfSims == 1) {
8099 enforceModifyPermission();
8100 } else {
8101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8102 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8103 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008104 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008105
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008106 try {
Michele30b57b22019-03-01 12:01:14 -08008107 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008108 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008109 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8110 return;
8111 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008112 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8113 } finally {
8114 Binder.restoreCallingIdentity(identity);
8115 }
8116 }
8117
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008118 @Override
8119 public boolean isApplicationOnUicc(int subId, int appType) {
8120 enforceReadPrivilegedPermission("isApplicationOnUicc");
8121 Phone phone = getPhone(subId);
8122 if (phone == null) {
8123 return false;
8124 }
8125 final long identity = Binder.clearCallingIdentity();
8126 try {
8127 UiccCard uiccCard = phone.getUiccCard();
8128 if (uiccCard == null) {
8129 return false;
8130 }
8131 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8132 if (uiccProfile == null) {
8133 return false;
8134 }
8135 if (TelephonyManager.APPTYPE_SIM <= appType
8136 && appType <= TelephonyManager.APPTYPE_ISIM) {
8137 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8138 }
8139 return false;
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
8142 }
8143 }
8144
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008145 /**
chen xub4baa772019-04-03 10:23:41 -07008146 * Get whether making changes to modem configurations will trigger reboot.
8147 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008148 */
8149 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008150 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8151 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008152 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008153 mApp, subId, callingPackage, callingFeatureId,
8154 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008155 return false;
8156 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008157 final long identity = Binder.clearCallingIdentity();
8158 try {
8159 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
8163 }
8164
Nathan Harold29f5f052019-02-15 13:41:57 -08008165 private void updateModemStateMetrics() {
8166 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8167 // TODO: check the state for each modem if the api is ready.
8168 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8169 }
8170
Pengquan Meng3889a572019-01-23 11:16:29 -08008171 @Override
8172 public int[] getSlotsMapping() {
8173 enforceReadPrivilegedPermission("getSlotsMapping");
8174
8175 final long identity = Binder.clearCallingIdentity();
8176 try {
8177 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8178 // All logical slots should have a mapping to a physical slot.
8179 int[] logicalSlotsMapping = new int[phoneCount];
8180 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8181 for (int i = 0; i < slotInfos.length; i++) {
8182 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8183 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8184 }
8185 }
8186 return logicalSlotsMapping;
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
8190 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008191
8192 /**
8193 * Get the IRadio HAL Version
8194 */
8195 @Override
8196 public int getRadioHalVersion() {
8197 Phone phone = getDefaultPhone();
8198 if (phone == null) return -1;
8199 HalVersion hv = phone.getHalVersion();
8200 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8201 return hv.major * 100 + hv.minor;
8202 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008203
8204 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008205 * Get the current calling package name.
8206 * @return the current calling package name
8207 */
8208 @Override
8209 public String getCurrentPackageName() {
8210 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8211 }
8212
8213 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008214 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8215 * corresponding network requests on a subId.
8216 *
8217 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008218 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008219 * 2) APN is un-metered for this subscription, or
8220 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008221 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008222 *
8223 * @return whether data is allowed for a apn type.
8224 *
8225 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008226 */
8227 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008228 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008229 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8230 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008231
8232 // Now that all security checks passes, perform the operation as ourselves.
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 Phone phone = getPhone(subId);
8236 if (phone == null) return false;
8237
Jack Yu41407ee2019-05-13 16:54:09 -07008238 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008239 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8240 } finally {
8241 Binder.restoreCallingIdentity(identity);
8242 }
8243 }
8244
8245 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008246 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008247 enforceReadPrivilegedPermission("isApnMetered");
8248
8249 // Now that all security checks passes, perform the operation as ourselves.
8250 final long identity = Binder.clearCallingIdentity();
8251 try {
8252 Phone phone = getPhone(subId);
8253 if (phone == null) return true; // By default return true.
8254
Jack Yu41407ee2019-05-13 16:54:09 -07008255 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008256 } finally {
8257 Binder.restoreCallingIdentity(identity);
8258 }
8259 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008260
8261 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008262 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8263 int subscriptionId, IBooleanConsumer resultCallback) {
8264 enforceModifyPermission();
8265 long token = Binder.clearCallingIdentity();
8266 try {
8267 Phone phone = getPhone(subscriptionId);
8268 if (phone == null) {
8269 try {
8270 if (resultCallback != null) {
8271 resultCallback.accept(false);
8272 }
8273 } catch (RemoteException e) {
8274 // ignore
8275 }
8276 return;
8277 }
8278 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8279 Pair.create(specifiers, (x) -> {
8280 try {
8281 if (resultCallback != null) {
8282 resultCallback.accept(x);
8283 }
8284 } catch (RemoteException e) {
8285 // ignore
8286 }
8287 });
8288 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8289 } finally {
8290 Binder.restoreCallingIdentity(token);
8291 }
8292 }
8293
8294 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008295 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8296 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8297 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8298 if (iccRecords == null) {
8299 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8300 return false;
8301 }
8302 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8303 }
8304
8305 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008306 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8307 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008308 if (callingPackage == null) {
8309 callingPackage = getCurrentPackageName();
8310 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008311 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8312 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008313 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8314 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008315 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8316 }
8317 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8318 Intent intent = new Intent();
8319 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8320 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8321 // Bring up choose default SMS subscription dialog right now
8322 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8323 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8324 mApp.startActivity(intent);
8325 }
chen xud5ca2d52019-05-28 15:20:57 -07008326
8327 @Override
8328 public String getMmsUAProfUrl(int subId) {
8329 //TODO investigate if this API should require proper permission check in R b/133791609
8330 final long identity = Binder.clearCallingIdentity();
8331 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008332 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8333 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8334 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8335 return carrierUAProfUrl;
8336 }
chen xud5ca2d52019-05-28 15:20:57 -07008337 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8338 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8339 } finally {
8340 Binder.restoreCallingIdentity(identity);
8341 }
8342 }
8343
8344 @Override
8345 public String getMmsUserAgent(int subId) {
8346 //TODO investigate if this API should require proper permission check in R b/133791609
8347 final long identity = Binder.clearCallingIdentity();
8348 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008349 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8350 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8351 if (!TextUtils.isEmpty(carrierUserAgent)) {
8352 return carrierUserAgent;
8353 }
chen xud5ca2d52019-05-28 15:20:57 -07008354 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8355 .getString(com.android.internal.R.string.config_mms_user_agent);
8356 } finally {
8357 Binder.restoreCallingIdentity(identity);
8358 }
8359 }
Jack Yub07d4972019-05-28 16:12:25 -07008360
8361 @Override
8362 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8363 enforceModifyPermission();
8364
8365 // Now that all security checks passes, perform the operation as ourselves.
8366 final long identity = Binder.clearCallingIdentity();
8367 try {
8368 Phone phone = getPhone(subId);
8369 if (phone == null) return false;
8370
8371 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8372 } finally {
8373 Binder.restoreCallingIdentity(identity);
8374 }
8375 }
8376
8377 @Override
8378 public boolean isDataAllowedInVoiceCall(int subId) {
8379 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8380
8381 // Now that all security checks passes, perform the operation as ourselves.
8382 final long identity = Binder.clearCallingIdentity();
8383 try {
8384 Phone phone = getPhone(subId);
8385 if (phone == null) return false;
8386
8387 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8388 } finally {
8389 Binder.restoreCallingIdentity(identity);
8390 }
8391 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008392
changbetty97defcf2019-12-24 15:40:37 +08008393 @Override
8394 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8395 enforceModifyPermission();
8396
8397 // Now that all security checks passes, perform the operation as ourselves.
8398 final long identity = Binder.clearCallingIdentity();
8399 try {
8400 Phone phone = getPhone(subId);
8401 if (phone == null) return false;
8402
8403 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
8408
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008409 /**
8410 * Updates whether conference event pacakge handling is enabled.
8411 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8412 * otherwise.
8413 */
8414 @Override
8415 public void setCepEnabled(boolean isCepEnabled) {
8416 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8417
8418 final long identity = Binder.clearCallingIdentity();
8419 try {
8420 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8421 for (Phone phone : PhoneFactory.getPhones()) {
8422 Phone defaultPhone = phone.getImsPhone();
8423 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8424 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8425 ImsPhoneCallTracker imsPhoneCallTracker =
8426 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8427 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8428 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8429 + imsPhone.getMsisdn());
8430 }
8431 }
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
allenwtsu46dcc572020-01-08 18:24:03 +08008436
8437 /**
8438 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8439 *
8440 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8441 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8442 * before being read.
8443 */
8444 @Override
8445 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8446 isCompressed) {
8447 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8448 mApp, subId, "notifyRcsAutoConfigurationReceived");
8449 try {
8450 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8451 if (configBinder == null) {
8452 Rlog.e(LOG_TAG, "null result for getImsConfig");
8453 } else {
8454 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8455 }
8456 } catch (RemoteException e) {
8457 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8458 }
8459 }
zoey chenf95ca592019-12-30 16:11:23 +08008460
8461 @Override
8462 public boolean isIccLockEnabled(int subId) {
8463 enforceReadPrivilegedPermission("isIccLockEnabled");
8464
8465 // Now that all security checks passes, perform the operation as ourselves.
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 Phone phone = getPhone(subId);
8469 if (phone != null && phone.getIccCard() != null) {
8470 return phone.getIccCard().getIccLockEnabled();
8471 } else {
8472 return false;
8473 }
8474 } finally {
8475 Binder.restoreCallingIdentity(identity);
8476 }
8477 }
8478
8479 /**
8480 * Set the ICC pin lock enabled or disabled..
8481 *
8482 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8483 * 0 or a positive integer as the attempts remaining value.
8484 *
8485 */
8486 @Override
8487 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8488 enforceModifyPermission();
8489
8490 Phone phone = getPhone(subId);
8491 if (phone == null) {
8492 return 0;
8493 }
8494 // Now that all security checks passes, perform the operation as ourselves.
8495 final long identity = Binder.clearCallingIdentity();
8496 try {
8497 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8498 new Pair<Boolean, String>(enabled, password), phone, null);
8499 return attemptsRemaining;
8500
8501 } catch (Exception e) {
8502 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8503 } finally {
8504 Binder.restoreCallingIdentity(identity);
8505 }
8506 return 0;
8507 }
8508
8509 /**
8510 * Change the ICC password used in ICC pin lock.
8511 *
8512 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8513 * 0 or a positive integer as the attempts remaining value.
8514 *
8515 */
8516 @Override
8517 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8518 enforceModifyPermission();
8519
8520 Phone phone = getPhone(subId);
8521 if (phone == null) {
8522 return 0;
8523 }
8524 // Now that all security checks passes, perform the operation as ourselves.
8525 final long identity = Binder.clearCallingIdentity();
8526 try {
8527 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8528 new Pair<String, String>(oldPassword, newPassword), phone, null);
8529 return attemptsRemaining;
8530
8531 } catch (Exception e) {
8532 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8533 } finally {
8534 Binder.restoreCallingIdentity(identity);
8535 }
8536 return 0;
8537 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008538
8539 @Override
8540 public boolean canConnectTo5GInDsdsMode() {
8541 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8542 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008543}