blob: 46d6463539b5be92494ccf8e726e5ef986500c2a [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;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Jordan Liua39e6c12020-03-04 13:59:23 -0800124import com.android.internal.annotations.VisibleForTesting;
sqian80370722020-01-29 15:02:51 -0800125import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700126import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700127import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700128import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800129import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700130import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700131import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800132import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700133import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800134import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800135import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700136import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800137import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700138import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800139import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700140import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700141import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700142import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700143import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700144import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800145import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700146import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700147import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700148import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700149import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700150import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700151import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700152import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700153import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800154import com.android.internal.telephony.SubscriptionController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Hall Liud0d1dc92020-01-20 13:42:00 -0800194import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700195
196/**
197 * Implementation of the ITelephony interface.
198 */
Santos Cordon117fee72014-05-16 17:56:12 -0700199public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700200 private static final String LOG_TAG = "PhoneInterfaceManager";
201 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
202 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800203 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204
205 // Message codes used with mMainThreadHandler
206 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700207 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
208 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700209 private static final int CMD_OPEN_CHANNEL = 9;
210 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
211 private static final int CMD_CLOSE_CHANNEL = 11;
212 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800213 private static final int CMD_NV_READ_ITEM = 13;
214 private static final int EVENT_NV_READ_ITEM_DONE = 14;
215 private static final int CMD_NV_WRITE_ITEM = 15;
216 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
217 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
218 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700219 private static final int CMD_RESET_MODEM_CONFIG = 19;
220 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800221 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
222 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
223 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
224 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800225 private static final int CMD_SEND_ENVELOPE = 25;
226 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000227 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
228 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700229 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
230 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
231 private static final int CMD_EXCHANGE_SIM_IO = 31;
232 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800233 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
234 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700235 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
236 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700237 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
238 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700239 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
240 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
241 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
242 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700243 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
244 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
245 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
246 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700247 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800248 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
249 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000250 private static final int CMD_SWITCH_SLOTS = 50;
251 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700252 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
253 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
254 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
255 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
256 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
257 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
258 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
259 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700260 private static final int CMD_GET_ALL_CELL_INFO = 60;
261 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
262 private static final int CMD_GET_CELL_LOCATION = 62;
263 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700264 private static final int CMD_MODEM_REBOOT = 64;
265 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700266 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
267 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800268 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
269 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700270 private static final int CMD_GET_MODEM_STATUS = 70;
271 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700272 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
273 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700274 private static final int CMD_ERASE_MODEM_CONFIG = 74;
275 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800276 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
277 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
278 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
279 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800280 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
281 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
sqian80370722020-01-29 15:02:51 -0800282 private static final int CMD_GET_CALL_FORWARDING = 83;
283 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
284 private static final int CMD_SET_CALL_FORWARDING = 85;
285 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
286 private static final int CMD_GET_CALL_WAITING = 87;
287 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
288 private static final int CMD_SET_CALL_WAITING = 89;
289 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700290
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800291 // Parameters of select command.
292 private static final int SELECT_COMMAND = 0xA4;
293 private static final int SELECT_P1 = 0x04;
294 private static final int SELECT_P2 = 0;
295 private static final int SELECT_P3 = 0x10;
296
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700297 /** The singleton instance. */
298 private static PhoneInterfaceManager sInstance;
299
Wink Saville3ab207e2014-11-20 13:07:20 -0800300 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800301 private CallManager mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -0800302 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700303 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800304 private AppOpsManager mAppOps;
305 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800306 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800307 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700308 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700309
Derek Tan97ebb422014-09-05 16:55:38 -0700310 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
311 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800312 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800313 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700314
Michelecea4cf22018-12-21 15:00:11 -0800315 // String to store multi SIM allowed
316 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
317
Derek Tan740e1672017-06-27 14:56:27 -0700318 // The AID of ISD-R.
319 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
320
yinxub1bed742017-04-17 11:45:04 -0700321 private NetworkScanRequestTracker mNetworkScanRequestTracker;
322
David Kelly5e06a7f2018-03-12 14:10:59 +0000323 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
324 private static final int MANUFACTURER_CODE_LENGTH = 8;
325
Derek Tan89e89d42014-07-08 17:00:10 -0700326 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700327 * Experiment flag to enable erase modem config on reset network, default value is false
328 */
329 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
330 "reset_network_erase_modem_config_enabled";
331
332 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700333 * A request object to use for transmitting data to an ICC.
334 */
335 private static final class IccAPDUArgument {
336 public int channel, cla, command, p1, p2, p3;
337 public String data;
338
339 public IccAPDUArgument(int channel, int cla, int command,
340 int p1, int p2, int p3, String data) {
341 this.channel = channel;
342 this.cla = cla;
343 this.command = command;
344 this.p1 = p1;
345 this.p2 = p2;
346 this.p3 = p3;
347 this.data = data;
348 }
349 }
350
351 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700352 * A request object to use for transmitting data to an ICC.
353 */
354 private static final class ManualNetworkSelectionArgument {
355 public OperatorInfo operatorInfo;
356 public boolean persistSelection;
357
358 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
359 this.operatorInfo = operatorInfo;
360 this.persistSelection = persistSelection;
361 }
362 }
363
364 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700365 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
366 * request after sending. The main thread will notify the request when it is complete.
367 */
368 private static final class MainThreadRequest {
369 /** The argument to use for the request */
370 public Object argument;
371 /** The result of the request that is run on the main thread */
372 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800373 // The subscriber id that this request applies to. Defaults to
374 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
375 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700376
Nathan Harold92bed182018-10-12 18:16:49 -0700377 // In cases where subId is unavailable, the caller needs to specify the phone.
378 public Phone phone;
379
vagdeviaf9a5b92018-08-15 16:01:53 -0700380 public WorkSource workSource;
381
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382 public MainThreadRequest(Object argument) {
383 this.argument = argument;
384 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800385
Nathan Harold92bed182018-10-12 18:16:49 -0700386 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
387 this.argument = argument;
388 if (phone != null) {
389 this.phone = phone;
390 }
391 this.workSource = workSource;
392 }
393
vagdeviaf9a5b92018-08-15 16:01:53 -0700394 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800395 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800396 if (subId != null) {
397 this.subId = subId;
398 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700399 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800400 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700401 }
402
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800403 private static final class IncomingThirdPartyCallArgs {
404 public final ComponentName component;
405 public final String callId;
406 public final String callerDisplayName;
407
408 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
409 String callerDisplayName) {
410 this.component = component;
411 this.callId = callId;
412 this.callerDisplayName = callerDisplayName;
413 }
414 }
415
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700416 /**
417 * A handler that processes messages on the main thread in the phone process. Since many
418 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
419 * inbound binder threads to the main thread in the phone process. The Binder thread
420 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
421 * on, which will be notified when the operation completes and will contain the result of the
422 * request.
423 *
424 * <p>If a MainThreadRequest object is provided in the msg.obj field,
425 * note that request.result must be set to something non-null for the calling thread to
426 * unblock.
427 */
428 private final class MainThreadHandler extends Handler {
429 @Override
430 public void handleMessage(Message msg) {
431 MainThreadRequest request;
432 Message onCompleted;
433 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800434 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700435 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800436 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700437
438 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700439 case CMD_HANDLE_USSD_REQUEST: {
440 request = (MainThreadRequest) msg.obj;
441 final Phone phone = getPhoneFromRequest(request);
442 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
443 String ussdRequest = ussdObject.first;
444 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700445
Pengquan Menga1bb6272018-09-06 09:59:22 -0700446 if (!isUssdApiAllowed(request.subId)) {
447 // Carrier does not support use of this API, return failure.
448 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
449 UssdResponse response = new UssdResponse(ussdRequest, null);
450 Bundle returnData = new Bundle();
451 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
452 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 request.result = true;
455 notifyRequester(request);
456 return;
457 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700458
Pengquan Menga1bb6272018-09-06 09:59:22 -0700459 try {
460 request.result = phone != null
461 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
462 } catch (CallStateException cse) {
463 request.result = false;
464 }
465 // Wake up the requesting thread
466 notifyRequester(request);
467 break;
pkanwar32d516d2016-10-14 19:37:38 -0700468 }
469
Yorke Lee716f67e2015-06-17 15:39:16 -0700470 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700471 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700472 final Phone phone = getPhoneFromRequest(request);
473 request.result = phone != null ?
474 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
475 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700476 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700477 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700478 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700481 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700482 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700483 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800484 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700485 if (uiccCard == null) {
486 loge("iccTransmitApduLogicalChannel: No UICC");
487 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700488 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
491 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700492 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700493 iccArgument.channel, iccArgument.cla, iccArgument.command,
494 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700495 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700497 break;
498
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700500 ar = (AsyncResult) msg.obj;
501 request = (MainThreadRequest) ar.userObj;
502 if (ar.exception == null && ar.result != null) {
503 request.result = ar.result;
504 } else {
505 request.result = new IccIoResult(0x6F, 0, (byte[])null);
506 if (ar.result == null) {
507 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800508 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800510 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700511 } else {
512 loge("iccTransmitApduLogicalChannel: Unknown exception");
513 }
514 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700515 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700516 break;
517
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700518 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
519 request = (MainThreadRequest) msg.obj;
520 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800521 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 if (uiccCard == null) {
523 loge("iccTransmitApduBasicChannel: No UICC");
524 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700525 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 } else {
527 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
528 request);
529 uiccCard.iccTransmitApduBasicChannel(
530 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
531 iccArgument.p3, iccArgument.data, onCompleted);
532 }
533 break;
534
535 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
536 ar = (AsyncResult) msg.obj;
537 request = (MainThreadRequest) ar.userObj;
538 if (ar.exception == null && ar.result != null) {
539 request.result = ar.result;
540 } else {
541 request.result = new IccIoResult(0x6F, 0, (byte[])null);
542 if (ar.result == null) {
543 loge("iccTransmitApduBasicChannel: Empty response");
544 } else if (ar.exception instanceof CommandException) {
545 loge("iccTransmitApduBasicChannel: CommandException: " +
546 ar.exception);
547 } else {
548 loge("iccTransmitApduBasicChannel: Unknown exception");
549 }
550 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700551 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700552 break;
553
554 case CMD_EXCHANGE_SIM_IO:
555 request = (MainThreadRequest) msg.obj;
556 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800557 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 if (uiccCard == null) {
559 loge("iccExchangeSimIO: No UICC");
560 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700561 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 } else {
563 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
564 request);
565 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
566 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
567 iccArgument.data, onCompleted);
568 }
569 break;
570
571 case EVENT_EXCHANGE_SIM_IO_DONE:
572 ar = (AsyncResult) msg.obj;
573 request = (MainThreadRequest) ar.userObj;
574 if (ar.exception == null && ar.result != null) {
575 request.result = ar.result;
576 } else {
577 request.result = new IccIoResult(0x6f, 0, (byte[])null);
578 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700579 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700580 break;
581
Derek Tan4d5e5c12014-02-04 11:54:58 -0800582 case CMD_SEND_ENVELOPE:
583 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800584 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700585 if (uiccCard == null) {
586 loge("sendEnvelopeWithStatus: No UICC");
587 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 } else {
590 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
591 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
592 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800593 break;
594
595 case EVENT_SEND_ENVELOPE_DONE:
596 ar = (AsyncResult) msg.obj;
597 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700598 if (ar.exception == null && ar.result != null) {
599 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800600 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700601 request.result = new IccIoResult(0x6F, 0, (byte[])null);
602 if (ar.result == null) {
603 loge("sendEnvelopeWithStatus: Empty response");
604 } else if (ar.exception instanceof CommandException) {
605 loge("sendEnvelopeWithStatus: CommandException: " +
606 ar.exception);
607 } else {
608 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
609 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800610 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700611 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800612 break;
613
Shishir Agrawal566b7612013-10-28 14:41:00 -0700614 case CMD_OPEN_CHANNEL:
615 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800616 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800617 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700618 if (uiccCard == null) {
619 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800620 request.result = new IccOpenLogicalChannelResponse(-1,
621 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700622 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700623 } else {
624 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
626 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700628 break;
629
630 case EVENT_OPEN_CHANNEL_DONE:
631 ar = (AsyncResult) msg.obj;
632 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700633 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700635 int[] result = (int[]) ar.result;
636 int channelId = result[0];
637 byte[] selectResponse = null;
638 if (result.length > 1) {
639 selectResponse = new byte[result.length - 1];
640 for (int i = 1; i < result.length; ++i) {
641 selectResponse[i - 1] = (byte) result[i];
642 }
643 }
644 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700645 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700646 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700647 if (ar.result == null) {
648 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700649 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700650 if (ar.exception != null) {
651 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
652 }
653
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700654 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700655 if (ar.exception instanceof CommandException) {
656 CommandException.Error error =
657 ((CommandException) (ar.exception)).getCommandError();
658 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700659 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700660 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700661 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700662 }
663 }
664 openChannelResp = new IccOpenLogicalChannelResponse(
665 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700666 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700667 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700668 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700669 break;
670
671 case CMD_CLOSE_CHANNEL:
672 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800673 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700674 if (uiccCard == null) {
675 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900676 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 } else {
679 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
680 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
681 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700682 break;
683
684 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800685 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
686 break;
687
688 case CMD_NV_READ_ITEM:
689 request = (MainThreadRequest) msg.obj;
690 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800691 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
692 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800693 break;
694
695 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700696 ar = (AsyncResult) msg.obj;
697 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800698 if (ar.exception == null && ar.result != null) {
699 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800701 request.result = "";
702 if (ar.result == null) {
703 loge("nvReadItem: Empty response");
704 } else if (ar.exception instanceof CommandException) {
705 loge("nvReadItem: CommandException: " +
706 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700707 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800708 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 }
710 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700711 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700712 break;
713
Jake Hambye994d462014-02-03 13:10:13 -0800714 case CMD_NV_WRITE_ITEM:
715 request = (MainThreadRequest) msg.obj;
716 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
717 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800718 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700719 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800720 break;
721
722 case EVENT_NV_WRITE_ITEM_DONE:
723 handleNullReturnEvent(msg, "nvWriteItem");
724 break;
725
726 case CMD_NV_WRITE_CDMA_PRL:
727 request = (MainThreadRequest) msg.obj;
728 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800729 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800730 break;
731
732 case EVENT_NV_WRITE_CDMA_PRL_DONE:
733 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
734 break;
735
chen xu6dac5ab2018-10-26 17:39:23 -0700736 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800737 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700738 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800739 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case EVENT_RESET_MODEM_CONFIG_DONE:
743 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
Jake Hamby7c27be32014-03-03 13:25:59 -0800746 case CMD_GET_PREFERRED_NETWORK_TYPE:
747 request = (MainThreadRequest) msg.obj;
748 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700749 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 break;
751
752 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
753 ar = (AsyncResult) msg.obj;
754 request = (MainThreadRequest) ar.userObj;
755 if (ar.exception == null && ar.result != null) {
756 request.result = ar.result; // Integer
757 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530758 // request.result must be set to something non-null
759 // for the calling thread to unblock
760 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800761 if (ar.result == null) {
762 loge("getPreferredNetworkType: Empty response");
763 } else if (ar.exception instanceof CommandException) {
764 loge("getPreferredNetworkType: CommandException: " +
765 ar.exception);
766 } else {
767 loge("getPreferredNetworkType: Unknown exception");
768 }
769 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700770 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800771 break;
772
773 case CMD_SET_PREFERRED_NETWORK_TYPE:
774 request = (MainThreadRequest) msg.obj;
775 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
776 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700777 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800778 break;
779
780 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
781 handleNullReturnEvent(msg, "setPreferredNetworkType");
782 break;
783
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000784 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
785 request = (MainThreadRequest)msg.obj;
786 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800787 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 break;
789
790 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
791 ar = (AsyncResult)msg.obj;
792 request = (MainThreadRequest)ar.userObj;
793 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700794 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000795 break;
796
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800797 case CMD_SET_VOICEMAIL_NUMBER:
798 request = (MainThreadRequest) msg.obj;
799 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
800 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800801 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
802 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800803 break;
804
805 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
806 handleNullReturnEvent(msg, "setVoicemailNumber");
807 break;
808
Stuart Scott54788802015-03-30 13:18:01 -0700809 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
810 request = (MainThreadRequest) msg.obj;
811 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
812 request);
813 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
814 break;
815
816 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
817 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
818 break;
819
Shishir Agrawal302c8692015-06-19 13:49:39 -0700820 case CMD_PERFORM_NETWORK_SCAN:
821 request = (MainThreadRequest) msg.obj;
822 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
823 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
824 break;
825
sqian80370722020-01-29 15:02:51 -0800826 case CMD_GET_CALL_FORWARDING:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
829 int callForwardingReason = (Integer) request.argument;
830 getPhoneFromRequest(request).getCallForwardingOption(
831 callForwardingReason, onCompleted);
832 break;
833
834 case EVENT_GET_CALL_FORWARDING_DONE:
835 ar = (AsyncResult) msg.obj;
836 request = (MainThreadRequest) ar.userObj;
837 CallForwardingInfo callForwardingInfo = null;
838 if (ar.exception == null && ar.result != null) {
839 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
840 for (CallForwardInfo callForwardInfo : callForwardInfos) {
841 // Service Class is a bit mask per 3gpp 27.007. Search for
842 // any service for voice call.
843 if ((callForwardInfo.serviceClass
844 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
845 callForwardingInfo = new CallForwardingInfo(
846 callForwardInfo.serviceClass, callForwardInfo.reason,
847 callForwardInfo.number,
848 callForwardInfo.timeSeconds);
849 break;
850 }
851 }
852 // Didn't find a call forward info for voice call.
853 if (callForwardingInfo == null) {
854 callForwardingInfo = new CallForwardingInfo(
855 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
856 0 /* reason */, null /* number */, 0 /* timeout */);
857 }
858 } else {
859 if (ar.result == null) {
860 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
861 }
862 if (ar.exception != null) {
863 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
864 }
865 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
866 if (ar.exception instanceof CommandException) {
867 CommandException.Error error =
868 ((CommandException) (ar.exception)).getCommandError();
869 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
870 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
871 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
872 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
873 }
874 }
875 callForwardingInfo = new CallForwardingInfo(
876 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
877 }
878 request.result = callForwardingInfo;
879 notifyRequester(request);
880 break;
881
882 case CMD_SET_CALL_FORWARDING:
883 request = (MainThreadRequest) msg.obj;
884 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
885 CallForwardingInfo callForwardingInfoToSet =
886 (CallForwardingInfo) request.argument;
887 getPhoneFromRequest(request).setCallForwardingOption(
888 callForwardingInfoToSet.getStatus(),
889 callForwardingInfoToSet.getReason(),
890 callForwardingInfoToSet.getNumber(),
891 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
892 break;
893
894 case EVENT_SET_CALL_FORWARDING_DONE:
895 ar = (AsyncResult) msg.obj;
896 request = (MainThreadRequest) ar.userObj;
897 if (ar.exception == null) {
898 request.result = true;
899 } else {
900 request.result = false;
901 loge("setCallForwarding exception: " + ar.exception);
902 }
903 notifyRequester(request);
904 break;
905
906 case CMD_GET_CALL_WAITING:
907 request = (MainThreadRequest) msg.obj;
908 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
909 getPhoneFromRequest(request).getCallWaiting(onCompleted);
910 break;
911
912 case EVENT_GET_CALL_WAITING_DONE:
913 ar = (AsyncResult) msg.obj;
914 request = (MainThreadRequest) ar.userObj;
915 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
916 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800917 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800918 // Service Class is a bit mask per 3gpp 27.007.
919 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800920 if (callForwardResults.length > 1
921 && ((callForwardResults[1]
922 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
923 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800924 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
925 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
926 } else {
927 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
928 }
929 } else {
930 if (ar.result == null) {
931 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
932 }
933 if (ar.exception != null) {
934 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
935 }
936 if (ar.exception instanceof CommandException) {
937 CommandException.Error error =
938 ((CommandException) (ar.exception)).getCommandError();
939 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
940 callForwardingStatus =
941 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
942 }
943 }
944 }
945 request.result = callForwardingStatus;
946 notifyRequester(request);
947 break;
948
949 case CMD_SET_CALL_WAITING:
950 request = (MainThreadRequest) msg.obj;
951 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
952 boolean isEnable = (Boolean) request.argument;
953 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
954 break;
955
956 case EVENT_SET_CALL_WAITING_DONE:
957 ar = (AsyncResult) msg.obj;
958 request = (MainThreadRequest) ar.userObj;
959 if (ar.exception == null) {
960 request.result = true;
961 } else {
962 request.result = false;
963 loge("setCallWaiting exception: " + ar.exception);
964 }
965 notifyRequester(request);
966 break;
967
Shishir Agrawal302c8692015-06-19 13:49:39 -0700968 case EVENT_PERFORM_NETWORK_SCAN_DONE:
969 ar = (AsyncResult) msg.obj;
970 request = (MainThreadRequest) ar.userObj;
971 CellNetworkScanResult cellScanResult;
972 if (ar.exception == null && ar.result != null) {
973 cellScanResult = new CellNetworkScanResult(
974 CellNetworkScanResult.STATUS_SUCCESS,
975 (List<OperatorInfo>) ar.result);
976 } else {
977 if (ar.result == null) {
978 loge("getCellNetworkScanResults: Empty response");
979 }
980 if (ar.exception != null) {
981 loge("getCellNetworkScanResults: Exception: " + ar.exception);
982 }
983 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
984 if (ar.exception instanceof CommandException) {
985 CommandException.Error error =
986 ((CommandException) (ar.exception)).getCommandError();
987 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
988 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
989 } else if (error == CommandException.Error.GENERIC_FAILURE) {
990 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
991 }
992 }
993 cellScanResult = new CellNetworkScanResult(errorCode, null);
994 }
995 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700996 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -0700997 break;
998
999 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1000 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001001 ManualNetworkSelectionArgument selArg =
1002 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001003 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1004 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1006 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 break;
1008
1009 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001010 ar = (AsyncResult) msg.obj;
1011 request = (MainThreadRequest) ar.userObj;
1012 if (ar.exception == null) {
1013 request.result = true;
1014 } else {
1015 request.result = false;
1016 loge("setNetworkSelectionModeManual " + ar.exception);
1017 }
1018 notifyRequester(request);
1019 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001020 break;
1021
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001022 case CMD_GET_MODEM_ACTIVITY_INFO:
1023 request = (MainThreadRequest) msg.obj;
1024 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001025 if (defaultPhone != null) {
1026 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001027 } else {
1028 ResultReceiver result = (ResultReceiver) request.argument;
1029 Bundle bundle = new Bundle();
1030 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1031 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1032 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001033 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001034 break;
1035
1036 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1037 ar = (AsyncResult) msg.obj;
1038 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001039 ResultReceiver result = (ResultReceiver) request.argument;
1040
1041 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001042 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001043 // Update the last modem activity info and the result of the request.
1044 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1045 if (isModemActivityInfoValid(info)) {
1046 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1047 int[] txTimeMs = info.getTransmitTimeMillis();
1048 int[] lastModemTxTimeMs = mLastModemActivityInfo
1049 .getTransmitTimeMillis();
1050 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1051 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1052 }
1053 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1054 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1055 + mLastModemActivityInfo.getSleepTimeMillis());
1056 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1057 + mLastModemActivityInfo.getIdleTimeMillis());
1058 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1059 mLastModemActivityInfo.setReceiveTimeMillis(
1060 info.getReceiveTimeMillis()
1061 + mLastModemActivityInfo.getReceiveTimeMillis());
1062 }
1063 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1064 mLastModemActivityInfo.getSleepTimeMillis(),
1065 mLastModemActivityInfo.getIdleTimeMillis(),
1066 mLastModemActivityInfo.getTransmitTimeMillis(),
1067 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001068 } else {
1069 if (ar.result == null) {
1070 loge("queryModemActivityInfo: Empty response");
1071 } else if (ar.exception instanceof CommandException) {
1072 loge("queryModemActivityInfo: CommandException: " +
1073 ar.exception);
1074 } else {
1075 loge("queryModemActivityInfo: Unknown exception");
1076 }
1077 }
sqian1a1be542020-03-05 11:37:28 -08001078 Bundle bundle = new Bundle();
1079 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1080 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001081 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001082 break;
1083
Meng Wang1a7c35a2016-05-05 20:56:15 -07001084 case CMD_SET_ALLOWED_CARRIERS:
1085 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001086 CarrierRestrictionRules argument =
1087 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001089 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 break;
1091
1092 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1093 ar = (AsyncResult) msg.obj;
1094 request = (MainThreadRequest) ar.userObj;
1095 if (ar.exception == null && ar.result != null) {
1096 request.result = ar.result;
1097 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001098 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1099 if (ar.exception instanceof CommandException) {
1100 loge("setAllowedCarriers: CommandException: " + ar.exception);
1101 CommandException.Error error =
1102 ((CommandException) (ar.exception)).getCommandError();
1103 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1104 request.result =
1105 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1106 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001107 } else {
1108 loge("setAllowedCarriers: Unknown exception");
1109 }
1110 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001111 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001112 break;
1113
1114 case CMD_GET_ALLOWED_CARRIERS:
1115 request = (MainThreadRequest) msg.obj;
1116 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001117 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001118 break;
1119
1120 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1121 ar = (AsyncResult) msg.obj;
1122 request = (MainThreadRequest) ar.userObj;
1123 if (ar.exception == null && ar.result != null) {
1124 request.result = ar.result;
1125 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001126 request.result = new IllegalStateException(
1127 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001128 if (ar.result == null) {
1129 loge("getAllowedCarriers: Empty response");
1130 } else if (ar.exception instanceof CommandException) {
1131 loge("getAllowedCarriers: CommandException: " +
1132 ar.exception);
1133 } else {
1134 loge("getAllowedCarriers: Unknown exception");
1135 }
1136 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001137 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001138 break;
1139
Nathan Haroldb3014052017-01-25 15:57:32 -08001140 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1141 ar = (AsyncResult) msg.obj;
1142 request = (MainThreadRequest) ar.userObj;
1143 if (ar.exception == null && ar.result != null) {
1144 request.result = ar.result;
1145 } else {
1146 request.result = new IllegalArgumentException(
1147 "Failed to retrieve Forbidden Plmns");
1148 if (ar.result == null) {
1149 loge("getForbiddenPlmns: Empty response");
1150 } else {
1151 loge("getForbiddenPlmns: Unknown exception");
1152 }
1153 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001154 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001155 break;
1156
1157 case CMD_GET_FORBIDDEN_PLMNS:
1158 request = (MainThreadRequest) msg.obj;
1159 uiccCard = getUiccCardFromRequest(request);
1160 if (uiccCard == null) {
1161 loge("getForbiddenPlmns() UiccCard is null");
1162 request.result = new IllegalArgumentException(
1163 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001164 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001165 break;
1166 }
1167 Integer appType = (Integer) request.argument;
1168 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1169 if (uiccApp == null) {
1170 loge("getForbiddenPlmns() no app with specified type -- "
1171 + appType);
1172 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001173 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001174 break;
1175 } else {
1176 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1177 + " specified type -- " + appType);
1178 }
1179 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1180 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1181 onCompleted);
1182 break;
1183
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001184 case CMD_SWITCH_SLOTS:
1185 request = (MainThreadRequest) msg.obj;
1186 int[] physicalSlots = (int[]) request.argument;
1187 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1188 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1189 break;
1190
1191 case EVENT_SWITCH_SLOTS_DONE:
1192 ar = (AsyncResult) msg.obj;
1193 request = (MainThreadRequest) ar.userObj;
1194 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001195 notifyRequester(request);
1196 break;
1197 case CMD_GET_NETWORK_SELECTION_MODE:
1198 request = (MainThreadRequest) msg.obj;
1199 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1200 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1201 break;
1202
1203 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1204 ar = (AsyncResult) msg.obj;
1205 request = (MainThreadRequest) ar.userObj;
1206 if (ar.exception != null) {
1207 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1208 } else {
1209 int mode = ((int[]) ar.result)[0];
1210 if (mode == 0) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1212 } else {
1213 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1214 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001215 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001216 notifyRequester(request);
1217 break;
1218 case CMD_GET_CDMA_ROAMING_MODE:
1219 request = (MainThreadRequest) msg.obj;
1220 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1221 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1222 break;
1223 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1224 ar = (AsyncResult) msg.obj;
1225 request = (MainThreadRequest) ar.userObj;
1226 if (ar.exception != null) {
1227 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1228 } else {
1229 request.result = ((int[]) ar.result)[0];
1230 }
1231 notifyRequester(request);
1232 break;
1233 case CMD_SET_CDMA_ROAMING_MODE:
1234 request = (MainThreadRequest) msg.obj;
1235 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1236 int mode = (int) request.argument;
1237 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1238 break;
1239 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1240 ar = (AsyncResult) msg.obj;
1241 request = (MainThreadRequest) ar.userObj;
1242 request.result = ar.exception == null;
1243 notifyRequester(request);
1244 break;
1245 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1246 request = (MainThreadRequest) msg.obj;
1247 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1248 int subscriptionMode = (int) request.argument;
1249 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1250 break;
1251 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1252 ar = (AsyncResult) msg.obj;
1253 request = (MainThreadRequest) ar.userObj;
1254 request.result = ar.exception == null;
1255 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001256 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001257 case CMD_GET_ALL_CELL_INFO:
1258 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001259 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001260 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001262 case EVENT_GET_ALL_CELL_INFO_DONE:
1263 ar = (AsyncResult) msg.obj;
1264 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001265 // If a timeout occurs, the response will be null
1266 request.result = (ar.exception == null && ar.result != null)
1267 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 synchronized (request) {
1269 request.notifyAll();
1270 }
1271 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001272 case CMD_REQUEST_CELL_INFO_UPDATE:
1273 request = (MainThreadRequest) msg.obj;
1274 request.phone.requestCellInfoUpdate(request.workSource,
1275 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1276 break;
1277 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1278 ar = (AsyncResult) msg.obj;
1279 request = (MainThreadRequest) ar.userObj;
1280 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1281 try {
1282 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001283 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001284 cb.onError(
1285 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1286 ar.exception.getClass().getName(),
1287 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001288 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001290 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001291 } else {
1292 // use the result as returned
1293 cb.onCellInfo((List<CellInfo>) ar.result);
1294 }
1295 } catch (RemoteException re) {
1296 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1297 }
1298 break;
1299 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001300 request = (MainThreadRequest) msg.obj;
1301 WorkSource ws = (WorkSource) request.argument;
1302 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001303 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001305 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001306 ar = (AsyncResult) msg.obj;
1307 request = (MainThreadRequest) ar.userObj;
1308 if (ar.exception == null) {
1309 request.result = ar.result;
1310 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001311 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001313 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001314 }
1315
1316 synchronized (request) {
1317 request.notifyAll();
1318 }
1319 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001320 case CMD_MODEM_REBOOT:
1321 request = (MainThreadRequest) msg.obj;
1322 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001323 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001324 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001325 case EVENT_CMD_MODEM_REBOOT_DONE:
1326 handleNullReturnEvent(msg, "rebootModem");
1327 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001328 case CMD_REQUEST_ENABLE_MODEM:
1329 request = (MainThreadRequest) msg.obj;
1330 boolean enable = (boolean) request.argument;
1331 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001332 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001333 PhoneConfigurationManager.getInstance()
1334 .enablePhone(request.phone, enable, onCompleted);
1335 break;
1336 case EVENT_ENABLE_MODEM_DONE:
1337 ar = (AsyncResult) msg.obj;
1338 request = (MainThreadRequest) ar.userObj;
1339 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001340 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001341 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001342 if ((boolean) request.result) {
1343 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1344 updateModemStateMetrics();
1345 } else {
1346 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1347 + ar.exception);
1348 }
1349 notifyRequester(request);
1350 break;
1351 case CMD_GET_MODEM_STATUS:
1352 request = (MainThreadRequest) msg.obj;
1353 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1354 PhoneConfigurationManager.getInstance()
1355 .getPhoneStatusFromModem(request.phone, onCompleted);
1356 break;
1357 case EVENT_GET_MODEM_STATUS_DONE:
1358 ar = (AsyncResult) msg.obj;
1359 request = (MainThreadRequest) ar.userObj;
1360 int id = request.phone.getPhoneId();
1361 if (ar.exception == null && ar.result != null) {
1362 request.result = ar.result;
1363 //update the cache as modem status has changed
1364 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1365 (boolean) request.result);
1366 } else {
1367 // Return true if modem status cannot be retrieved. For most cases,
1368 // modem status is on. And for older version modems, GET_MODEM_STATUS
1369 // and disable modem are not supported. Modem is always on.
1370 // TODO: this should be fixed in R to support a third
1371 // status UNKNOWN b/131631629
1372 request.result = true;
1373 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1374 + ar.exception);
1375 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001376 notifyRequester(request);
1377 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001378 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1379 request = (MainThreadRequest) msg.obj;
1380 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1381 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1382 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1383 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1384 break;
1385 }
1386 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1387 ar = (AsyncResult) msg.obj;
1388 request = (MainThreadRequest) ar.userObj;
1389 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1390 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1391 args.second.accept(ar.exception == null);
1392 notifyRequester(request);
1393 break;
1394 }
yincheng zhaod698b842019-09-06 17:06:54 -07001395 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1396 ar = (AsyncResult) msg.obj;
1397 request = (MainThreadRequest) ar.userObj;
1398 if (ar.exception == null && ar.result != null) {
1399 request.result = ar.result;
1400 } else {
1401 request.result = -1;
1402 loge("Failed to set Forbidden Plmns");
1403 if (ar.result == null) {
1404 loge("setForbidenPlmns: Empty response");
1405 } else if (ar.exception != null) {
1406 loge("setForbiddenPlmns: Exception: " + ar.exception);
1407 request.result = -1;
1408 } else {
1409 loge("setForbiddenPlmns: Unknown exception");
1410 }
1411 }
1412 notifyRequester(request);
1413 break;
1414 case CMD_SET_FORBIDDEN_PLMNS:
1415 request = (MainThreadRequest) msg.obj;
1416 uiccCard = getUiccCardFromRequest(request);
1417 if (uiccCard == null) {
1418 loge("setForbiddenPlmns: UiccCard is null");
1419 request.result = -1;
1420 notifyRequester(request);
1421 break;
1422 }
1423 Pair<Integer, List<String>> setFplmnsArgs =
1424 (Pair<Integer, List<String>>) request.argument;
1425 appType = setFplmnsArgs.first;
1426 List<String> fplmns = setFplmnsArgs.second;
1427 uiccApp = uiccCard.getApplicationByType(appType);
1428 if (uiccApp == null) {
1429 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1430 request.result = -1;
1431 loge("Failed to get UICC App");
1432 notifyRequester(request);
1433 } else {
1434 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1435 ((SIMRecords) uiccApp.getIccRecords())
1436 .setForbiddenPlmns(onCompleted, fplmns);
1437 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001438 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001439 case CMD_ERASE_MODEM_CONFIG:
1440 request = (MainThreadRequest) msg.obj;
1441 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1442 defaultPhone.eraseModemConfig(onCompleted);
1443 break;
1444 case EVENT_ERASE_MODEM_CONFIG_DONE:
1445 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001446 break;
zoey chenf95ca592019-12-30 16:11:23 +08001447
1448 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1449 request = (MainThreadRequest) msg.obj;
1450 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1451 Pair<String, String> changed = (Pair<String, String>) request.argument;
1452 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1453 changed.first, changed.second, onCompleted);
1454 break;
1455 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1456 ar = (AsyncResult) msg.obj;
1457 request = (MainThreadRequest) ar.userObj;
1458 if (ar.exception == null) {
1459 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1460 } else {
1461 request.result = msg.arg1;
1462 }
1463 notifyRequester(request);
1464 break;
1465
1466 case CMD_SET_ICC_LOCK_ENABLED:
1467 request = (MainThreadRequest) msg.obj;
1468 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1469 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1470 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1471 enabled.first, enabled.second, onCompleted);
1472 break;
1473 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1474 ar = (AsyncResult) msg.obj;
1475 request = (MainThreadRequest) ar.userObj;
1476 if (ar.exception == null) {
1477 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1478 } else {
1479 request.result = msg.arg1;
1480 }
1481 notifyRequester(request);
1482 break;
1483
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001484 default:
1485 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1486 break;
1487 }
1488 }
Jake Hambye994d462014-02-03 13:10:13 -08001489
Pengquan Menga1bb6272018-09-06 09:59:22 -07001490 private void notifyRequester(MainThreadRequest request) {
1491 synchronized (request) {
1492 request.notifyAll();
1493 }
1494 }
1495
Jake Hambye994d462014-02-03 13:10:13 -08001496 private void handleNullReturnEvent(Message msg, String command) {
1497 AsyncResult ar = (AsyncResult) msg.obj;
1498 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1499 if (ar.exception == null) {
1500 request.result = true;
1501 } else {
1502 request.result = false;
1503 if (ar.exception instanceof CommandException) {
1504 loge(command + ": CommandException: " + ar.exception);
1505 } else {
1506 loge(command + ": Unknown exception");
1507 }
1508 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001509 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001510 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001511 }
1512
1513 /**
1514 * Posts the specified command to be executed on the main thread,
1515 * waits for the request to complete, and returns the result.
1516 * @see #sendRequestAsync
1517 */
1518 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001519 return sendRequest(
1520 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001521 }
1522
1523 /**
1524 * Posts the specified command to be executed on the main thread,
1525 * waits for the request to complete, and returns the result.
1526 * @see #sendRequestAsync
1527 */
1528 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1529 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001530 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001531 }
1532
1533 /**
1534 * Posts the specified command to be executed on the main thread,
1535 * waits for the request to complete, and returns the result.
1536 * @see #sendRequestAsync
1537 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001538 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001539 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001540 }
1541
1542 /**
1543 * Posts the specified command to be executed on the main thread,
1544 * waits for the request to complete, and returns the result.
1545 * @see #sendRequestAsync
1546 */
Nathan Harold92bed182018-10-12 18:16:49 -07001547 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1548 return sendRequest(command, argument, subId, null, workSource);
1549 }
1550
1551 /**
1552 * Posts the specified command to be executed on the main thread,
1553 * waits for the request to complete, and returns the result.
1554 * @see #sendRequestAsync
1555 */
1556 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1557 return sendRequest(
1558 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1559 }
1560
1561 /**
1562 * Posts the specified command to be executed on the main thread,
1563 * waits for the request to complete, and returns the result.
1564 * @see #sendRequestAsync
1565 */
1566 private Object sendRequest(
1567 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001568 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1569 throw new RuntimeException("This method will deadlock if called from the main thread.");
1570 }
1571
Nathan Harold92bed182018-10-12 18:16:49 -07001572 MainThreadRequest request = null;
1573 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1574 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1575 } else if (phone != null) {
1576 request = new MainThreadRequest(argument, phone, workSource);
1577 } else {
1578 request = new MainThreadRequest(argument, subId, workSource);
1579 }
1580
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 Message msg = mMainThreadHandler.obtainMessage(command, request);
1582 msg.sendToTarget();
1583
1584 // Wait for the request to complete
1585 synchronized (request) {
1586 while (request.result == null) {
1587 try {
1588 request.wait();
1589 } catch (InterruptedException e) {
1590 // Do nothing, go back and wait until the request is complete
1591 }
1592 }
1593 }
1594 return request.result;
1595 }
1596
1597 /**
1598 * Asynchronous ("fire and forget") version of sendRequest():
1599 * Posts the specified command to be executed on the main thread, and
1600 * returns immediately.
1601 * @see #sendRequest
1602 */
1603 private void sendRequestAsync(int command) {
1604 mMainThreadHandler.sendEmptyMessage(command);
1605 }
1606
1607 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001608 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001609 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001610 */
1611 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001612 sendRequestAsync(command, argument, null, null);
1613 }
1614
1615 /**
1616 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1617 * @see {@link #sendRequest(int,Object)}
1618 */
1619 private void sendRequestAsync(
1620 int command, Object argument, Phone phone, WorkSource workSource) {
1621 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001622 Message msg = mMainThreadHandler.obtainMessage(command, request);
1623 msg.sendToTarget();
1624 }
1625
1626 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001627 * Initialize the singleton PhoneInterfaceManager instance.
1628 * This is only done once, at startup, from PhoneApp.onCreate().
1629 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001630 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001631 synchronized (PhoneInterfaceManager.class) {
1632 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001633 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001634 } else {
1635 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1636 }
1637 return sInstance;
1638 }
1639 }
1640
1641 /** Private constructor; @see init() */
Jordan Liua39e6c12020-03-04 13:59:23 -08001642 @VisibleForTesting
1643 /* package */ PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001646 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001647 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1649 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001650 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001651 mTelephonySharedPreferences =
1652 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001653 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001654 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Wink Saville3ab207e2014-11-20 13:07:20 -08001655
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 publish();
1657 }
1658
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001659 private Phone getDefaultPhone() {
1660 Phone thePhone = getPhone(getDefaultSubscription());
1661 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1662 }
1663
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001664 private void publish() {
1665 if (DBG) log("publish: " + this);
1666
1667 ServiceManager.addService("phone", this);
1668 }
1669
Stuart Scott584921c2015-01-15 17:10:34 -08001670 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001671 if (request.phone != null) {
1672 return request.phone;
1673 } else {
1674 return getPhoneFromSubId(request.subId);
1675 }
1676 }
1677
1678 private Phone getPhoneFromSubId(int subId) {
1679 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1680 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001681 }
1682
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001683 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1684 Phone phone = getPhoneFromRequest(request);
1685 return phone == null ? null :
1686 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1687 }
1688
Wink Saville36469e72014-06-11 15:17:00 -07001689 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001690 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001691 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001692 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001693
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001694 private void sendEraseModemConfig(Phone phone) {
1695 if (phone != null) {
1696 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1697 mApp, phone.getSubId(), "eraseModemConfig");
1698 final long identity = Binder.clearCallingIdentity();
1699 try {
1700 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1701 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1702 } finally {
1703 Binder.restoreCallingIdentity(identity);
1704 }
1705 }
1706 }
1707
Peter Wang050bb052020-01-13 23:33:09 -08001708 private boolean isImsAvailableOnDevice() {
1709 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1710 if (pm == null) {
1711 // For some reason package manger is not available.. This will fail internally anyway,
1712 // so do not throw error and allow.
1713 return true;
1714 }
1715 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1716 }
1717
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001718 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001719 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001720 }
1721
Wink Savilleb564aae2014-10-23 10:18:09 -07001722 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001723 if (DBG) log("dial: " + number);
1724 // No permission check needed here: This is just a wrapper around the
1725 // ACTION_DIAL intent, which is available to any app since it puts up
1726 // the UI before it does anything.
1727
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001728 final long identity = Binder.clearCallingIdentity();
1729 try {
1730 String url = createTelUrl(number);
1731 if (url == null) {
1732 return;
1733 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001735 // PENDING: should we just silently fail if phone is offhook or ringing?
1736 PhoneConstants.State state = mCM.getState(subId);
1737 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1738 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1739 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1740 mApp.startActivity(intent);
1741 }
1742 } finally {
1743 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001744 }
1745 }
1746
1747 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001748 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001749 }
1750
Wink Savilleb564aae2014-10-23 10:18:09 -07001751 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001752 if (DBG) log("call: " + number);
1753
1754 // This is just a wrapper around the ACTION_CALL intent, but we still
1755 // need to do a permission check since we're calling startActivity()
1756 // from the context of the phone app.
1757 enforceCallPermission();
1758
Jordan Liu1617b712019-07-10 15:06:26 -07001759 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 != AppOpsManager.MODE_ALLOWED) {
1761 return;
1762 }
1763
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001764 final long identity = Binder.clearCallingIdentity();
1765 try {
1766 String url = createTelUrl(number);
1767 if (url == null) {
1768 return;
1769 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001770
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001771 boolean isValid = false;
1772 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1773 if (slist != null) {
1774 for (SubscriptionInfo subInfoRecord : slist) {
1775 if (subInfoRecord.getSubscriptionId() == subId) {
1776 isValid = true;
1777 break;
1778 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001779 }
Wink Saville08874612014-08-31 19:19:58 -07001780 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 if (!isValid) {
1782 return;
1783 }
Wink Saville08874612014-08-31 19:19:58 -07001784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1786 intent.putExtra(SUBSCRIPTION_KEY, subId);
1787 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1788 mApp.startActivity(intent);
1789 } finally {
1790 Binder.restoreCallingIdentity(identity);
1791 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001792 }
1793
Wink Savilleb564aae2014-10-23 10:18:09 -07001794 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001795 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001796 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1797 }
1798
Wink Savilleb564aae2014-10-23 10:18:09 -07001799 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001800 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001801 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1802 }
1803
Wink Savilleb564aae2014-10-23 10:18:09 -07001804 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001805 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001806
1807 final long identity = Binder.clearCallingIdentity();
1808 try {
1809 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1810 checkSimPin.start();
1811 return checkSimPin.unlockSim(null, pin);
1812 } finally {
1813 Binder.restoreCallingIdentity(identity);
1814 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001815 }
1816
Wink Savilleb564aae2014-10-23 10:18:09 -07001817 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001818 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001819
1820 final long identity = Binder.clearCallingIdentity();
1821 try {
1822 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1823 checkSimPuk.start();
1824 return checkSimPuk.unlockSim(puk, pin);
1825 } finally {
1826 Binder.restoreCallingIdentity(identity);
1827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001828 }
1829
1830 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001831 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 * a synchronous one.
1833 */
1834 private static class UnlockSim extends Thread {
1835
1836 private final IccCard mSimCard;
1837
1838 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001839 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1840 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001841
1842 // For replies from SimCard interface
1843 private Handler mHandler;
1844
1845 // For async handler to identify request type
1846 private static final int SUPPLY_PIN_COMPLETE = 100;
1847
1848 public UnlockSim(IccCard simCard) {
1849 mSimCard = simCard;
1850 }
1851
1852 @Override
1853 public void run() {
1854 Looper.prepare();
1855 synchronized (UnlockSim.this) {
1856 mHandler = new Handler() {
1857 @Override
1858 public void handleMessage(Message msg) {
1859 AsyncResult ar = (AsyncResult) msg.obj;
1860 switch (msg.what) {
1861 case SUPPLY_PIN_COMPLETE:
1862 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1863 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001864 mRetryCount = msg.arg1;
1865 if (ar.exception != null) {
1866 if (ar.exception instanceof CommandException &&
1867 ((CommandException)(ar.exception)).getCommandError()
1868 == CommandException.Error.PASSWORD_INCORRECT) {
1869 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001870 } //When UiccCardApp dispose,handle message and return exception
1871 else if (ar.exception instanceof CommandException &&
1872 ((CommandException) (ar.exception)).getCommandError()
1873 == CommandException.Error.ABORTED) {
1874 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001875 } else {
1876 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1877 }
1878 } else {
1879 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1880 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001881 mDone = true;
1882 UnlockSim.this.notifyAll();
1883 }
1884 break;
1885 }
1886 }
1887 };
1888 UnlockSim.this.notifyAll();
1889 }
1890 Looper.loop();
1891 }
1892
1893 /*
1894 * Use PIN or PUK to unlock SIM card
1895 *
1896 * If PUK is null, unlock SIM card with PIN
1897 *
1898 * If PUK is not null, unlock SIM card with PUK and set PIN code
1899 */
Wink Saville9de0f752013-10-22 19:04:03 -07001900 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001901
1902 while (mHandler == null) {
1903 try {
1904 wait();
1905 } catch (InterruptedException e) {
1906 Thread.currentThread().interrupt();
1907 }
1908 }
1909 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1910
1911 if (puk == null) {
1912 mSimCard.supplyPin(pin, callback);
1913 } else {
1914 mSimCard.supplyPuk(puk, pin, callback);
1915 }
1916
1917 while (!mDone) {
1918 try {
1919 Log.d(LOG_TAG, "wait for done");
1920 wait();
1921 } catch (InterruptedException e) {
1922 // Restore the interrupted status
1923 Thread.currentThread().interrupt();
1924 }
1925 }
1926 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001927 int[] resultArray = new int[2];
1928 resultArray[0] = mResult;
1929 resultArray[1] = mRetryCount;
1930 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001931 }
1932 }
1933
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001934 /**
1935 * This method has been removed due to privacy and stability concerns.
1936 */
1937 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001938 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001939 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1940 return;
Wink Saville36469e72014-06-11 15:17:00 -07001941 }
1942
Nathan Harold1f889d82020-06-04 17:05:26 -07001943 @Override
1944 public void updateServiceLocationWithPackageName(String callingPackage) {
1945 mApp.getSystemService(AppOpsManager.class)
1946 .checkPackage(Binder.getCallingUid(), callingPackage);
1947
1948 final int targetSdk = getTargetSdk(callingPackage);
1949 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1950 // Callers targeting S have no business invoking this method.
1951 return;
1952 }
1953
1954 LocationAccessPolicy.LocationPermissionResult locationResult =
1955 LocationAccessPolicy.checkLocationPermission(mApp,
1956 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1957 .setCallingPackage(callingPackage)
1958 .setCallingFeatureId(null)
1959 .setCallingPid(Binder.getCallingPid())
1960 .setCallingUid(Binder.getCallingUid())
1961 .setMethod("updateServiceLocation")
1962 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1963 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1964 .build());
1965 // Apps that lack location permission have no business calling this method;
1966 // however, because no permission was declared in the public API, denials must
1967 // all be "soft".
1968 switch (locationResult) {
1969 case DENIED_HARD: /* fall through */
1970 case DENIED_SOFT:
1971 return;
1972 }
1973
1974 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001975 final long identity = Binder.clearCallingIdentity();
1976 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001977 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001978 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001979 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001980 }
1981 } finally {
1982 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001983 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001984 }
1985
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001986 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001987 @Override
1988 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001989 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001990 }
1991
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001992 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08001993 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1994 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1995 callingFeatureId);
1996 }
1997
1998 @Deprecated
1999 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002000 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002001 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2002 }
2003
2004 @Override
2005 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2006 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002007 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002008 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002009 return false;
2010 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002011
2012 final long identity = Binder.clearCallingIdentity();
2013 try {
2014 return isRadioOnForSubscriber(subId);
2015 } finally {
2016 Binder.restoreCallingIdentity(identity);
2017 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002018 }
2019
2020 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021 final long identity = Binder.clearCallingIdentity();
2022 try {
2023 final Phone phone = getPhone(subId);
2024 if (phone != null) {
2025 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2026 } else {
2027 return false;
2028 }
2029 } finally {
2030 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002031 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002032 }
2033
2034 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002035 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002036 }
Wink Saville36469e72014-06-11 15:17:00 -07002037
Wink Savilleb564aae2014-10-23 10:18:09 -07002038 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002039 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002040
2041 final long identity = Binder.clearCallingIdentity();
2042 try {
2043 final Phone phone = getPhone(subId);
2044 if (phone != null) {
2045 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2046 }
2047 } finally {
2048 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002049 }
Wink Saville36469e72014-06-11 15:17:00 -07002050 }
2051
2052 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002053 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002054 }
2055
Wink Savilleb564aae2014-10-23 10:18:09 -07002056 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002058
2059 final long identity = Binder.clearCallingIdentity();
2060 try {
2061 final Phone phone = getPhone(subId);
2062 if (phone == null) {
2063 return false;
2064 }
2065 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2066 toggleRadioOnOffForSubscriber(subId);
2067 }
2068 return true;
2069 } finally {
2070 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002071 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002072 }
Wink Saville36469e72014-06-11 15:17:00 -07002073
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002074 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002075 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002076 /*
2077 * If any of the Radios are available, it will need to be
2078 * shutdown. So return true if any Radio is available.
2079 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 final long identity = Binder.clearCallingIdentity();
2081 try {
2082 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2083 Phone phone = PhoneFactory.getPhone(i);
2084 if (phone != null && phone.isRadioAvailable()) return true;
2085 }
2086 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2087 return false;
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002090 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002091 }
2092
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002093 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002094 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 enforceModifyPermission();
2096
2097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2100 logv("Shutting down Phone " + i);
2101 shutdownRadioUsingPhoneId(i);
2102 }
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002105 }
2106 }
2107
2108 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002109 Phone phone = PhoneFactory.getPhone(phoneId);
2110 if (phone != null && phone.isRadioAvailable()) {
2111 phone.shutdownRadio();
2112 }
2113 }
2114
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002116 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002117
2118 final long identity = Binder.clearCallingIdentity();
2119 try {
2120 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2121 if (defaultPhone != null) {
2122 defaultPhone.setRadioPower(turnOn);
2123 return true;
2124 } else {
2125 loge("There's no default phone.");
2126 return false;
2127 }
2128 } finally {
2129 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002130 }
Wink Saville36469e72014-06-11 15:17:00 -07002131 }
2132
Wink Savilleb564aae2014-10-23 10:18:09 -07002133 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002135
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 final Phone phone = getPhone(subId);
2139 if (phone != null) {
2140 phone.setRadioPower(turnOn);
2141 return true;
2142 } else {
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002147 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002148 }
2149
Wink Saville36469e72014-06-11 15:17:00 -07002150 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002151 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002152 public boolean enableDataConnectivity() {
2153 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002154
2155 final long identity = Binder.clearCallingIdentity();
2156 try {
2157 int subId = mSubscriptionController.getDefaultDataSubId();
2158 final Phone phone = getPhone(subId);
2159 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002160 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002161 return true;
2162 } else {
2163 return false;
2164 }
2165 } finally {
2166 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002167 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002168 }
2169
Wink Saville36469e72014-06-11 15:17:00 -07002170 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002172 public boolean disableDataConnectivity() {
2173 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002174
2175 final long identity = Binder.clearCallingIdentity();
2176 try {
2177 int subId = mSubscriptionController.getDefaultDataSubId();
2178 final Phone phone = getPhone(subId);
2179 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002180 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002181 return true;
2182 } else {
2183 return false;
2184 }
2185 } finally {
2186 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002187 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002188 }
2189
Sanket Padawe356d7632015-06-22 14:03:32 -07002190 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002191 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 final Phone phone = getPhone(subId);
2195 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002196 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197 } else {
2198 return false;
2199 }
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002202 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002203 }
2204
2205 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002206 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002207 }
2208
pkanwarae03a6b2016-11-06 20:37:09 -08002209 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002210 enforceCallPermission();
2211
2212 final long identity = Binder.clearCallingIdentity();
2213 try {
2214 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2215 return;
2216 }
2217 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2218 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2219 } finally {
2220 Binder.restoreCallingIdentity(identity);
2221 }
pkanwar32d516d2016-10-14 19:37:38 -07002222 };
2223
Wink Savilleb564aae2014-10-23 10:18:09 -07002224 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002226
2227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2230 return false;
2231 }
2232 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2233 } finally {
2234 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002235 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002236 }
2237
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002239 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002240 }
2241
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002242 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243 final long identity = Binder.clearCallingIdentity();
2244 try {
2245 Phone phone = PhoneFactory.getPhone(slotIndex);
2246 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2247 PhoneConstantConversions.convertCallState(phone.getState());
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
2250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Sanket Padawe356d7632015-06-22 14:03:32 -07002253 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002254 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002255 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2256 }
2257
2258 @Override
2259 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002262 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002263 if (phone != null) {
2264 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2265 } else {
2266 return PhoneConstantConversions.convertDataState(
2267 PhoneConstants.DataState.DISCONNECTED);
2268 }
2269 } finally {
2270 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002271 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002272 }
2273
Sanket Padawe356d7632015-06-22 14:03:32 -07002274 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002275 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002276 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2277 }
2278
2279 @Override
2280 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002281 final long identity = Binder.clearCallingIdentity();
2282 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002283 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002284 if (phone != null) {
2285 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2286 } else {
2287 return TelephonyManager.DATA_ACTIVITY_NONE;
2288 }
2289 } finally {
2290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002292 }
2293
2294 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002295 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002296 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002297 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002298
2299 LocationAccessPolicy.LocationPermissionResult locationResult =
2300 LocationAccessPolicy.checkLocationPermission(mApp,
2301 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2302 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002303 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002304 .setCallingPid(Binder.getCallingPid())
2305 .setCallingUid(Binder.getCallingUid())
2306 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002307 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002308 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2309 .build());
2310 switch (locationResult) {
2311 case DENIED_HARD:
2312 throw new SecurityException("Not allowed to access cell location");
2313 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002314 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2315 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 }
2317
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002318 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002319 final long identity = Binder.clearCallingIdentity();
2320 try {
2321 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002322 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002323 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002324 } finally {
2325 Binder.restoreCallingIdentity(identity);
2326 }
Svetoslav64fad262015-04-14 14:35:21 -07002327 }
2328
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002329 @Override
Jack Yu01425032020-02-22 19:38:58 -08002330 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002331 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2332 // registered cell info, so return a NULL country instead.
2333 final long identity = Binder.clearCallingIdentity();
2334 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002335 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2336 // Get default phone in this case.
2337 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2338 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002339 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002340 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002341 if (phone == null) return "";
2342 ServiceStateTracker sst = phone.getServiceStateTracker();
2343 if (sst == null) return "";
2344 LocaleTracker lt = sst.getLocaleTracker();
2345 if (lt == null) return "";
2346 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2347 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2348 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002349 } finally {
2350 Binder.restoreCallingIdentity(identity);
2351 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002352 }
2353
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002354 /**
2355 * This method was removed due to potential issues caused by performing partial
2356 * updates of service state, and lack of a credible use case.
2357 *
2358 * This has the ability to break the telephony implementation by disabling notification of
2359 * changes in device connectivity. DO NOT USE THIS!
2360 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002361 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002362 public void enableLocationUpdates() {
2363 mApp.enforceCallingOrSelfPermission(
2364 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002365 }
2366
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002367 /**
2368 * This method was removed due to potential issues caused by performing partial
2369 * updates of service state, and lack of a credible use case.
2370 *
2371 * This has the ability to break the telephony implementation by disabling notification of
2372 * changes in device connectivity. DO NOT USE THIS!
2373 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002374 @Override
2375 public void disableLocationUpdates() {
2376 mApp.enforceCallingOrSelfPermission(
2377 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002378 }
2379
Nathan Harold31d7ff32018-10-15 20:20:30 -07002380 /**
2381 * Returns the target SDK version number for a given package name.
2382 *
Nathan Haroldec184742019-07-10 17:04:16 -07002383 * This call MUST be invoked before clearing the calling UID.
2384 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002385 * @return target SDK if the package is found or INT_MAX.
2386 */
2387 private int getTargetSdk(String packageName) {
2388 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002389 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002390 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002391 if (ai != null) return ai.targetSdkVersion;
2392 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002393 loge("Failed to get package info for pkg="
2394 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002395 }
2396 return Integer.MAX_VALUE;
2397 }
2398
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002399 @Override
2400 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002401 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2402 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002403 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002404 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2405 throw new SecurityException(
2406 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2407 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002408
Jordan Liu1617b712019-07-10 15:06:26 -07002409 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002410 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2411 return null;
2412 }
Svetoslav64fad262015-04-14 14:35:21 -07002413
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002414 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002416 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002417 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418
Nathan Haroldf180aac2018-06-01 18:43:55 -07002419 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2420 for (CellInfo ci : info) {
2421 if (ci instanceof CellInfoGsm) {
2422 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2423 } else if (ci instanceof CellInfoWcdma) {
2424 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2425 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002426 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002427 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002428 }
2429
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002430 private List<CellInfo> getCachedCellInfo() {
2431 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2432 for (Phone phone : PhoneFactory.getPhones()) {
2433 List<CellInfo> info = phone.getAllCellInfo();
2434 if (info != null) cellInfos.addAll(info);
2435 }
2436 return cellInfos;
2437 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002438
2439 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002440 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002441 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002442 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002443
2444 LocationAccessPolicy.LocationPermissionResult locationResult =
2445 LocationAccessPolicy.checkLocationPermission(mApp,
2446 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2447 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002448 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002449 .setCallingPid(Binder.getCallingPid())
2450 .setCallingUid(Binder.getCallingUid())
2451 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002452 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002453 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2454 .build());
2455 switch (locationResult) {
2456 case DENIED_HARD:
2457 throw new SecurityException("Not allowed to access cell info");
2458 case DENIED_SOFT:
2459 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002460 }
2461
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002462 final int targetSdk = getTargetSdk(callingPackage);
2463 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2464 return getCachedCellInfo();
2465 }
2466
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002467 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002468 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002469 final long identity = Binder.clearCallingIdentity();
2470 try {
2471 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2472 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002473 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002474 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002475 if (info != null) cellInfos.addAll(info);
2476 }
2477 return cellInfos;
2478 } finally {
2479 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002480 }
2481 }
2482
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002483 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002484 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2485 String callingFeatureId) {
2486 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2487 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002488 }
2489
2490 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002491 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2492 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002493 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002494 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002495 }
2496
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002497 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2498 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002499 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002500 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002501
2502 LocationAccessPolicy.LocationPermissionResult locationResult =
2503 LocationAccessPolicy.checkLocationPermission(mApp,
2504 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2505 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002507 .setCallingPid(Binder.getCallingPid())
2508 .setCallingUid(Binder.getCallingUid())
2509 .setMethod("requestCellInfoUpdate")
2510 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2511 .build());
2512 switch (locationResult) {
2513 case DENIED_HARD:
2514 throw new SecurityException("Not allowed to access cell info");
2515 case DENIED_SOFT:
Nathan Harold5320c422019-05-09 10:26:08 -07002516 try {
2517 cb.onCellInfo(new ArrayList<CellInfo>());
2518 } catch (RemoteException re) {
2519 // Drop without consequences
2520 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002521 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002522 }
2523
Nathan Harolda939a962019-05-09 10:13:47 -07002524
2525 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002526 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2527
2528 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2529 }
2530
2531 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002532 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002533 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002534 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002535
2536 final long identity = Binder.clearCallingIdentity();
2537 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002538 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002539 } finally {
2540 Binder.restoreCallingIdentity(identity);
2541 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002542 }
2543
Shishir Agrawala9f32182016-04-12 12:00:16 -07002544 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002545 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002546 Phone phone = PhoneFactory.getPhone(slotIndex);
2547 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002548 return null;
2549 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002550 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002551 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002552 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002553 return null;
2554 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002555
2556 final long identity = Binder.clearCallingIdentity();
2557 try {
2558 return phone.getImei();
2559 } finally {
2560 Binder.restoreCallingIdentity(identity);
2561 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002562 }
2563
2564 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002565 public String getTypeAllocationCodeForSlot(int slotIndex) {
2566 Phone phone = PhoneFactory.getPhone(slotIndex);
2567 String tac = null;
2568 if (phone != null) {
2569 String imei = phone.getImei();
2570 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2571 }
2572 return tac;
2573 }
2574
2575 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002577 Phone phone = PhoneFactory.getPhone(slotIndex);
2578 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002579 return null;
2580 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002581
Jeff Davidson913390f2018-02-23 17:11:49 -08002582 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002583 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002584 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002585 return null;
2586 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002587
2588 final long identity = Binder.clearCallingIdentity();
2589 try {
2590 return phone.getMeid();
2591 } finally {
2592 Binder.restoreCallingIdentity(identity);
2593 }
Jack Yu2af8d712017-03-15 17:14:14 -07002594 }
2595
2596 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002597 public String getManufacturerCodeForSlot(int slotIndex) {
2598 Phone phone = PhoneFactory.getPhone(slotIndex);
2599 String manufacturerCode = null;
2600 if (phone != null) {
2601 String meid = phone.getMeid();
2602 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2603 }
2604 return manufacturerCode;
2605 }
2606
2607 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002608 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2609 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002610 Phone phone = PhoneFactory.getPhone(slotIndex);
2611 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002612 return null;
2613 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002614 int subId = phone.getSubId();
2615 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002616 mApp, subId, callingPackage, callingFeatureId,
2617 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002618 return null;
2619 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002620
2621 final long identity = Binder.clearCallingIdentity();
2622 try {
2623 return phone.getDeviceSvn();
2624 } finally {
2625 Binder.restoreCallingIdentity(identity);
2626 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002627 }
2628
fionaxu43304da2017-11-27 22:51:16 -08002629 @Override
2630 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002631 final long identity = Binder.clearCallingIdentity();
2632 try {
2633 final Phone phone = getPhone(subId);
2634 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2635 } finally {
2636 Binder.restoreCallingIdentity(identity);
2637 }
fionaxu43304da2017-11-27 22:51:16 -08002638 }
2639
2640 @Override
2641 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002642 final long identity = Binder.clearCallingIdentity();
2643 try {
2644 final Phone phone = getPhone(subId);
2645 return phone == null ? null : phone.getCarrierName();
2646 } finally {
2647 Binder.restoreCallingIdentity(identity);
2648 }
fionaxu43304da2017-11-27 22:51:16 -08002649 }
2650
calvinpanffe225e2018-11-01 19:43:06 +08002651 @Override
chen xu0026ca62019-03-06 15:28:50 -08002652 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002653 final long identity = Binder.clearCallingIdentity();
2654 try {
2655 final Phone phone = getPhone(subId);
2656 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002657 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
2661 }
2662
2663 @Override
chen xu0026ca62019-03-06 15:28:50 -08002664 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002668 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002669 } finally {
2670 Binder.restoreCallingIdentity(identity);
2671 }
2672 }
2673
chen xu651eec72018-11-11 19:03:44 -08002674 @Override
chen xu864e11c2018-12-06 22:10:03 -08002675 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2676 if (!isSubscriptionMccMnc) {
2677 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2678 }
chen xu651eec72018-11-11 19:03:44 -08002679 final Phone phone = PhoneFactory.getPhone(slotIndex);
2680 if (phone == null) {
2681 return TelephonyManager.UNKNOWN_CARRIER_ID;
2682 }
2683 final long identity = Binder.clearCallingIdentity();
2684 try {
2685 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2686 } finally {
2687 Binder.restoreCallingIdentity(identity);
2688 }
2689 }
2690
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002691 //
2692 // Internal helper methods.
2693 //
2694
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002695 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002696 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2697 *
2698 * @throws SecurityException if the caller does not have the required permission
2699 */
2700 private void enforceModifyPermission() {
2701 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2702 }
2703
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002704 /**
2705 * Make sure the caller is system.
2706 *
2707 * @throws SecurityException if the caller is not system.
2708 */
2709 private void enforceSystemCaller() {
2710 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2711 throw new SecurityException("Caller must be system");
2712 }
2713 }
2714
Shuo Qianf2b2df42019-11-13 17:43:31 -08002715 private void enforceActiveEmergencySessionPermission() {
2716 mApp.enforceCallingOrSelfPermission(
2717 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2718 }
2719
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 /**
2721 * Make sure the caller has the CALL_PHONE permission.
2722 *
2723 * @throws SecurityException if the caller does not have the required permission
2724 */
2725 private void enforceCallPermission() {
2726 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2727 }
2728
paulhu423b5f22019-08-23 19:17:33 +08002729 private void enforceSettingsPermission() {
2730 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002731 }
2732
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002733 private String createTelUrl(String number) {
2734 if (TextUtils.isEmpty(number)) {
2735 return null;
2736 }
2737
Jake Hambye994d462014-02-03 13:10:13 -08002738 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 }
2740
Ihab Awadf9e92732013-12-05 18:02:52 -08002741 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002742 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2743 }
2744
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002745 private static void logv(String msg) {
2746 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2747 }
2748
Ihab Awadf9e92732013-12-05 18:02:52 -08002749 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002750 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2751 }
2752
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002753 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002755 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002756 }
2757
Sanket Padawe356d7632015-06-22 14:03:32 -07002758 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002759 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002760 final long identity = Binder.clearCallingIdentity();
2761 try {
2762 final Phone phone = PhoneFactory.getPhone(slotIndex);
2763 if (phone == null) {
2764 return PhoneConstants.PHONE_TYPE_NONE;
2765 } else {
2766 return phone.getPhoneType();
2767 }
2768 } finally {
2769 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002771 }
2772
2773 /**
2774 * Returns the CDMA ERI icon index to display
2775 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002776 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002777 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2778 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2779 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002780 }
2781
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002783 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2784 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002786 mApp, subId, callingPackage, callingFeatureId,
2787 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002788 return -1;
2789 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002790
2791 final long identity = Binder.clearCallingIdentity();
2792 try {
2793 final Phone phone = getPhone(subId);
2794 if (phone != null) {
2795 return phone.getCdmaEriIconIndex();
2796 } else {
2797 return -1;
2798 }
2799 } finally {
2800 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002801 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002802 }
2803
2804 /**
2805 * Returns the CDMA ERI icon mode,
2806 * 0 - ON
2807 * 1 - FLASHING
2808 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002809 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002810 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2811 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2812 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002813 }
2814
Sanket Padawe356d7632015-06-22 14:03:32 -07002815 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002816 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2817 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002818 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002819 mApp, subId, callingPackage, callingFeatureId,
2820 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002821 return -1;
2822 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002823
2824 final long identity = Binder.clearCallingIdentity();
2825 try {
2826 final Phone phone = getPhone(subId);
2827 if (phone != null) {
2828 return phone.getCdmaEriIconMode();
2829 } else {
2830 return -1;
2831 }
2832 } finally {
2833 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002834 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002835 }
2836
2837 /**
2838 * Returns the CDMA ERI text,
2839 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002840 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002841 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2842 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2843 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002844 }
2845
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002847 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2848 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002850 mApp, subId, callingPackage, callingFeatureId,
2851 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 return null;
2853 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002854
2855 final long identity = Binder.clearCallingIdentity();
2856 try {
2857 final Phone phone = getPhone(subId);
2858 if (phone != null) {
2859 return phone.getCdmaEriText();
2860 } else {
2861 return null;
2862 }
2863 } finally {
2864 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002865 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002866 }
2867
2868 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002869 * Returns the CDMA MDN.
2870 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002872 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2874 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002875
2876 final long identity = Binder.clearCallingIdentity();
2877 try {
2878 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002879 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880 return phone.getLine1Number();
2881 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002882 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002883 return null;
2884 }
2885 } finally {
2886 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002887 }
2888 }
2889
2890 /**
2891 * Returns the CDMA MIN.
2892 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002893 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002894 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002895 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2896 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002897
2898 final long identity = Binder.clearCallingIdentity();
2899 try {
2900 final Phone phone = getPhone(subId);
2901 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2902 return phone.getCdmaMin();
2903 } else {
2904 return null;
2905 }
2906 } finally {
2907 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002908 }
2909 }
2910
Hall Liud892bec2018-11-30 14:51:45 -08002911 @Override
2912 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2913 INumberVerificationCallback callback, String callingPackage) {
2914 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2915 != PERMISSION_GRANTED) {
2916 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2917 }
2918 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2919
2920 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2921 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2922 throw new SecurityException("Calling package must be configured in the device config");
2923 }
2924
2925 if (range == null) {
2926 throw new NullPointerException("Range must be non-null");
2927 }
2928
2929 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002930 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002931
2932 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2933 }
2934
Junda Liuca05d5d2014-08-14 22:36:34 -07002935 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002936 * Returns true if CDMA provisioning needs to run.
2937 */
2938 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002939 final long identity = Binder.clearCallingIdentity();
2940 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002941 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002942 } finally {
2943 Binder.restoreCallingIdentity(identity);
2944 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002945 }
2946
2947 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002948 * Sets the voice mail number of a given subId.
2949 */
2950 @Override
2951 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002952 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2953 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954
2955 final long identity = Binder.clearCallingIdentity();
2956 try {
2957 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2958 new Pair<String, String>(alphaTag, number), new Integer(subId));
2959 return success;
2960 } finally {
2961 Binder.restoreCallingIdentity(identity);
2962 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002963 }
2964
Ta-wei Yen87c49842016-05-13 21:19:52 -07002965 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002966 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2967 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002968 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2969 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002970 if (!TextUtils.equals(callingPackage, systemDialer)) {
2971 throw new SecurityException("caller must be system dialer");
2972 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002973
2974 final long identity = Binder.clearCallingIdentity();
2975 try {
2976 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2977 if (phoneAccountHandle == null) {
2978 return null;
2979 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002980 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002981 } finally {
2982 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002983 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002984 }
2985
2986 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002987 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2988 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002989 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002990 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002991 mApp, subId, callingPackage, callingFeatureId,
2992 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002993 return null;
2994 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002995
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002996 final long identity = Binder.clearCallingIdentity();
2997 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002998 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07002999 } finally {
3000 Binder.restoreCallingIdentity(identity);
3001 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003002 }
3003
3004 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003005 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3006 VisualVoicemailSmsFilterSettings settings) {
3007 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003008
3009 final long identity = Binder.clearCallingIdentity();
3010 try {
3011 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003012 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003013 } finally {
3014 Binder.restoreCallingIdentity(identity);
3015 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003016 }
3017
3018 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003019 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3020 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
3022 final long identity = Binder.clearCallingIdentity();
3023 try {
3024 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003025 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003026 } finally {
3027 Binder.restoreCallingIdentity(identity);
3028 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003029 }
3030
3031 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003032 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3033 String callingPackage, int subId) {
3034 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003035
3036 final long identity = Binder.clearCallingIdentity();
3037 try {
3038 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003039 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003040 } finally {
3041 Binder.restoreCallingIdentity(identity);
3042 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003043 }
3044
3045 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003046 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003047 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003048
3049 final long identity = Binder.clearCallingIdentity();
3050 try {
3051 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003052 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003053 } finally {
3054 Binder.restoreCallingIdentity(identity);
3055 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003056 }
3057
3058 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003059 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3060 String callingAttributionTag, int subId, String number, int port, String text,
3061 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003062 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003063 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003064 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003065 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003066 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3067 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003068 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003069
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003070 /**
fionaxu0152e512016-11-14 13:36:14 -08003071 * Sets the voice activation state of a given subId.
3072 */
3073 @Override
3074 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003075 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3076 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077
3078 final long identity = Binder.clearCallingIdentity();
3079 try {
3080 final Phone phone = getPhone(subId);
3081 if (phone != null) {
3082 phone.setVoiceActivationState(activationState);
3083 } else {
3084 loge("setVoiceActivationState fails with invalid subId: " + subId);
3085 }
3086 } finally {
3087 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003088 }
3089 }
3090
3091 /**
3092 * Sets the data activation state of a given subId.
3093 */
3094 @Override
3095 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003096 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3097 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003098
3099 final long identity = Binder.clearCallingIdentity();
3100 try {
3101 final Phone phone = getPhone(subId);
3102 if (phone != null) {
3103 phone.setDataActivationState(activationState);
3104 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003105 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003106 }
3107 } finally {
3108 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003109 }
3110 }
3111
3112 /**
3113 * Returns the voice activation state of a given subId.
3114 */
3115 @Override
3116 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003117 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118
fionaxu0152e512016-11-14 13:36:14 -08003119 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003120 final long identity = Binder.clearCallingIdentity();
3121 try {
3122 if (phone != null) {
3123 return phone.getVoiceActivationState();
3124 } else {
3125 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3126 }
3127 } finally {
3128 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003129 }
3130 }
3131
3132 /**
3133 * Returns the data activation state of a given subId.
3134 */
3135 @Override
3136 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003137 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003138
fionaxu0152e512016-11-14 13:36:14 -08003139 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003140 final long identity = Binder.clearCallingIdentity();
3141 try {
3142 if (phone != null) {
3143 return phone.getDataActivationState();
3144 } else {
3145 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3146 }
3147 } finally {
3148 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003149 }
3150 }
3151
3152 /**
Wink Saville36469e72014-06-11 15:17:00 -07003153 * Returns the unread count of voicemails for a subId
3154 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003155 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003156 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3157 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003158 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003159 mApp, subId, callingPackage, callingFeatureId,
3160 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003161 return 0;
3162 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003163 final long identity = Binder.clearCallingIdentity();
3164 try {
3165 final Phone phone = getPhone(subId);
3166 if (phone != null) {
3167 return phone.getVoiceMessageCount();
3168 } else {
3169 return 0;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003173 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003174 }
3175
3176 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003177 * returns true, if the device is in a state where both voice and data
3178 * are supported simultaneously. This can change based on location or network condition.
3179 */
3180 @Override
3181 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003182 final long identity = Binder.clearCallingIdentity();
3183 try {
3184 final Phone phone = getPhone(subId);
3185 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3186 } finally {
3187 Binder.restoreCallingIdentity(identity);
3188 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003189 }
3190
3191 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003192 * Send the dialer code if called from the current default dialer or the caller has
3193 * carrier privilege.
3194 * @param inputCode The dialer code to send
3195 */
3196 @Override
3197 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003198 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003199 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003200 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3201 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003202 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003203 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003204 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003205 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206
3207 final long identity = Binder.clearCallingIdentity();
3208 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003209 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
fionaxu235cc5e2017-03-06 22:25:57 -08003213 }
3214
Pengquan Menga1bb6272018-09-06 09:59:22 -07003215 @Override
3216 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003217 TelephonyPermissions
3218 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3219 mApp, subId, "getNetworkSelectionMode");
3220 final long identity = Binder.clearCallingIdentity();
3221 try {
3222 if (!isActiveSubscription(subId)) {
3223 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3224 }
3225 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3226 } finally {
3227 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003228 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003229 }
3230
Brad Ebinger35c841c2018-10-01 10:40:55 -07003231 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003232 public boolean isInEmergencySmsMode() {
3233 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3234 final long identity = Binder.clearCallingIdentity();
3235 try {
3236 for (Phone phone : PhoneFactory.getPhones()) {
3237 if (phone.isInEmergencySmsMode()) {
3238 return true;
3239 }
3240 }
3241 } finally {
3242 Binder.restoreCallingIdentity(identity);
3243 }
3244 return false;
3245 }
3246
shilu366312e2019-12-17 09:28:10 -08003247 /**
3248 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3249 * @param subId The subscription to use to check the configuration.
3250 * @param c The callback that will be used to send the result.
3251 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003252 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003253 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3254 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003255 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3256 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003257
Brad Ebinger77b832e2019-10-17 17:03:22 -07003258 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3259 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3260 "IMS not available on device.");
3261 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003262 final long token = Binder.clearCallingIdentity();
3263 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003264 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003265 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003266 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003267 } catch (ImsException e) {
3268 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003269 } finally {
3270 Binder.restoreCallingIdentity(token);
3271 }
3272 }
3273
shilu366312e2019-12-17 09:28:10 -08003274 /**
3275 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3276 * @param subId The subscription to use to check the configuration.
3277 * @param c The callback that will be used to send the result.
3278 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003279 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003280 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003281 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3282 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003283 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3284 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3285 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003286 final long token = Binder.clearCallingIdentity();
3287 try {
3288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3289 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3290 .removeRegistrationCallbackForSubscription(c, subId);
3291 } catch (ImsException e) {
3292 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3293 + "is inactive, ignoring unregister.");
3294 // If the subscription is no longer active, just return, since the callback
3295 // will already have been removed internally.
3296 } finally {
3297 Binder.restoreCallingIdentity(token);
3298 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003299 }
3300
Brad Ebinger774ba362019-10-22 17:36:18 -07003301 /**
3302 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3303 */
3304 @Override
3305 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3306 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3307 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3308 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3309 "IMS not available on device.");
3310 }
3311 final long token = Binder.clearCallingIdentity();
3312 try {
3313 Phone phone = getPhone(subId);
3314 if (phone == null) {
3315 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3316 + subId + "'");
3317 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3318 }
3319 phone.getImsRegistrationState(regState -> {
3320 try {
3321 consumer.accept((regState == null)
3322 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3323 } catch (RemoteException e) {
3324 // Ignore if the remote process is no longer available to call back.
3325 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3326 }
3327 });
3328 } finally {
3329 Binder.restoreCallingIdentity(token);
3330 }
3331 }
3332
3333 /**
3334 * Get the transport type for the IMS service registration state.
3335 */
3336 @Override
3337 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003338 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3339 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003340 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3341 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3342 "IMS not available on device.");
3343 }
3344 final long token = Binder.clearCallingIdentity();
3345 try {
3346 Phone phone = getPhone(subId);
3347 if (phone == null) {
3348 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3349 + subId + "'");
3350 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3351 }
3352 phone.getImsRegistrationTech(regTech -> {
3353 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3354 int regTechConverted = (regTech == null)
3355 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3356 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3357 regTechConverted);
3358 try {
3359 consumer.accept(regTechConverted);
3360 } catch (RemoteException e) {
3361 // Ignore if the remote process is no longer available to call back.
3362 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3363 }
3364 });
3365 } finally {
3366 Binder.restoreCallingIdentity(token);
3367 }
3368 }
3369
shilu366312e2019-12-17 09:28:10 -08003370 /**
3371 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3372 * @param subId The subscription to use to check the configuration.
3373 * @param c The callback that will be used to send the result.
3374 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003375 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003376 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3377 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003378 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3379 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003380 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3381 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3382 "IMS not available on device.");
3383 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003384 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3385 final long token = Binder.clearCallingIdentity();
3386 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003387 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003388 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003389 } catch (ImsException e) {
3390 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003391 } finally {
3392 Binder.restoreCallingIdentity(token);
3393 }
3394 }
3395
shilu366312e2019-12-17 09:28:10 -08003396 /**
3397 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3398 * @param subId The subscription to use to check the configuration.
3399 * @param c The callback that will be used to send the result.
3400 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003402 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003403 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3404 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003405 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3406 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3407 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003408
3409 final long token = Binder.clearCallingIdentity();
3410 try {
3411 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3412 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003413 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003414 } catch (ImsException e) {
3415 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3416 + "is inactive, ignoring unregister.");
3417 // If the subscription is no longer active, just return, since the callback
3418 // will already have been removed internally.
3419 } finally {
3420 Binder.restoreCallingIdentity(token);
3421 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003422 }
3423
3424 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003425 public boolean isCapable(int subId, int capability, int regTech) {
3426 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3428 final long token = Binder.clearCallingIdentity();
3429 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003430 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003431 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003432 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3434 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003435 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003436 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3437 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003438 } finally {
3439 Binder.restoreCallingIdentity(token);
3440 }
3441 }
3442
3443 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003444 public boolean isAvailable(int subId, int capability, int regTech) {
3445 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 final long token = Binder.clearCallingIdentity();
3447 try {
3448 Phone phone = getPhone(subId);
3449 if (phone == null) return false;
3450 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003451 } catch (com.android.ims.ImsException e) {
3452 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3453 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003454 } finally {
3455 Binder.restoreCallingIdentity(token);
3456 }
3457 }
3458
Brad Ebinger77b832e2019-10-17 17:03:22 -07003459 /**
3460 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3461 * subscription.
3462 * @param subId The subscription to use to check the configuration.
3463 * @param callback The callback that will be used to send the result.
3464 * @param capability The MmTelFeature capability that will be used to send the result.
3465 * @param transportType The transport type of the MmTelFeature capability.
3466 */
3467 @Override
3468 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3469 int transportType) {
3470 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3471 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3472 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3473 "IMS not available on device.");
3474 }
3475 final long token = Binder.clearCallingIdentity();
3476 try {
3477 int slotId = getSlotIndex(subId);
3478 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3479 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3480 + subId + "'");
3481 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3482 }
3483 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3484 transportType, aBoolean -> {
3485 try {
3486 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3487 } catch (RemoteException e) {
3488 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3489 + "running. Ignore");
3490 }
3491 });
3492 } finally {
3493 Binder.restoreCallingIdentity(token);
3494 }
3495 }
3496
shilu366312e2019-12-17 09:28:10 -08003497 /**
3498 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3499 * @param subId The subscription to use to check the configuration.
3500 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003501 @Override
3502 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003503 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3504 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003505
Brad Ebinger35c841c2018-10-01 10:40:55 -07003506 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3507 final long token = Binder.clearCallingIdentity();
3508 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003509 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003510 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003511 } catch (ImsException e) {
3512 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 } finally {
3514 Binder.restoreCallingIdentity(token);
3515 }
3516 }
3517
3518 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003519 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003520 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003521 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 final long identity = Binder.clearCallingIdentity();
3523 try {
3524 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003525 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003527 } catch (ImsException e) {
3528 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003529 } finally {
3530 Binder.restoreCallingIdentity(identity);
3531 }
3532 }
3533
shilu366312e2019-12-17 09:28:10 -08003534 /**
3535 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3536 * @param subId The subscription to use to check the configuration.
3537 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003539 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003540 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3541 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003542 final long identity = Binder.clearCallingIdentity();
3543 try {
3544 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003545 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3546 } catch (ImsException e) {
3547 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 } finally {
3549 Binder.restoreCallingIdentity(identity);
3550 }
3551 }
3552
3553 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003554 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003556 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003557 final long identity = Binder.clearCallingIdentity();
3558 try {
3559 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003560 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003561 } catch (ImsException e) {
3562 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 } finally {
3564 Binder.restoreCallingIdentity(identity);
3565 }
3566 }
3567
shilu366312e2019-12-17 09:28:10 -08003568 /**
3569 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3570 * @param subId The subscription to use to check the configuration.
3571 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 @Override
3573 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003574 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3575 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003576 final long identity = Binder.clearCallingIdentity();
3577 try {
3578 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003579 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003580 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003581 } catch (ImsException e) {
3582 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 } finally {
3584 Binder.restoreCallingIdentity(identity);
3585 }
3586 }
3587
3588 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003589 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003591 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 final long identity = Binder.clearCallingIdentity();
3593 try {
3594 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003595 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003596 } catch (ImsException e) {
3597 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 } finally {
3599 Binder.restoreCallingIdentity(identity);
3600 }
3601 }
3602
shilu366312e2019-12-17 09:28:10 -08003603 /**
3604 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3605 * @param subId The subscription to use to check the configuration.
3606 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 @Override
3608 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003609 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3610 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003611 final long identity = Binder.clearCallingIdentity();
3612 try {
3613 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003614 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003615 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003616 } catch (ImsException e) {
3617 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 } finally {
3619 Binder.restoreCallingIdentity(identity);
3620 }
3621 }
3622
3623 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003624 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003625 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003626 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 final long identity = Binder.clearCallingIdentity();
3628 try {
3629 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003630 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003632 } catch (ImsException e) {
3633 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003634 } finally {
3635 Binder.restoreCallingIdentity(identity);
3636 }
3637 }
3638
3639 @Override
3640 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3641 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3642 "setVoWiFiNonPersistent");
3643 final long identity = Binder.clearCallingIdentity();
3644 try {
3645 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003646 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003647 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003648 } catch (ImsException e) {
3649 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003650 } finally {
3651 Binder.restoreCallingIdentity(identity);
3652 }
3653 }
3654
shilu366312e2019-12-17 09:28:10 -08003655 /**
3656 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3657 * @param subId The subscription to use to check the configuration.
3658 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003659 @Override
3660 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003661 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3662 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003663 final long identity = Binder.clearCallingIdentity();
3664 try {
3665 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003666 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003667 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003668 } catch (ImsException e) {
3669 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003670 } finally {
3671 Binder.restoreCallingIdentity(identity);
3672 }
3673 }
3674
3675 @Override
3676 public void setVoWiFiModeSetting(int subId, int mode) {
3677 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3678 "setVoWiFiModeSetting");
3679 final long identity = Binder.clearCallingIdentity();
3680 try {
3681 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003682 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003684 } catch (ImsException e) {
3685 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003686 } finally {
3687 Binder.restoreCallingIdentity(identity);
3688 }
3689 }
3690
3691 @Override
3692 public int getVoWiFiRoamingModeSetting(int subId) {
3693 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3694 final long identity = Binder.clearCallingIdentity();
3695 try {
3696 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003697 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003699 } catch (ImsException e) {
3700 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003701 } finally {
3702 Binder.restoreCallingIdentity(identity);
3703 }
3704 }
3705
3706 @Override
3707 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3708 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3709 "setVoWiFiRoamingModeSetting");
3710 final long identity = Binder.clearCallingIdentity();
3711 try {
3712 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003713 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003714 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003715 } catch (ImsException e) {
3716 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003717 } finally {
3718 Binder.restoreCallingIdentity(identity);
3719 }
3720 }
3721
3722 @Override
3723 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3724 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3725 "setRttCapabilityEnabled");
3726 final long identity = Binder.clearCallingIdentity();
3727 try {
3728 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003729 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3730 } catch (ImsException e) {
3731 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003732 } finally {
3733 Binder.restoreCallingIdentity(identity);
3734 }
3735 }
3736
shilu366312e2019-12-17 09:28:10 -08003737 /**
3738 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3739 * @param subId The subscription to use to check the configuration.
3740 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 @Override
3742 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003743 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3744 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003745 final long identity = Binder.clearCallingIdentity();
3746 try {
3747 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003748 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003749 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003750 } catch (ImsException e) {
3751 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003752 } finally {
3753 Binder.restoreCallingIdentity(identity);
3754 }
3755 }
3756
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003757 @Override
3758 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3759 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3760 final long identity = Binder.clearCallingIdentity();
3761 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003762 if (!isImsAvailableOnDevice()) {
3763 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3764 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003765 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003766 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003767 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003768 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003769 } catch (ImsException e) {
3770 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003771 } finally {
3772 Binder.restoreCallingIdentity(identity);
3773 }
3774 }
3775
3776 @Override
3777 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3778 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3779 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003780 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3781 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3782 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003783 try {
3784 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003785 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003786 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003787 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003788 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3789 + "is inactive, ignoring unregister.");
3790 // If the subscription is no longer active, just return, since the callback will already
3791 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003792 } finally {
3793 Binder.restoreCallingIdentity(identity);
3794 }
3795 }
3796
allenwtsu99c623b2020-01-03 18:24:23 +08003797
3798 private void checkModifyPhoneStatePermission(int subId, String message) {
3799 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3800 message);
3801 }
3802
3803 private boolean isImsProvisioningRequired(int subId, int capability,
3804 boolean isMmtelCapability) {
3805 Phone phone = getPhone(subId);
3806 if (phone == null) {
3807 loge("phone instance null for subid " + subId);
3808 return false;
3809 }
3810 if (isMmtelCapability) {
3811 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3812 return false;
3813 }
3814 } else {
3815 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3816 return false;
3817 }
3818 }
3819 return true;
3820 }
3821
3822 @Override
3823 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3824 boolean isProvisioned) {
3825 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3826
3827 final long identity = Binder.clearCallingIdentity();
3828 try {
3829 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3830 if (!isImsProvisioningRequired(subId, capability, false)) {
3831 return;
3832 }
3833
3834 // this capability requires provisioning, route to the correct API.
3835 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3836 switch (capability) {
3837 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3838 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3839 ims.setEabProvisioned(isProvisioned);
3840 break;
3841 default: {
3842 throw new IllegalArgumentException("Tried to set provisioning for "
3843 + "rcs capability '" + capability + "', which does not require "
3844 + "provisioning.");
3845 }
3846 }
3847 } finally {
3848 Binder.restoreCallingIdentity(identity);
3849 }
3850
3851 }
3852
3853
3854 @Override
3855 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3856 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3857 final long identity = Binder.clearCallingIdentity();
3858 try {
3859 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3860 if (!isImsProvisioningRequired(subId, capability, false)) {
3861 return true;
3862 }
3863
3864 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3865 switch (capability) {
3866 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3867 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3868 return ims.isEabProvisionedOnDevice();
3869
3870 default: {
3871 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3872 + "capability '" + capability + "', which does not require "
3873 + "provisioning.");
3874 }
3875 }
3876
3877 } finally {
3878 Binder.restoreCallingIdentity(identity);
3879 }
3880 }
3881
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003882 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003883 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3884 boolean isProvisioned) {
3885 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3886 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3887 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3888 }
allenwtsu99c623b2020-01-03 18:24:23 +08003889 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003890 final long identity = Binder.clearCallingIdentity();
3891 try {
3892 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003893 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003894 return;
3895 }
3896
3897 // this capability requires provisioning, route to the correct API.
3898 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3899 switch (capability) {
3900 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3901 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3902 ims.setVolteProvisioned(isProvisioned);
3903 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3904 ims.setWfcProvisioned(isProvisioned);
3905 }
3906 break;
3907 }
3908 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3909 // There is currently no difference in VT provisioning type.
3910 ims.setVtProvisioned(isProvisioned);
3911 break;
3912 }
3913 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3914 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3915 // change the capability of the feature instead if needed.
3916 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3917 == isProvisioned) {
3918 // No change in provisioning.
3919 return;
3920 }
3921 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3922 try {
3923 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003924 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003925 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3926 + ", Exception" + e.getMessage());
3927 }
3928 break;
3929 }
3930 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003931 throw new IllegalArgumentException("Tried to set provisioning for "
3932 + "MmTel capability '" + capability + "', which does not require "
3933 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003934 }
3935 }
3936
3937 } finally {
3938 Binder.restoreCallingIdentity(identity);
3939 }
3940 }
3941
3942 @Override
3943 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3944 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3945 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3946 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3947 }
3948 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3949 final long identity = Binder.clearCallingIdentity();
3950 try {
3951 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003952 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003953 return true;
3954 }
3955
3956 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3957 switch (capability) {
3958 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3959 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3960 return ims.isVolteProvisionedOnDevice();
3961 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3962 return ims.isWfcProvisionedOnDevice();
3963 }
3964 // This should never happen, since we are checking tech above to make sure it
3965 // is either LTE or IWLAN.
3966 throw new IllegalArgumentException("Invalid radio technology for voice "
3967 + "capability.");
3968 }
3969 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3970 // There is currently no difference in VT provisioning type.
3971 return ims.isVtProvisionedOnDevice();
3972 }
3973 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3974 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3975 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3976 }
3977 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003978 throw new IllegalArgumentException(
3979 "Tried to get provisioning for MmTel capability '" + capability
3980 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003981 }
3982 }
3983
3984 } finally {
3985 Binder.restoreCallingIdentity(identity);
3986 }
3987 }
3988
3989 @Override
3990 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3991 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3992 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3993 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3994 }
3995 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
3996 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
3997 return (provisionedBits & capability) > 0;
3998 }
3999
4000 @Override
4001 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4002 boolean isProvisioned) {
4003 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4004 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4005 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4006 }
4007 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4008 "setProvisioningStatusForCapability");
4009 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4010 // If the current provisioning status for capability already matches isProvisioned,
4011 // do nothing.
4012 if (((provisionedBits & capability) > 0) == isProvisioned) {
4013 return;
4014 }
4015 if (isProvisioned) {
4016 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4017 } else {
4018 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4019 }
4020 }
4021
4022 /**
4023 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4024 * technology. The bitfield should mirror the bitfield defined by
4025 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4026 */
4027 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4028 String key = getMmTelProvisioningKey(subId, tech);
4029 // Default is no capabilities are provisioned.
4030 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4031 }
4032
4033 /**
4034 * Sets the MmTel capability provisioning bitfield (defined by
4035 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4036 * technology specified.
4037 *
4038 * Note: This is a synchronous command and should not be called on UI thread.
4039 */
4040 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4041 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4042 String key = getMmTelProvisioningKey(subId, tech);
4043 editor.putInt(key, newField);
4044 editor.commit();
4045 }
4046
4047 private static String getMmTelProvisioningKey(int subId, int tech) {
4048 // resulting key is provision_ims_mmtel_{subId}_{tech}
4049 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4050 }
4051
4052 /**
4053 * Query CarrierConfig to see if the specified capability requires provisioning for the
4054 * carrier associated with the subscription id.
4055 */
4056 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4057 int capability) {
4058 CarrierConfigManager configManager = new CarrierConfigManager(context);
4059 PersistableBundle c = configManager.getConfigForSubId(subId);
4060 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004061 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004062 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4063 false);
4064 boolean requireVoiceVtProvisioning = c.getBoolean(
4065 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4066
4067 // First check to make sure that the capability requires provisioning.
4068 switch (capability) {
4069 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4070 // intentional fallthrough
4071 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4072 if (requireVoiceVtProvisioning) {
4073 // Voice and Video requires provisioning
4074 return true;
4075 }
4076 break;
4077 }
4078 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4079 if (requireUtProvisioning) {
4080 // UT requires provisioning
4081 return true;
4082 }
4083 break;
4084 }
4085 }
4086 return false;
4087 }
4088
allenwtsu99c623b2020-01-03 18:24:23 +08004089 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4090 int capability) {
4091 CarrierConfigManager configManager = new CarrierConfigManager(context);
4092 PersistableBundle c = configManager.getConfigForSubId(subId);
4093
4094 boolean requireRcsProvisioning = c.getBoolean(
4095 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4096
4097 // First check to make sure that the capability requires provisioning.
4098 switch (capability) {
4099 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4100 // intentional fallthrough
4101 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4102 if (requireRcsProvisioning) {
4103 // OPTION or PRESENCE requires provisioning
4104 return true;
4105 }
4106 break;
4107 }
4108 }
4109 return false;
4110 }
4111
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004112 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004113 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004114 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4115 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4116 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004117 enforceReadPrivilegedPermission("getImsProvisioningInt");
4118 final long identity = Binder.clearCallingIdentity();
4119 try {
4120 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004121 int slotId = getSlotIndex(subId);
4122 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4123 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4124 + subId + "' for key:" + key);
4125 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4126 }
4127 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004128 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004129 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4130 + subId + "' for key:" + key);
4131 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004132 } finally {
4133 Binder.restoreCallingIdentity(identity);
4134 }
4135 }
4136
4137 @Override
4138 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004139 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4140 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4141 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004142 enforceReadPrivilegedPermission("getImsProvisioningString");
4143 final long identity = Binder.clearCallingIdentity();
4144 try {
4145 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004146 int slotId = getSlotIndex(subId);
4147 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4148 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4149 + subId + "' for key:" + key);
4150 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4151 }
4152 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004153 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004154 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4155 + subId + "' for key:" + key);
4156 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004157 } finally {
4158 Binder.restoreCallingIdentity(identity);
4159 }
4160 }
4161
4162 @Override
4163 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004164 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4165 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4166 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004167 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4168 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 int slotId = getSlotIndex(subId);
4173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4174 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4175 + subId + "' for key:" + key);
4176 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4177 }
4178 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4181 + "' for key:" + key);
4182 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
4188 @Override
4189 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4191 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4192 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4194 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 int slotId = getSlotIndex(subId);
4199 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4200 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4201 + subId + "' for key:" + key);
4202 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4203 }
4204 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004206 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4207 + "' for key:" + key);
4208 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004214 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004215 int slotId = SubscriptionManager.getSlotIndex(subId);
4216 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4218 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004219 }
4220 return slotId;
4221 }
4222
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004223 private int getSlotIndex(int subId) {
4224 int slotId = SubscriptionManager.getSlotIndex(subId);
4225 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4226 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4227 }
4228 return slotId;
4229 }
4230
Wink Saville36469e72014-06-11 15:17:00 -07004231 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004232 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004233 */
4234 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004235 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4236 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004237 final int targetSdk = getTargetSdk(callingPackage);
4238 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004239 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004240 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004241 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004242 mApp, subId, callingPackage, callingFeatureId,
4243 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004244 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4245 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004246
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004247 final long identity = Binder.clearCallingIdentity();
4248 try {
4249 final Phone phone = getPhone(subId);
4250 if (phone != null) {
4251 return phone.getServiceState().getDataNetworkType();
4252 } else {
4253 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4254 }
4255 } finally {
4256 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004257 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004258 }
4259
4260 /**
4261 * Returns the data network type
4262 */
4263 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004264 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4265 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4266 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004267 }
4268
4269 /**
4270 * Returns the data network type for a subId
4271 */
4272 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004273 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4274 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004275 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004276 mApp, subId, callingPackage, callingFeatureId,
4277 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004278 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4279 }
4280
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004281 final long identity = Binder.clearCallingIdentity();
4282 try {
4283 final Phone phone = getPhone(subId);
4284 if (phone != null) {
4285 return phone.getServiceState().getDataNetworkType();
4286 } else {
4287 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4288 }
4289 } finally {
4290 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004291 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004292 }
4293
4294 /**
Wink Saville36469e72014-06-11 15:17:00 -07004295 * Returns the Voice network type for a subId
4296 */
4297 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004298 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4299 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004300 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004301 mApp, subId, callingPackage, callingFeatureId,
4302 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004303 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4304 }
4305
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004306 final long identity = Binder.clearCallingIdentity();
4307 try {
4308 final Phone phone = getPhone(subId);
4309 if (phone != null) {
4310 return phone.getServiceState().getVoiceNetworkType();
4311 } else {
4312 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4313 }
4314 } finally {
4315 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004316 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004317 }
4318
4319 /**
4320 * @return true if a ICC card is present
4321 */
4322 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004323 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004324 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4325 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004326 }
4327
4328 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004329 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004330 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004331 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004332 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004333 final long identity = Binder.clearCallingIdentity();
4334 try {
4335 final Phone phone = PhoneFactory.getPhone(slotIndex);
4336 if (phone != null) {
4337 return phone.getIccCard().hasIccCard();
4338 } else {
4339 return false;
4340 }
4341 } finally {
4342 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004343 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004344 }
4345
4346 /**
4347 * Return if the current radio is LTE on CDMA. This
4348 * is a tri-state return value as for a period of time
4349 * the mode may be unknown.
4350 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004351 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004352 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004353 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004354 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004355 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004356 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4357 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4358 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004359 }
4360
Sanket Padawe356d7632015-06-22 14:03:32 -07004361 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004362 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4363 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004364 try {
4365 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4366 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004367 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4368 }
4369
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004370 final long identity = Binder.clearCallingIdentity();
4371 try {
4372 final Phone phone = getPhone(subId);
4373 if (phone == null) {
4374 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4375 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004376 return TelephonyProperties.lte_on_cdma_device()
4377 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004378 }
4379 } finally {
4380 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004381 }
Wink Saville36469e72014-06-11 15:17:00 -07004382 }
4383
Wink Saville36469e72014-06-11 15:17:00 -07004384 /**
4385 * {@hide}
4386 * Returns Default subId, 0 in the case of single standby.
4387 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004388 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004389 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004390 }
4391
Shishir Agrawala9f32182016-04-12 12:00:16 -07004392 private int getSlotForDefaultSubscription() {
4393 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4394 }
4395
Wink Savilleb564aae2014-10-23 10:18:09 -07004396 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004397 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004398 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004399
Pengquan Menge92a50d2018-09-21 15:54:48 -07004400 private boolean isActiveSubscription(int subId) {
4401 return mSubscriptionController.isActiveSubId(subId);
4402 }
4403
Ihab Awadf2177b72013-11-25 13:33:23 -08004404 /**
4405 * @see android.telephony.TelephonyManager.WifiCallingChoices
4406 */
4407 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004408 final long identity = Binder.clearCallingIdentity();
4409 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004410 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004411 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4412 getWhenToMakeWifiCallsDefaultPreference());
4413 } finally {
4414 Binder.restoreCallingIdentity(identity);
4415 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004416 }
4417
4418 /**
4419 * @see android.telephony.TelephonyManager.WifiCallingChoices
4420 */
4421 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 final long identity = Binder.clearCallingIdentity();
4423 try {
4424 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004425 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004426 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4427 } finally {
4428 Binder.restoreCallingIdentity(identity);
4429 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004430 }
4431
Sailesh Nepald1e68152013-12-12 19:08:02 -08004432 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004433 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004434 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004435 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004436
Jordan Liu4c733742019-02-28 12:03:40 -08004437 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4438 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4439 if (phoneId == -1) {
4440 throw new IllegalArgumentException("Given slot index: " + slotIndex
4441 + " does not correspond to an active phone");
4442 }
4443 return PhoneFactory.getPhone(phoneId);
4444 }
4445
Shishir Agrawal566b7612013-10-28 14:41:00 -07004446 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004447 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4448 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4450 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004451 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004452 if (DBG) {
4453 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4454 }
4455 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4456 p2);
4457 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004458
Jordan Liu4c733742019-02-28 12:03:40 -08004459
4460 @Override
4461 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4462 int slotIndex, String callingPackage, String aid, int p2) {
4463 enforceModifyPermission();
4464 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4465 if (DBG) {
4466 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4467 }
4468 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4469 callingPackage, aid, p2);
4470 }
4471
4472 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4473 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004474 final long identity = Binder.clearCallingIdentity();
4475 try {
4476 if (TextUtils.equals(ISDR_AID, aid)) {
4477 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004478 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4479 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004480 if (bestComponent == null
4481 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4482 loge("The calling package is not allowed to access ISD-R.");
4483 throw new SecurityException(
4484 "The calling package is not allowed to access ISD-R.");
4485 }
Derek Tan740e1672017-06-27 14:56:27 -07004486 }
Derek Tan740e1672017-06-27 14:56:27 -07004487
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004488 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004489 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4490 null /* workSource */);
4491 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004492 return response;
4493 } finally {
4494 Binder.restoreCallingIdentity(identity);
4495 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004496 }
4497
4498 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004499 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004500 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4501 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004502 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4503 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004505
Jordan Liu4c733742019-02-28 12:03:40 -08004506 @Override
4507 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4508 enforceModifyPermission();
4509 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4510 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4511 channel);
4512 }
4513
4514 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004515 final long identity = Binder.clearCallingIdentity();
4516 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004517 if (channel < 0) {
4518 return false;
4519 }
Jordan Liu4c733742019-02-28 12:03:40 -08004520 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4521 null /* workSource */);
4522 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004523 return success;
4524 } finally {
4525 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004526 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004527 }
4528
4529 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004530 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004531 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4533 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004534 if (DBG) {
4535 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4536 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4537 + p3 + " data=" + data);
4538 }
4539 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4540 command, p1, p2, p3, data);
4541 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004542
Jordan Liu4c733742019-02-28 12:03:40 -08004543 @Override
4544 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4545 int command, int p1, int p2, int p3, String data) {
4546 enforceModifyPermission();
4547 if (DBG) {
4548 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4549 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4550 + p3 + " data=" + data);
4551 }
4552 return iccTransmitApduLogicalChannelWithPermission(
4553 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4554 data);
4555 }
4556
4557 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4558 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004559 final long identity = Binder.clearCallingIdentity();
4560 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004561 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004562 return "";
4563 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004564
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004565 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004566 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4567 null /* workSource */);
4568 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 // Append the returned status code to the end of the response payload.
4571 String s = Integer.toHexString(
4572 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4573 if (response.payload != null) {
4574 s = IccUtils.bytesToHexString(response.payload) + s;
4575 }
4576 return s;
4577 } finally {
4578 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004579 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004580 }
Jake Hambye994d462014-02-03 13:10:13 -08004581
Evan Charltonc66da362014-05-16 14:06:40 -07004582 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004583 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4584 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004585 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4586 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004587 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004588 if (DBG) {
4589 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4590 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4591 }
4592 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4593 cla, command, p1, p2, p3, data);
4594 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004595
Jordan Liu4c733742019-02-28 12:03:40 -08004596 @Override
4597 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4598 int command, int p1, int p2, int p3, String data) {
4599 enforceModifyPermission();
4600 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4601 if (DBG) {
4602 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4603 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4604 + " data=" + data);
4605 }
4606
4607 return iccTransmitApduBasicChannelWithPermission(
4608 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4609 p2, p3, data);
4610 }
4611
4612 // open APDU basic channel assuming the caller has sufficient permissions
4613 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4614 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004615 final long identity = Binder.clearCallingIdentity();
4616 try {
4617 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4618 && TextUtils.equals(ISDR_AID, data)) {
4619 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004620 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4621 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004622 if (bestComponent == null
4623 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4624 loge("The calling package is not allowed to select ISD-R.");
4625 throw new SecurityException(
4626 "The calling package is not allowed to select ISD-R.");
4627 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004628 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004629
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004630 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004631 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4632 null /* workSource */);
4633 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 // Append the returned status code to the end of the response payload.
4636 String s = Integer.toHexString(
4637 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4638 if (response.payload != null) {
4639 s = IccUtils.bytesToHexString(response.payload) + s;
4640 }
4641 return s;
4642 } finally {
4643 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004644 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004645 }
4646
4647 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004648 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004649 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4651 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004652
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004653 final long identity = Binder.clearCallingIdentity();
4654 try {
4655 if (DBG) {
4656 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4657 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4658 }
4659
4660 IccIoResult response =
4661 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4662 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4663 subId);
4664
4665 if (DBG) {
4666 log("Exchange SIM_IO [R]" + response);
4667 }
4668
4669 byte[] result = null;
4670 int length = 2;
4671 if (response.payload != null) {
4672 length = 2 + response.payload.length;
4673 result = new byte[length];
4674 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4675 } else {
4676 result = new byte[length];
4677 }
4678
4679 result[length - 1] = (byte) response.sw2;
4680 result[length - 2] = (byte) response.sw1;
4681 return result;
4682 } finally {
4683 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004684 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004685 }
4686
Nathan Haroldb3014052017-01-25 15:57:32 -08004687 /**
4688 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4689 * on a particular subscription
4690 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004691 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4692 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004693 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004694 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004695 return null;
4696 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004697
4698 final long identity = Binder.clearCallingIdentity();
4699 try {
4700 if (appType != TelephonyManager.APPTYPE_USIM
4701 && appType != TelephonyManager.APPTYPE_SIM) {
4702 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4703 return null;
4704 }
4705 Object response = sendRequest(
4706 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4707 if (response instanceof String[]) {
4708 return (String[]) response;
4709 }
yincheng zhaod698b842019-09-06 17:06:54 -07004710 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004711 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004712 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004713 } finally {
4714 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004715 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004716 }
4717
yincheng zhaod698b842019-09-06 17:06:54 -07004718 /**
4719 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4720 * subscription.
4721 *
4722 * @param subId the id of the subscription.
4723 * @param appType the uicc app type, must be USIM or SIM.
4724 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4725 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004726 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004727 * @return number of fplmns that is successfully written to the SIM.
4728 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004729 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4730 String callingFeatureId) {
4731 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4732 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004733 if (DBG) logv("no permissions for setForbiddenplmns");
4734 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4735 }
4736 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4737 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4738 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4739 }
4740 if (fplmns == null) {
4741 throw new IllegalArgumentException("Fplmn List provided is null");
4742 }
4743 for (String fplmn : fplmns) {
4744 if (!CellIdentity.isValidPlmn(fplmn)) {
4745 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4746 }
4747 }
4748 final long identity = Binder.clearCallingIdentity();
4749 try {
4750 Object response = sendRequest(
4751 CMD_SET_FORBIDDEN_PLMNS,
4752 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4753 subId);
4754 return (int) response;
4755 } finally {
4756 Binder.restoreCallingIdentity(identity);
4757 }
4758 }
4759
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004760 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004761 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004762 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4763 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004764
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004765 final long identity = Binder.clearCallingIdentity();
4766 try {
4767 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4768 if (response.payload == null) {
4769 return "";
4770 }
Evan Charltonc66da362014-05-16 14:06:40 -07004771
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004772 // Append the returned status code to the end of the response payload.
4773 String s = Integer.toHexString(
4774 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4775 s = IccUtils.bytesToHexString(response.payload) + s;
4776 return s;
4777 } finally {
4778 Binder.restoreCallingIdentity(identity);
4779 }
Evan Charltonc66da362014-05-16 14:06:40 -07004780 }
4781
Jake Hambye994d462014-02-03 13:10:13 -08004782 /**
4783 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4784 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4785 *
4786 * @param itemID the ID of the item to read
4787 * @return the NV item as a String, or null on error.
4788 */
4789 @Override
4790 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004791 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004792 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4793 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004794
4795 final long identity = Binder.clearCallingIdentity();
4796 try {
4797 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004798 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4800 return value;
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Jake Hambye994d462014-02-03 13:10:13 -08004804 }
4805
4806 /**
4807 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4808 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4809 *
4810 * @param itemID the ID of the item to read
4811 * @param itemValue the value to write, as a String
4812 * @return true on success; false on any failure
4813 */
4814 @Override
4815 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004816 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004817 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4818 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004819
4820 final long identity = Binder.clearCallingIdentity();
4821 try {
4822 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4823 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004824 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4826 return success;
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Jake Hambye994d462014-02-03 13:10:13 -08004830 }
4831
4832 /**
4833 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4834 * Used for device configuration by some CDMA operators.
4835 *
4836 * @param preferredRoamingList byte array containing the new PRL
4837 * @return true on success; false on any failure
4838 */
4839 @Override
4840 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843
4844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4847 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4848 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4849 return success;
4850 } finally {
4851 Binder.restoreCallingIdentity(identity);
4852 }
Jake Hambye994d462014-02-03 13:10:13 -08004853 }
4854
4855 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004856 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004857 * Used for device configuration by some CDMA operators.
4858 *
chen xu6dac5ab2018-10-26 17:39:23 -07004859 * @param slotIndex - device slot.
4860 *
Jake Hambye994d462014-02-03 13:10:13 -08004861 * @return true on success; false on any failure
4862 */
4863 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004864 public boolean resetModemConfig(int slotIndex) {
4865 Phone phone = PhoneFactory.getPhone(slotIndex);
4866 if (phone != null) {
4867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4868 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869
chen xu6dac5ab2018-10-26 17:39:23 -07004870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4873 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4874 return success;
4875 } finally {
4876 Binder.restoreCallingIdentity(identity);
4877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004878 }
chen xu6dac5ab2018-10-26 17:39:23 -07004879 return false;
4880 }
4881
4882 /**
4883 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4884 *
4885 * @param slotIndex - device slot.
4886 *
4887 * @return true on success; false on any failure
4888 */
4889 @Override
4890 public boolean rebootModem(int slotIndex) {
4891 Phone phone = PhoneFactory.getPhone(slotIndex);
4892 if (phone != null) {
4893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4894 mApp, phone.getSubId(), "rebootModem");
4895
4896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4899 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4900 return success;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
4904 }
4905 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004906 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004907
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004908 public String[] getPcscfAddress(String apnType, String callingPackage,
4909 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004910 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004911 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4912 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004913 return new String[0];
4914 }
4915
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004916 final long identity = Binder.clearCallingIdentity();
4917 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004918 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004919 } finally {
4920 Binder.restoreCallingIdentity(identity);
4921 }
Wink Saville36469e72014-06-11 15:17:00 -07004922 }
4923
Brad Ebinger51f743a2017-01-23 13:50:20 -08004924 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004925 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4926 * {@link #disableIms(int)}.
4927 * @param slotIndex device slot.
4928 */
4929 public void resetIms(int slotIndex) {
4930 enforceModifyPermission();
4931
4932 final long identity = Binder.clearCallingIdentity();
4933 try {
4934 if (mImsResolver == null) {
4935 // may happen if the does not support IMS.
4936 return;
4937 }
4938 mImsResolver.disableIms(slotIndex);
4939 mImsResolver.enableIms(slotIndex);
4940 } finally {
4941 Binder.restoreCallingIdentity(identity);
4942 }
4943 }
4944
4945 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004946 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4947 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004948 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004949 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004950 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004951
4952 final long identity = Binder.clearCallingIdentity();
4953 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004954 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004955 // may happen if the device does not support IMS.
4956 return;
4957 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004958 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004959 } finally {
4960 Binder.restoreCallingIdentity(identity);
4961 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004962 }
4963
4964 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004965 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4966 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004967 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004968 public void disableIms(int slotId) {
4969 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970
4971 final long identity = Binder.clearCallingIdentity();
4972 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004973 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004974 // may happen if the device does not support IMS.
4975 return;
4976 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004977 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004978 } finally {
4979 Binder.restoreCallingIdentity(identity);
4980 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004981 }
4982
4983 /**
4984 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4985 * feature or {@link null} if the service is not available. If the feature is available, the
4986 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4987 */
4988 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004989 IImsServiceFeatureCallback callback) {
4990 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004991
4992 final long identity = Binder.clearCallingIdentity();
4993 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004994 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004995 // may happen if the device does not support IMS.
4996 return null;
4997 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004998 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004999 } finally {
5000 Binder.restoreCallingIdentity(identity);
5001 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005002 }
5003
5004 /**
5005 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5006 * feature during emergency calling or {@link null} if the service is not available. If the
5007 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5008 * listener for feature updates.
5009 */
5010 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5011 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005012
5013 final long identity = Binder.clearCallingIdentity();
5014 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005015 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005016 // may happen if the device does not support IMS.
5017 return null;
5018 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005019 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005020 } finally {
5021 Binder.restoreCallingIdentity(identity);
5022 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005023 }
5024
Brad Ebinger5f64b052017-12-14 14:26:15 -08005025 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005026 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5027 */
5028 public void unregisterImsFeatureCallback(int slotId, int featureType,
5029 IImsServiceFeatureCallback callback) {
5030 enforceModifyPermission();
5031
5032 final long identity = Binder.clearCallingIdentity();
5033 try {
5034 if (mImsResolver == null) return;
5035 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5036 } finally {
5037 Binder.restoreCallingIdentity(identity);
5038 }
5039 }
5040
5041 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005042 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005043 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005044 */
5045 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5046 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005047
5048 final long identity = Binder.clearCallingIdentity();
5049 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005050 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005051 // may happen if the device does not support IMS.
5052 return null;
5053 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005054 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005055 } finally {
5056 Binder.restoreCallingIdentity(identity);
5057 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005058 }
5059
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005060 /**
5061 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005063 */
5064 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5065 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066
5067 final long identity = Binder.clearCallingIdentity();
5068 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005069 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005070 // may happen if the device does not support IMS.
5071 return null;
5072 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005073 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005074 } finally {
5075 Binder.restoreCallingIdentity(identity);
5076 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005077 }
5078
Brad Ebinger884c07b2018-02-15 16:17:40 -08005079 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005080 * Sets the ImsService Package Name that Telephony will bind to.
5081 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005082 * @param slotIndex the slot ID that the ImsService should bind for.
5083 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005084 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005085 * @param featureTypes An integer array of feature types associated with a packageName.
5086 * @param packageName The name of the package that the current configuration will be replaced
5087 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005088 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005089 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005090 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5091 int[] featureTypes, String packageName) {
5092 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5093 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005094 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5095 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005096 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005097
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005098 final long identity = Binder.clearCallingIdentity();
5099 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005100 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005101 // may happen if the device does not support IMS.
5102 return false;
5103 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005104 Map<Integer, String> featureConfig = new HashMap<>();
5105 for (int featureType : featureTypes) {
5106 featureConfig.put(featureType, packageName);
5107 }
5108 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5109 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005110 } finally {
5111 Binder.restoreCallingIdentity(identity);
5112 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005113 }
5114
5115 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005116 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005117 *
5118 * @param slotId The slot that the ImsService is associated with.
5119 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5120 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005121 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005122 * @return the package name of the ImsService configuration.
5123 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005124 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5125 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005126 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005127 TelephonyPermissions
5128 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5129 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5130 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005131
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005132 final long identity = Binder.clearCallingIdentity();
5133 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005134 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005135 // may happen if the device does not support IMS.
5136 return "";
5137 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005138 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005139 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5140 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005141 } finally {
5142 Binder.restoreCallingIdentity(identity);
5143 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005144 }
5145
Brad Ebinger77b832e2019-10-17 17:03:22 -07005146 /**
5147 * Get the MmTelFeature state associated with the requested subscription id.
5148 * @param subId The subscription that the MmTelFeature is associated with.
5149 * @param callback A callback with an integer containing the
5150 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5151 */
5152 @Override
5153 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5154 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5155 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5156 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5157 "IMS not available on device.");
5158 }
5159 final long token = Binder.clearCallingIdentity();
5160 try {
5161 int slotId = getSlotIndex(subId);
5162 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5163 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5164 + subId + "'");
5165 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5166 }
5167 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5168 try {
5169 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5170 } catch (RemoteException e) {
5171 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5172 + "Ignore");
5173 }
5174 });
5175 } finally {
5176 Binder.restoreCallingIdentity(token);
5177 }
5178 }
5179
Wink Saville36469e72014-06-11 15:17:00 -07005180 public void setImsRegistrationState(boolean registered) {
5181 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005182
5183 final long identity = Binder.clearCallingIdentity();
5184 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005185 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005186 } finally {
5187 Binder.restoreCallingIdentity(identity);
5188 }
Wink Saville36469e72014-06-11 15:17:00 -07005189 }
5190
5191 /**
Stuart Scott54788802015-03-30 13:18:01 -07005192 * Set the network selection mode to automatic.
5193 *
5194 */
5195 @Override
5196 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005197 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5198 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005199
5200 final long identity = Binder.clearCallingIdentity();
5201 try {
shilufc958392020-01-20 11:36:01 -08005202 if (!isActiveSubscription(subId)) {
5203 return;
5204 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5206 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5207 } finally {
5208 Binder.restoreCallingIdentity(identity);
5209 }
Stuart Scott54788802015-03-30 13:18:01 -07005210 }
5211
Pengquan Mengea84e042018-09-20 14:57:26 -07005212 /**
5213 * Ask the radio to connect to the input network and change selection mode to manual.
5214 *
5215 * @param subId the id of the subscription.
5216 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5217 * the operator to attach to.
5218 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5219 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5220 * normal network selection next time.
5221 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005222 */
5223 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005224 public boolean setNetworkSelectionModeManual(
5225 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005226 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5227 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005228
5229 if (!isActiveSubscription(subId)) {
5230 return false;
5231 }
5232
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005233 final long identity = Binder.clearCallingIdentity();
5234 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005235 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005236 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005237 if (DBG) {
5238 log("setNetworkSelectionModeManual: subId: " + subId
5239 + " operator: " + operatorInfo);
5240 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5242 } finally {
5243 Binder.restoreCallingIdentity(identity);
5244 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005245 }
5246
5247 /**
5248 * Scans for available networks.
5249 */
5250 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005251 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5252 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005253 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5254 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005255 LocationAccessPolicy.LocationPermissionResult locationResult =
5256 LocationAccessPolicy.checkLocationPermission(mApp,
5257 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5258 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005259 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005260 .setCallingPid(Binder.getCallingPid())
5261 .setCallingUid(Binder.getCallingUid())
5262 .setMethod("getCellNetworkScanResults")
5263 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5264 .build());
5265 switch (locationResult) {
5266 case DENIED_HARD:
5267 throw new SecurityException("Not allowed to access scan results -- location");
5268 case DENIED_SOFT:
5269 return null;
5270 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005271
Pengquan Menga1bb6272018-09-06 09:59:22 -07005272 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005273 try {
5274 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005275 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005276 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005280 }
5281
5282 /**
sqian80370722020-01-29 15:02:51 -08005283 * Get the call forwarding info, given the call forwarding reason.
5284 */
5285 @Override
5286 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5287 enforceReadPrivilegedPermission("getCallForwarding");
5288 long identity = Binder.clearCallingIdentity();
5289 try {
5290 if (DBG) {
5291 log("getCallForwarding: subId " + subId
5292 + " callForwardingReason" + callForwardingReason);
5293 }
5294 return (CallForwardingInfo) sendRequest(
5295 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5296 } finally {
5297 Binder.restoreCallingIdentity(identity);
5298 }
5299 }
5300
5301 /**
5302 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5303 * reason, the number to forward, and the timeout before the forwarding is attempted.
5304 */
5305 @Override
5306 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5307 enforceModifyPermission();
5308 long identity = Binder.clearCallingIdentity();
5309 try {
5310 if (DBG) {
5311 log("setCallForwarding: subId " + subId
5312 + " callForwardingInfo" + callForwardingInfo);
5313 }
5314 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5315 } finally {
5316 Binder.restoreCallingIdentity(identity);
5317 }
5318 }
5319
5320 /**
5321 * Get the call forwarding info, given the call forwarding reason.
5322 */
5323 @Override
5324 public int getCallWaitingStatus(int subId) {
5325 enforceReadPrivilegedPermission("getCallForwarding");
5326 long identity = Binder.clearCallingIdentity();
5327 try {
5328 if (DBG) log("getCallWaitingStatus: subId " + subId);
5329 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5330 } finally {
5331 Binder.restoreCallingIdentity(identity);
5332 }
5333 }
5334
5335 /**
5336 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5337 * reason, the number to forward, and the timeout before the forwarding is attempted.
5338 */
5339 @Override
5340 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5341 enforceModifyPermission();
5342 long identity = Binder.clearCallingIdentity();
5343 try {
5344 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5345 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5346 } finally {
5347 Binder.restoreCallingIdentity(identity);
5348 }
5349 }
5350
5351 /**
yinxub1bed742017-04-17 11:45:04 -07005352 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005353 *
yinxub1bed742017-04-17 11:45:04 -07005354 * @param subId id of the subscription
5355 * @param request contains the radio access networks with bands/channels to scan
5356 * @param messenger callback messenger for scan results or errors
5357 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005358 * @return the id of the requested scan which can be used to stop the scan.
5359 */
5360 @Override
5361 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005362 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005363 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5364 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005365 LocationAccessPolicy.LocationPermissionResult locationResult =
5366 LocationAccessPolicy.checkLocationPermission(mApp,
5367 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5368 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005369 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005370 .setCallingPid(Binder.getCallingPid())
5371 .setCallingUid(Binder.getCallingUid())
5372 .setMethod("requestNetworkScan")
5373 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5374 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005375 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005376 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005377 if (e != null) {
5378 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5379 throw e;
5380 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005381 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005382 return TelephonyScanManager.INVALID_SCAN_ID;
5383 }
5384 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005385 }
Hall Liu912dfd32019-04-25 14:02:26 -07005386 int callingUid = Binder.getCallingUid();
5387 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005388 final long identity = Binder.clearCallingIdentity();
5389 try {
5390 return mNetworkScanRequestTracker.startNetworkScan(
5391 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005392 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005393 } finally {
5394 Binder.restoreCallingIdentity(identity);
5395 }
yinxu504e1392017-04-12 16:03:22 -07005396 }
5397
Hall Liub2ac8ef2019-02-28 15:56:23 -08005398 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005399 NetworkScanRequest request, int subId) {
5400 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5401 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5402 boolean hasNetworkScanPermission =
5403 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5404 == PERMISSION_GRANTED;
5405
5406 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5407 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5408 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005409 }
5410
5411 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5412 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005413 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5414 return new SecurityException("Specific channels must not be"
5415 + " scanned without location access.");
5416 }
5417 }
5418 }
5419
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 return null;
5421 }
5422
yinxu504e1392017-04-12 16:03:22 -07005423 /**
5424 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005425 *
5426 * @param subId id of the subscription
5427 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005428 */
5429 @Override
5430 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005431 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5432 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005433
Hall Liu912dfd32019-04-25 14:02:26 -07005434 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005435 final long identity = Binder.clearCallingIdentity();
5436 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005437 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
yinxu504e1392017-04-12 16:03:22 -07005441 }
5442
5443 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005444 * Get the calculated preferred network type.
5445 * Used for debugging incorrect network type.
5446 *
5447 * @return the preferred network type, defined in RILConstants.java.
5448 */
5449 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005450 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005451 final Phone defaultPhone = getDefaultPhone();
5452 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005453 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005454 return RILConstants.PREFERRED_NETWORK_MODE;
5455 }
5456
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005457 final long identity = Binder.clearCallingIdentity();
5458 try {
5459 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005460 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005461 } finally {
5462 Binder.restoreCallingIdentity(identity);
5463 }
Junda Liu84d15a22014-07-02 11:21:04 -07005464 }
5465
5466 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005467 * Get the preferred network type.
5468 * Used for device configuration by some CDMA operators.
5469 *
5470 * @return the preferred network type, defined in RILConstants.java.
5471 */
5472 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005473 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005474 TelephonyPermissions
5475 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5476 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005477
5478 final long identity = Binder.clearCallingIdentity();
5479 try {
5480 if (DBG) log("getPreferredNetworkType");
5481 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5482 int networkType = (result != null ? result[0] : -1);
5483 if (DBG) log("getPreferredNetworkType: " + networkType);
5484 return networkType;
5485 } finally {
5486 Binder.restoreCallingIdentity(identity);
5487 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005488 }
5489
5490 /**
5491 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005492 *
5493 * @param networkType the preferred network type, defined in RILConstants.java.
5494 * @return true on success; false on any failure.
5495 */
5496 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005497 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5499 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500
5501 final long identity = Binder.clearCallingIdentity();
5502 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005503 Settings.Global.putInt(mApp.getContentResolver(),
5504 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005505
5506 Boolean success = (Boolean) sendRequest(
5507 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5508 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5509 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005510 } finally {
5511 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005512 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005513 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005514
5515 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005516 * Get the allowed network types that store in the telephony provider.
5517 *
5518 * @param subId the id of the subscription.
5519 * @return allowedNetworkTypes the allowed network types.
5520 */
5521 @Override
5522 public long getAllowedNetworkTypes(int subId) {
5523 TelephonyPermissions
5524 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5525 mApp, subId, "getAllowedNetworkTypes");
5526
5527 final long identity = Binder.clearCallingIdentity();
5528 try {
5529 return SubscriptionManager.getLongSubscriptionProperty(
5530 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5531 } finally {
5532 Binder.restoreCallingIdentity(identity);
5533 }
5534 }
5535
5536 /**
5537 * Set the allowed network types.
5538 *
5539 * @param subId the id of the subscription.
5540 * @param allowedNetworkTypes the allowed network types.
5541 * @return true on success; false on any failure.
5542 */
5543 @Override
5544 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5545 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5546 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005547
calvinpan089c2a62020-03-12 14:17:55 +08005548 SubscriptionManager.setSubscriptionProperty(subId,
5549 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5550 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005551
calvinpan089c2a62020-03-12 14:17:55 +08005552 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5553 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5554 RILConstants.PREFERRED_NETWORK_MODE);
5555 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005556 }
5557
5558 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005559 * Get the allowed network types for certain reason.
5560 *
5561 * @param subId the id of the subscription.
5562 * @param reason the reason the allowed network type change is taking place
5563 * @return the allowed network types.
5564 */
5565 @Override
5566 public long getAllowedNetworkTypesForReason(int subId,
5567 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5568 TelephonyPermissions
5569 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "getAllowedNetworkTypesForReason");
5571 final long identity = Binder.clearCallingIdentity();
5572 try {
5573 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
5577 }
5578
5579 /**
5580 * Get the effective allowed network types on the device.
5581 * This API will return an intersection of allowed network types for all reasons,
5582 * including the configuration done through setAllowedNetworkTypes
5583 *
5584 * @param subId the id of the subscription.
5585 * @return the allowed network types
5586 */
5587 @Override
5588 public long getEffectiveAllowedNetworkTypes(int subId) {
5589 TelephonyPermissions
5590 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5591 mApp, subId, "getEffectiveAllowedNetworkTypes");
5592 final long identity = Binder.clearCallingIdentity();
5593 try {
5594 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5595 } finally {
5596 Binder.restoreCallingIdentity(identity);
5597 }
5598 }
5599
5600 /**
5601 * Set the allowed network types of the device and
5602 * provide the reason triggering the allowed network change.
5603 *
5604 * @param subId the id of the subscription.
5605 * @param reason the reason the allowed network type change is taking place
5606 * @param allowedNetworkTypes the allowed network types.
5607 * @return true on success; false on any failure.
5608 */
5609 @Override
5610 public boolean setAllowedNetworkTypesForReason(int subId,
5611 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5612 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5613 mApp, subId, "setAllowedNetworkTypesForReason");
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5617 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5618 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5619 RILConstants.PREFERRED_NETWORK_MODE);
5620 return setPreferredNetworkType(subId, preferredNetworkMode);
5621 } finally {
5622 Binder.restoreCallingIdentity(identity);
5623 }
5624 }
5625
5626 /**
Miaoa84611c2019-03-15 09:21:10 +08005627 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005628 *
Miaoa84611c2019-03-15 09:21:10 +08005629 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005630 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005631 * @hide
5632 */
5633 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005634 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005635 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005636 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005637 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005638 try {
Miaoa84611c2019-03-15 09:21:10 +08005639 if (phone != null) {
5640 return phone.hasMatchedTetherApnSetting();
5641 } else {
5642 return false;
5643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005644 } finally {
5645 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005646 }
Junda Liu475951f2014-11-07 16:45:03 -08005647 }
5648
5649 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005650 * Set mobile data enabled
5651 * Used by the user through settings etc to turn on/off mobile data
5652 *
5653 * @param enable {@code true} turn turn data on, else {@code false}
5654 */
5655 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005656 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005659
5660 final long identity = Binder.clearCallingIdentity();
5661 try {
5662 int phoneId = mSubscriptionController.getPhoneId(subId);
5663 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5664 Phone phone = PhoneFactory.getPhone(phoneId);
5665 if (phone != null) {
5666 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005667 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005668 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005669 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005670 }
5671 } finally {
5672 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005673 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005674 }
5675
5676 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005677 * Enable or disable always reporting signal strength changes from radio.
5678 *
5679 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5680 */
5681 @Override
5682 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5683 enforceModifyPermission();
5684 enforceSystemCaller();
5685
5686 final long identity = Binder.clearCallingIdentity();
5687 final Phone phone = getPhone(subId);
5688 try {
5689 if (phone != null) {
5690 if (DBG) {
5691 log("setAlwaysReportSignalStrength: subId=" + subId
5692 + " isEnable=" + isEnable);
5693 }
5694 phone.setAlwaysReportSignalStrength(isEnable);
5695 } else {
5696 loge("setAlwaysReportSignalStrength: no phone found for subId="
5697 + subId);
5698 }
5699 } finally {
5700 Binder.restoreCallingIdentity(identity);
5701 }
5702 }
5703
5704 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005705 * Get the user enabled state of Mobile Data.
5706 *
5707 * TODO: remove and use isUserDataEnabled.
5708 * This can't be removed now because some vendor codes
5709 * calls through ITelephony directly while they should
5710 * use TelephonyManager.
5711 *
5712 * @return true on enabled
5713 */
5714 @Override
5715 public boolean getDataEnabled(int subId) {
5716 return isUserDataEnabled(subId);
5717 }
5718
5719 /**
5720 * Get whether mobile data is enabled per user setting.
5721 *
5722 * There are other factors deciding whether mobile data is actually enabled, but they are
5723 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005724 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005725 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005726 *
5727 * @return {@code true} if data is enabled else {@code false}
5728 */
5729 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005730 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005731 try {
5732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5733 null);
5734 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005735 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5736 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005737 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005738
5739 final long identity = Binder.clearCallingIdentity();
5740 try {
5741 int phoneId = mSubscriptionController.getPhoneId(subId);
5742 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5743 Phone phone = PhoneFactory.getPhone(phoneId);
5744 if (phone != null) {
5745 boolean retVal = phone.isUserDataEnabled();
5746 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5747 return retVal;
5748 } else {
5749 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5750 return false;
5751 }
5752 } finally {
5753 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005754 }
5755 }
5756
5757 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005758 * Checks if the device is capable of mobile data by considering whether whether the
5759 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5760 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005761 *
Shuo Qian985d1232020-01-08 14:30:06 -08005762 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005763 */
5764 @Override
5765 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005766 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005767
5768 final long identity = Binder.clearCallingIdentity();
5769 try {
5770 int phoneId = mSubscriptionController.getPhoneId(subId);
5771 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5772 Phone phone = PhoneFactory.getPhone(phoneId);
5773 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005774 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005775 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5776 return retVal;
5777 } else {
5778 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5779 return false;
5780 }
5781 } finally {
5782 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005783 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005784 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005785
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005786 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005787 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005788 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5789 // Skip the check if it's one of these special uids
5790 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5791 }
5792
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005793 //load access rules from carrier configs, and check those as well: b/139133814
5794 SubscriptionController subController = SubscriptionController.getInstance();
5795 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5796 || subController == null) return privilegeFromSim;
5797
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005798 PackageManager pkgMgr = phone.getContext().getPackageManager();
5799 String[] packages = pkgMgr.getPackagesForUid(uid);
5800
5801 final long identity = Binder.clearCallingIdentity();
5802 try {
5803 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5804 SubscriptionManager subManager = (SubscriptionManager)
5805 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5806 for (String pkg : packages) {
5807 if (subManager.canManageSubscription(subInfo, pkg)) {
5808 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5809 }
5810 }
5811 return privilegeFromSim;
5812 } finally {
5813 Binder.restoreCallingIdentity(identity);
5814 }
5815 }
5816
5817 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5818 String pkgName) {
5819 //load access rules from carrier configs, and check those as well: b/139133814
5820 SubscriptionController subController = SubscriptionController.getInstance();
5821 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5822 || subController == null) return privilegeFromSim;
5823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5827 SubscriptionManager subManager = (SubscriptionManager)
5828 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5829 return subManager.canManageSubscription(subInfo, pkgName)
5830 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5831 } finally {
5832 Binder.restoreCallingIdentity(identity);
5833 }
5834 }
5835
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005836 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005837 public int getCarrierPrivilegeStatus(int subId) {
5838 final Phone phone = getPhone(subId);
5839 if (phone == null) {
5840 loge("getCarrierPrivilegeStatus: Invalid subId");
5841 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5842 }
5843 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005844 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005845 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5847 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005848
5849 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5850 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005851 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005852 }
Junda Liu29340342014-07-10 15:23:27 -07005853
5854 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005855 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005856 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005857 final Phone phone = getPhone(subId);
5858 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005859 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005860 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5861 }
5862 UiccProfile profile =
5863 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5864 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005865 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005866 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5867 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005868 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005869 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005870 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005871 }
5872
5873 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005874 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5875 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005876 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005877 }
5878
5879 int phoneId = SubscriptionManager.getPhoneId(subId);
5880 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005881 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005882 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005883 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5884 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005885 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5886 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5887 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005888 }
5889
5890 @Override
5891 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005892 if (TextUtils.isEmpty(pkgName))
5893 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005894 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5895 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5896 UiccCard card = UiccController.getInstance().getUiccCard(i);
5897 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005898 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005899 continue;
5900 }
5901
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005902 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5903 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5904 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005905 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5906 break;
5907 }
5908 }
5909
5910 return result;
Junda Liu29340342014-07-10 15:23:27 -07005911 }
Derek Tan89e89d42014-07-08 17:00:10 -07005912
5913 @Override
Junda Liue64de782015-04-16 17:19:16 -07005914 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5915 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5916 loge("phoneId " + phoneId + " is not valid.");
5917 return null;
5918 }
5919 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005920 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005921 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005922 return null ;
5923 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005924 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005925 }
5926
Amith Yamasani6e118872016-02-19 12:53:51 -08005927 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005928 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005929 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005930 List<String> privilegedPackages = new ArrayList<>();
5931 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005932 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5933 // has UICC in that slot.
5934 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005935 if (card.hasCarrierPrivilegeRules()) {
5936 if (packages == null) {
5937 // Only check packages in user 0 for now
5938 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005939 PackageManager.MATCH_DISABLED_COMPONENTS
5940 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005941 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005942 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005943 }
5944 for (int p = packages.size() - 1; p >= 0; p--) {
5945 PackageInfo pkgInfo = packages.get(p);
5946 if (pkgInfo != null && pkgInfo.packageName != null
5947 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005948 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005949 privilegedPackages.add(pkgInfo.packageName);
5950 }
5951 }
5952 }
5953 }
5954 return privilegedPackages;
5955 }
5956
chen xuf7e9fe82019-05-09 19:31:02 -07005957 @Override
5958 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005959 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5960
5961 final long identity = Binder.clearCallingIdentity();
5962
chen xuf7e9fe82019-05-09 19:31:02 -07005963 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00005964 try {
5965 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5966 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5967 }
5968 } finally {
5969 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005970 }
5971 return privilegedPackages;
5972 }
5973
Wink Savilleb564aae2014-10-23 10:18:09 -07005974 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005975 final Phone phone = getPhone(subId);
5976 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005977 if (card == null) {
5978 loge("getIccId: No UICC");
5979 return null;
5980 }
5981 String iccId = card.getIccId();
5982 if (TextUtils.isEmpty(iccId)) {
5983 loge("getIccId: ICC ID is null or empty.");
5984 return null;
5985 }
5986 return iccId;
5987 }
5988
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005989 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005990 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5991 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08005992 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005993 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005994
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005995 final long identity = Binder.clearCallingIdentity();
5996 try {
5997 final String iccId = getIccId(subId);
5998 final Phone phone = getPhone(subId);
5999 if (phone == null) {
6000 return false;
6001 }
6002 final String subscriberId = phone.getSubscriberId();
6003
6004 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006005 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006006 + subscriberId + " to " + number);
6007 }
6008
6009 if (TextUtils.isEmpty(iccId)) {
6010 return false;
6011 }
6012
6013 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6014
6015 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6016 if (alphaTag == null) {
6017 editor.remove(alphaTagPrefKey);
6018 } else {
6019 editor.putString(alphaTagPrefKey, alphaTag);
6020 }
6021
6022 // Record both the line number and IMSI for this ICCID, since we need to
6023 // track all merged IMSIs based on line number
6024 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6025 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6026 if (number == null) {
6027 editor.remove(numberPrefKey);
6028 editor.remove(subscriberPrefKey);
6029 } else {
6030 editor.putString(numberPrefKey, number);
6031 editor.putString(subscriberPrefKey, subscriberId);
6032 }
6033
6034 editor.commit();
6035 return true;
6036 } finally {
6037 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006038 }
Derek Tan7226c842014-07-02 17:42:23 -07006039 }
6040
6041 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006042 public String getLine1NumberForDisplay(int subId, String callingPackage,
6043 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006044 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006045 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006046 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006047 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006048 return null;
6049 }
Derek Tan97ebb422014-09-05 16:55:38 -07006050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 String iccId = getIccId(subId);
6054 if (iccId != null) {
6055 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6056 if (DBG_MERGE) {
6057 log("getLine1NumberForDisplay returning "
6058 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6059 }
6060 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006061 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6063 return null;
6064 } finally {
6065 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006066 }
Derek Tan7226c842014-07-02 17:42:23 -07006067 }
6068
6069 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006070 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6071 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006073 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006074 return null;
6075 }
Derek Tan97ebb422014-09-05 16:55:38 -07006076
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006077 final long identity = Binder.clearCallingIdentity();
6078 try {
6079 String iccId = getIccId(subId);
6080 if (iccId != null) {
6081 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6082 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6083 }
6084 return null;
6085 } finally {
6086 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006087 }
Derek Tan7226c842014-07-02 17:42:23 -07006088 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006089
6090 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006091 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6092 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006093 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6094 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006095 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006096 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006097 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006098 return null;
6099 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006100
Jordan Liub49b04b2019-05-06 14:45:15 -07006101 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6102 // the process, where TelephonyManager was instantiated.
6103 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006104 final long identity = Binder.clearCallingIdentity();
6105 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006106 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 final TelephonyManager tele = TelephonyManager.from(context);
6108 final SubscriptionManager sub = SubscriptionManager.from(context);
6109
6110 // Figure out what subscribers are currently active
6111 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006112
Jordan Liub49b04b2019-05-06 14:45:15 -07006113 // Only consider subs which match the current subId
6114 // This logic can be simplified. See b/131189269 for progress.
6115 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006116 activeSubscriberIds.add(tele.getSubscriberId(subId));
6117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118
6119 // First pass, find a number override for an active subscriber
6120 String mergeNumber = null;
6121 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6122 for (String key : prefs.keySet()) {
6123 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6124 final String subscriberId = (String) prefs.get(key);
6125 if (activeSubscriberIds.contains(subscriberId)) {
6126 final String iccId = key.substring(
6127 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6128 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6129 mergeNumber = (String) prefs.get(numberKey);
6130 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006131 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 + " for active subscriber " + subscriberId);
6133 }
6134 if (!TextUtils.isEmpty(mergeNumber)) {
6135 break;
6136 }
6137 }
6138 }
6139 }
6140
6141 // Shortcut when no active merged subscribers
6142 if (TextUtils.isEmpty(mergeNumber)) {
6143 return null;
6144 }
6145
6146 // Second pass, find all subscribers under that line override
6147 final ArraySet<String> result = new ArraySet<>();
6148 for (String key : prefs.keySet()) {
6149 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6150 final String number = (String) prefs.get(key);
6151 if (mergeNumber.equals(number)) {
6152 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6153 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6154 final String subscriberId = (String) prefs.get(subscriberKey);
6155 if (!TextUtils.isEmpty(subscriberId)) {
6156 result.add(subscriberId);
6157 }
6158 }
6159 }
6160 }
6161
6162 final String[] resultArray = result.toArray(new String[result.size()]);
6163 Arrays.sort(resultArray);
6164 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006165 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006166 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6167 }
6168 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006169 } finally {
6170 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006171 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006172 }
6173
6174 @Override
Malcolm Chen6ca97372019-07-01 16:28:21 -07006175 public String[] getMergedSubscriberIdsFromGroup(int subId, String callingPackage) {
6176 enforceReadPrivilegedPermission("getMergedSubscriberIdsFromGroup");
6177
6178 final long identity = Binder.clearCallingIdentity();
6179 try {
6180 final TelephonyManager telephonyManager = mApp.getSystemService(
6181 TelephonyManager.class);
6182 String subscriberId = telephonyManager.getSubscriberId(subId);
6183 if (subscriberId == null) {
6184 if (DBG) {
6185 log("getMergedSubscriberIdsFromGroup can't find subscriberId for subId "
6186 + subId);
6187 }
6188 return null;
6189 }
6190
6191 final SubscriptionInfo info = SubscriptionController.getInstance()
6192 .getSubscriptionInfo(subId);
6193 final ParcelUuid groupUuid = info.getGroupUuid();
6194 // If it doesn't belong to any group, return just subscriberId of itself.
6195 if (groupUuid == null) {
6196 return new String[]{subscriberId};
6197 }
6198
6199 // Get all subscriberIds from the group.
6200 final List<String> mergedSubscriberIds = new ArrayList<>();
6201 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006202 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
6203 null);
Malcolm Chen6ca97372019-07-01 16:28:21 -07006204 for (SubscriptionInfo subInfo : groupInfos) {
6205 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6206 if (subscriberId != null) {
6207 mergedSubscriberIds.add(subscriberId);
6208 }
6209 }
6210
6211 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6212 } finally {
6213 Binder.restoreCallingIdentity(identity);
6214
6215 }
6216 }
6217
6218 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006219 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006220 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006221 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222
6223 final long identity = Binder.clearCallingIdentity();
6224 try {
6225 final Phone phone = getPhone(subId);
6226 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6227 } finally {
6228 Binder.restoreCallingIdentity(identity);
6229 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006230 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006231
6232 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006233 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006234 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6235 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006236 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6237 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238
6239 final long identity = Binder.clearCallingIdentity();
6240 try {
6241 final Phone phone = getPhone(subId);
6242 if (phone == null) {
6243 return false;
6244 }
6245 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6246 cdmaNonRoamingList);
6247 } finally {
6248 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006249 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006250 }
6251
6252 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006253 @Deprecated
6254 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6255 enforceModifyPermission();
6256
6257 int returnValue = 0;
6258 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006259 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006260 if(result.exception == null) {
6261 if (result.result != null) {
6262 byte[] responseData = (byte[])(result.result);
6263 if(responseData.length > oemResp.length) {
6264 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6265 responseData.length + "bytes. Buffer Size is " +
6266 oemResp.length + "bytes.");
6267 }
6268 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6269 returnValue = responseData.length;
6270 }
6271 } else {
6272 CommandException ex = (CommandException) result.exception;
6273 returnValue = ex.getCommandError().ordinal();
6274 if(returnValue > 0) returnValue *= -1;
6275 }
6276 } catch (RuntimeException e) {
6277 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6278 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6279 if(returnValue > 0) returnValue *= -1;
6280 }
6281
6282 return returnValue;
6283 }
6284
6285 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006286 public void setRadioCapability(RadioAccessFamily[] rafs) {
6287 try {
6288 ProxyController.getInstance().setRadioCapability(rafs);
6289 } catch (RuntimeException e) {
6290 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6291 }
6292 }
6293
6294 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006295 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006296 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006297 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006298 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006299 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006300 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006301 final long identity = Binder.clearCallingIdentity();
6302 try {
chen xub97461a2018-10-26 14:17:57 -07006303 TelephonyPermissions
6304 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6305 mApp, phone.getSubId(), "getRadioAccessFamily");
6306 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006307 } finally {
6308 Binder.restoreCallingIdentity(identity);
6309 }
chen xub97461a2018-10-26 14:17:57 -07006310 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006311 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006312
6313 @Override
6314 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006315 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006316 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006317
6318 final long identity = Binder.clearCallingIdentity();
6319 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006320 ImsManager.getInstance(defaultPhone.getContext(),
6321 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006322 } finally {
6323 Binder.restoreCallingIdentity(identity);
6324 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006325 }
6326
6327 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006328 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006329 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006330 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6331 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006332 return false;
6333 }
Svet Ganovb320e182015-04-16 12:30:10 -07006334
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006335 final long identity = Binder.clearCallingIdentity();
6336 try {
6337 // Check the user preference and the system-level IMS setting. Even if the user has
6338 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6339 // In the long run, we may instead need to check if there exists a connection service
6340 // which can support video calling.
6341 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006342 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 return imsManager.isVtEnabledByPlatform()
6344 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6345 && imsManager.isVtEnabledByUser();
6346 } finally {
6347 Binder.restoreCallingIdentity(identity);
6348 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006349 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006350
Andrew Leea1239f22015-03-02 17:44:07 -08006351 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006352 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6353 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006354 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006355 mApp, subId, callingPackage, callingFeatureId,
6356 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 return false;
6358 }
6359
6360 final long identity = Binder.clearCallingIdentity();
6361 try {
6362 CarrierConfigManager configManager =
6363 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006364 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006365 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6366 } finally {
6367 Binder.restoreCallingIdentity(identity);
6368 }
Andrew Leea1239f22015-03-02 17:44:07 -08006369 }
6370
6371 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006372 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006374 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 return false;
6376 }
6377
6378 final long identity = Binder.clearCallingIdentity();
6379 try {
6380 CarrierConfigManager configManager =
6381 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006382 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006383 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6384 } finally {
6385 Binder.restoreCallingIdentity(identity);
6386 }
Andrew Leea1239f22015-03-02 17:44:07 -08006387 }
6388
Andrew Lee9431b832015-03-09 18:46:45 -07006389 @Override
6390 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006391 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006392 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006393 }
6394
6395 @Override
6396 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006397 final long identity = Binder.clearCallingIdentity();
6398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006399 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 } finally {
6401 Binder.restoreCallingIdentity(identity);
6402 }
Andrew Lee9431b832015-03-09 18:46:45 -07006403 }
6404
Hall Liuf6668912018-10-31 17:05:23 -07006405 /**
6406 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6407 * support for the feature and device firmware support.
6408 *
6409 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6410 */
6411 @Override
6412 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006414 final Phone phone = getPhone(subscriptionId);
6415 if (phone == null) {
6416 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6417 return false;
6418 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006420 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6422 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006423 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 return isCarrierSupported && isDeviceSupported;
6425 } finally {
6426 Binder.restoreCallingIdentity(identity);
6427 }
Hall Liu98187582018-01-22 19:15:32 -08006428 }
6429
Hall Liuf6668912018-10-31 17:05:23 -07006430 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006431 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6432 * RTT setting, will return true if the device and carrier both support RTT.
6433 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006434 */
6435 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 final long identity = Binder.clearCallingIdentity();
6437 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006438 boolean isRttSupported = isRttSupported(subscriptionId);
6439 boolean isUserRttSettingOn = Settings.Secure.getInt(
6440 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6441 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6442 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6443 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006444 } finally {
6445 Binder.restoreCallingIdentity(identity);
6446 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006447 }
6448
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006449 @Deprecated
6450 @Override
6451 public String getDeviceId(String callingPackage) {
6452 return getDeviceIdWithFeature(callingPackage, null);
6453 }
6454
Sanket Padawe7310cc72015-01-14 09:53:20 -08006455 /**
6456 * Returns the unique device ID of phone, for example, the IMEI for
6457 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6458 *
6459 * <p>Requires Permission:
6460 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6461 */
6462 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006463 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006464 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006465 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006466 return null;
6467 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006468 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006469 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006470 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006471 return null;
6472 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006473
6474 final long identity = Binder.clearCallingIdentity();
6475 try {
6476 return phone.getDeviceId();
6477 } finally {
6478 Binder.restoreCallingIdentity(identity);
6479 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006480 }
6481
Ping Sunc67b7c22016-03-02 19:16:45 +08006482 /**
6483 * {@hide}
6484 * Returns the IMS Registration Status on a particular subid
6485 *
6486 * @param subId
6487 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006488 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006489 Phone phone = getPhone(subId);
6490 if (phone != null) {
6491 return phone.isImsRegistered();
6492 } else {
6493 return false;
6494 }
6495 }
6496
Santos Cordon7a1885b2015-02-03 11:15:19 -08006497 @Override
6498 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006499 final long identity = Binder.clearCallingIdentity();
6500 try {
6501 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6502 } finally {
6503 Binder.restoreCallingIdentity(identity);
6504 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006505 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006506
Tyler Gunnf70ed162019-04-03 15:28:53 -07006507 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006508 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006509 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006510 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006511 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006512 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6513 }
6514 final long identity = Binder.clearCallingIdentity();
6515 try {
6516 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6517 } finally {
6518 Binder.restoreCallingIdentity(identity);
6519 }
6520 }
6521
6522 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006523 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006524 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6525 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 Phone phone = getPhone(subscriptionId);
6529 if (phone == null) {
6530 return null;
6531 }
6532 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
6536 }
6537
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006538 /**
6539 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006540 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006541 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 Phone phone = getPhone(subId);
6545 if (phone != null) {
6546 return phone.isWifiCallingEnabled();
6547 } else {
6548 return false;
6549 }
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006552 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006553 }
6554
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006555 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006556 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006557 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006558 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 Phone phone = getPhone(subId);
6562 if (phone != null) {
6563 return phone.isVideoEnabled();
6564 } else {
6565 return false;
6566 }
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006569 }
6570 }
6571
6572 /**
6573 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6574 * defined in {@link ImsRegistrationImplBase}.
6575 */
6576 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 Phone phone = getPhone(subId);
6580 if (phone != null) {
6581 return phone.getImsRegistrationTech();
6582 } else {
6583 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6584 }
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006587 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006588 }
6589
Stuart Scott8eef64f2015-04-08 15:13:54 -07006590 @Override
6591 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006592 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006593 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6594 return;
6595 }
6596
Svet Ganovcc087f82015-05-12 20:35:54 -07006597 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006598
Svet Ganovcc087f82015-05-12 20:35:54 -07006599 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006600 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6601 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006602 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006603 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006604 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006605 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6606 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006607 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006608 // There has been issues when Sms raw table somehow stores orphan
6609 // fragments. They lead to garbled message when new fragments come
6610 // in and combined with those stale ones. In case this happens again,
6611 // user can reset all network settings which will clean up this table.
6612 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006613 // Clean up IMS settings as well here.
6614 int slotId = getSlotIndex(subId);
6615 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6616 ImsManager.getInstance(mApp, slotId).factoryReset();
6617 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006618
6619 // Erase modem config if erase modem on network setting is enabled.
6620 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6621 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6622 if (configValue != null && Boolean.parseBoolean(configValue)) {
6623 sendEraseModemConfig(getDefaultPhone());
6624 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006625 } finally {
6626 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006627 }
6628 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006629
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006630 private void cleanUpSmsRawTable(Context context) {
6631 ContentResolver resolver = context.getContentResolver();
6632 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6633 resolver.delete(uri, null, null);
6634 }
6635
Narayan Kamath1c496c22015-04-16 14:40:19 +01006636 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006637 public String getSimLocaleForSubscriber(int subId) {
6638 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6639 final Phone phone = getPhone(subId);
6640 if (phone == null) {
6641 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006642 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006644 final long identity = Binder.clearCallingIdentity();
6645 try {
chen xu5d3637b2019-01-21 23:31:38 -08006646 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006647 phone.getContext().getOpPackageName(), null);
chen xu6291c472019-02-04 12:55:53 -08006648 if (info == null) {
6649 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6650 return null;
6651 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006652 // Try and fetch the locale from the carrier properties or from the SIM language
6653 // preferences (EF-PL and EF-LI)...
6654 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006655 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006656 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6657 if (localeFromDefaultSim != null) {
6658 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6659 if (DBG) log("Using locale from subId: " + subId + " locale: "
6660 + localeFromDefaultSim);
6661 return localeFromDefaultSim.toLanguageTag();
6662 } else {
6663 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006664 }
6665 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006666
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006667 // The SIM language preferences only store a language (e.g. fr = French), not an
6668 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6669 // the SIM and carrier preferences does not include a country we add the country
6670 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006671 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006672 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006673 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006674 return mccLocale.toLanguageTag();
6675 }
6676
6677 if (DBG) log("No locale found - returning null");
6678 return null;
6679 } finally {
6680 Binder.restoreCallingIdentity(identity);
6681 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006682 }
6683
6684 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006685 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
6686 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006687 }
6688
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006689 /**
6690 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6691 */
6692 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006693 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
6694 null);
Narayan Kamath1c496c22015-04-16 14:40:19 +01006695 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006696
Chenjie Yu1ba97252018-01-11 18:16:20 -08006697 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006698 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006699
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006700 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006701 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6702 * representing the state of the modem.
6703 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006704 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6705 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006706 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006707 */
6708 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006709 public void requestModemActivityInfo(ResultReceiver result) {
6710 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006711 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006712
6713 final long identity = Binder.clearCallingIdentity();
6714 try {
sqian1a1be542020-03-05 11:37:28 -08006715 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 } finally {
6717 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006718 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006719 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006720
Siddharth Rayb8114062018-06-17 15:02:38 -07006721 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6722 // less than total activity duration.
6723 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6724 if (info == null) {
6725 return false;
6726 }
6727 int activityDurationMs =
6728 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6729 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006730 int[] txTimeMs = info.getTransmitTimeMillis();
6731 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6732 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006733 }
6734 return (info.isValid()
6735 && (info.getSleepTimeMillis() <= activityDurationMs)
6736 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006737 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006738 && (totalTxTimeMs <= activityDurationMs));
6739 }
6740
Jack Yu85bd38a2015-11-09 11:34:32 -08006741 /**
6742 * {@hide}
6743 * Returns the service state information on specified subscription.
6744 */
6745 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006746 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6747 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006748 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006749 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006750 return null;
6751 }
6752
Hall Liuf19c44f2018-11-27 14:38:17 -08006753 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6754 LocationAccessPolicy.checkLocationPermission(mApp,
6755 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6756 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006757 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006758 .setCallingPid(Binder.getCallingPid())
6759 .setCallingUid(Binder.getCallingUid())
6760 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006761 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006762 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6763 .build());
6764
6765 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6766 LocationAccessPolicy.checkLocationPermission(mApp,
6767 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6768 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006769 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006770 .setCallingPid(Binder.getCallingPid())
6771 .setCallingUid(Binder.getCallingUid())
6772 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006773 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006774 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6775 .build());
6776 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6777 boolean hasFinePermission =
6778 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6779 boolean hasCoarsePermission =
6780 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6781
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006782 final long identity = Binder.clearCallingIdentity();
6783 try {
6784 final Phone phone = getPhone(subId);
6785 if (phone == null) {
6786 return null;
6787 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006788
Hall Liuf19c44f2018-11-27 14:38:17 -08006789 ServiceState ss = phone.getServiceState();
6790
6791 // Scrub out the location info in ServiceState depending on what level of access
6792 // the caller has.
6793 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006794 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6795 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006796 } finally {
6797 Binder.restoreCallingIdentity(identity);
6798 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006799 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006800
6801 /**
6802 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6803 *
6804 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6805 * voicemail ringtone.
6806 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6807 * PhoneAccount.
6808 */
6809 @Override
6810 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006811 final long identity = Binder.clearCallingIdentity();
6812 try {
6813 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6814 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006815 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6819 } finally {
6820 Binder.restoreCallingIdentity(identity);
6821 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006822 }
6823
6824 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006825 * Sets the per-account voicemail ringtone.
6826 *
6827 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6828 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6829 *
6830 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6831 * voicemail ringtone.
6832 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6833 * PhoneAccount.
6834 */
6835 @Override
6836 public void setVoicemailRingtoneUri(String callingPackage,
6837 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006838 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006839 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006840 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6841 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006842 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6843 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6844 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006845 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006846
6847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6850 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006851 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 }
6853 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6854 } finally {
6855 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006856 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006857 }
6858
6859 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006860 * Returns whether vibration is set for voicemail notification in Phone settings.
6861 *
6862 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6863 * voicemail vibration setting.
6864 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6865 */
6866 @Override
6867 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006868 final long identity = Binder.clearCallingIdentity();
6869 try {
6870 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6871 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006872 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006874
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006875 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6876 } finally {
6877 Binder.restoreCallingIdentity(identity);
6878 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006879 }
6880
Youhan Wange64578a2016-05-02 15:32:42 -07006881 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006882 * Sets the per-account voicemail vibration.
6883 *
6884 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6885 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6886 *
6887 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6888 * voicemail vibration setting.
6889 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6890 * specific PhoneAccount.
6891 */
6892 @Override
6893 public void setVoicemailVibrationEnabled(String callingPackage,
6894 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006895 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006896 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006897 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6898 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6900 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6901 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006902 }
6903
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6907 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006908 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 }
6910 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6911 } finally {
6912 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006913 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006914 }
6915
6916 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006917 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6918 *
6919 * @throws SecurityException if the caller does not have the required permission
6920 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006921 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006922 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006923 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006924 }
6925
6926 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006927 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6928 * permission.
6929 *
6930 * @throws SecurityException if the caller does not have the required permission
6931 */
6932 private void enforceSendSmsPermission() {
6933 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6934 }
6935
6936 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006937 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006938 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006939 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006940 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006941 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006942 final long identity = Binder.clearCallingIdentity();
6943 try {
6944 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006945 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 if (componentName == null) {
6947 throw new SecurityException(
6948 "Caller not current active visual voicemail package[null]");
6949 }
6950 String vvmPackage = componentName.getPackageName();
6951 if (!callingPackage.equals(vvmPackage)) {
6952 throw new SecurityException("Caller not current active visual voicemail package["
6953 + vvmPackage + "]");
6954 }
6955 } finally {
6956 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006957 }
6958 }
6959
6960 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006961 * Return the application ID for the app type.
6962 *
6963 * @param subId the subscription ID that this request applies to.
6964 * @param appType the uicc app type.
6965 * @return Application ID for specificied app type, or null if no uicc.
6966 */
6967 @Override
6968 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006969 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006970 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006971
6972 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006973 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006974 if (phone == null) {
6975 return null;
6976 }
6977 String aid = null;
6978 try {
6979 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6980 .getApplicationByType(appType).getAid();
6981 } catch (Exception e) {
6982 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6983 }
6984 return aid;
6985 } finally {
6986 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006987 }
Youhan Wange64578a2016-05-02 15:32:42 -07006988 }
6989
Youhan Wang4001d252016-05-11 10:29:41 -07006990 /**
6991 * Return the Electronic Serial Number.
6992 *
6993 * @param subId the subscription ID that this request applies to.
6994 * @return ESN or null if error.
6995 */
6996 @Override
6997 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006998 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07006999 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007000
7001 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007002 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007003 if (phone == null) {
7004 return null;
7005 }
7006 String esn = null;
7007 try {
7008 esn = phone.getEsn();
7009 } catch (Exception e) {
7010 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7011 }
7012 return esn;
7013 } finally {
7014 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007015 }
Youhan Wang4001d252016-05-11 10:29:41 -07007016 }
7017
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007018 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007019 * Return the Preferred Roaming List Version.
7020 *
7021 * @param subId the subscription ID that this request applies to.
7022 * @return PRLVersion or null if error.
7023 */
7024 @Override
7025 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007026 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007027 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007028
7029 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007030 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007031 if (phone == null) {
7032 return null;
7033 }
7034 String cdmaPrlVersion = null;
7035 try {
7036 cdmaPrlVersion = phone.getCdmaPrlVersion();
7037 } catch (Exception e) {
7038 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7039 }
7040 return cdmaPrlVersion;
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007043 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007044 }
7045
7046 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007047 * Get snapshot of Telephony histograms
7048 * @return List of Telephony histograms
7049 * @hide
7050 */
7051 @Override
7052 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007053 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7054 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007055
7056 final long identity = Binder.clearCallingIdentity();
7057 try {
7058 return RIL.getTelephonyRILTimingHistograms();
7059 } finally {
7060 Binder.restoreCallingIdentity(identity);
7061 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007062 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007063
7064 /**
7065 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007066 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7067 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007068 * Require system privileges. In the future we may add this to carrier APIs.
7069 *
Michele Berionne482f8202018-11-27 18:57:59 -08007070 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007071 */
7072 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007073 @TelephonyManager.SetCarrierRestrictionResult
7074 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007075 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007076 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007077
Michele Berionne482f8202018-11-27 18:57:59 -08007078 if (carrierRestrictionRules == null) {
7079 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007080 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007081
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 final long identity = Binder.clearCallingIdentity();
7083 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007084 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007085 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007086 } finally {
7087 Binder.restoreCallingIdentity(identity);
7088 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007089 }
7090
7091 /**
7092 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007093 * Get the allowed carrier list and the excluded carrier list, including the priority between
7094 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007095 * Require system privileges. In the future we may add this to carrier APIs.
7096 *
Michele Berionne482f8202018-11-27 18:57:59 -08007097 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007098 */
7099 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007100 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007101 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007102 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
7105 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007106 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7107 if (response instanceof CarrierRestrictionRules) {
7108 return (CarrierRestrictionRules) response;
7109 }
7110 // Response is an Exception of some kind,
7111 // which is signalled to the user as a NULL retval
7112 return null;
7113 } catch (Exception e) {
7114 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7115 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007116 } finally {
7117 Binder.restoreCallingIdentity(identity);
7118 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007119 }
7120
fionaxu59545b42016-05-25 15:53:37 -07007121 /**
7122 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7123 * @param subId the subscription ID that this action applies to.
7124 * @param enabled control enable or disable metered apns.
7125 * {@hide}
7126 */
7127 @Override
7128 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7129 enforceModifyPermission();
7130 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007131
7132 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007133 if (phone == null) {
7134 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7135 return;
7136 }
7137 try {
7138 phone.carrierActionSetMeteredApnsEnabled(enabled);
7139 } catch (Exception e) {
7140 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007141 } finally {
7142 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007143 }
7144 }
7145
7146 /**
7147 * Action set from carrier signalling broadcast receivers to enable/disable radio
7148 * @param subId the subscription ID that this action applies to.
7149 * @param enabled control enable or disable radio.
7150 * {@hide}
7151 */
7152 @Override
7153 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7154 enforceModifyPermission();
7155 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007156
7157 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007158 if (phone == null) {
7159 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7160 return;
7161 }
7162 try {
7163 phone.carrierActionSetRadioEnabled(enabled);
7164 } catch (Exception e) {
7165 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007166 } finally {
7167 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007168 }
7169 }
7170
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007171 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007172 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7173 * network status based on which carrier apps could apply actions accordingly,
7174 * enable/disable default url handler for example.
7175 *
7176 * @param subId the subscription ID that this action applies to.
7177 * @param report control start/stop reporting the default network status.
7178 * {@hide}
7179 */
7180 @Override
7181 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7182 enforceModifyPermission();
7183 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007184
7185 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007186 if (phone == null) {
7187 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7188 return;
7189 }
7190 try {
7191 phone.carrierActionReportDefaultNetworkStatus(report);
7192 } catch (Exception e) {
7193 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007194 } finally {
7195 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007196 }
7197 }
7198
7199 /**
fionaxud9622282017-07-17 17:51:30 -07007200 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7201 * @param subId the subscription ID that this action applies to.
7202 * {@hide}
7203 */
7204 @Override
7205 public void carrierActionResetAll(int subId) {
7206 enforceModifyPermission();
7207 final Phone phone = getPhone(subId);
7208 if (phone == null) {
7209 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7210 return;
7211 }
7212 try {
7213 phone.carrierActionResetAll();
7214 } catch (Exception e) {
7215 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7216 }
7217 }
7218
7219 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007220 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7221 * bug report is being generated.
7222 */
7223 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007224 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007225 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7226 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007227 writer.println("Permission Denial: can't dump Phone from pid="
7228 + Binder.getCallingPid()
7229 + ", uid=" + Binder.getCallingUid()
7230 + "without permission "
7231 + android.Manifest.permission.DUMP);
7232 return;
7233 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007234 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007235 }
Jack Yueb89b242016-06-22 13:27:47 -07007236
Brad Ebingerdac2f002018-04-03 15:17:52 -07007237 @Override
7238 public void onShellCommand(FileDescriptor in, FileDescriptor out, FileDescriptor err,
7239 String[] args, ShellCallback callback, ResultReceiver resultReceiver)
7240 throws RemoteException {
Torbjorn Eklund1050cb02018-11-16 14:05:38 +01007241 (new TelephonyShellCommand(this, getDefaultPhone().getContext()))
7242 .exec(this, in, out, err, args, callback, resultReceiver);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007243 }
7244
Jack Yueb89b242016-06-22 13:27:47 -07007245 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007246 * Policy control of data connection. Usually used when data limit is passed.
7247 * @param enabled True if enabling the data, otherwise disabling.
7248 * @param subId Subscription index
7249 * {@hide}
7250 */
7251 @Override
7252 public void setPolicyDataEnabled(boolean enabled, int subId) {
7253 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007254
7255 final long identity = Binder.clearCallingIdentity();
7256 try {
7257 Phone phone = getPhone(subId);
7258 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007259 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007260 }
7261 } finally {
7262 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007263 }
7264 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007265
7266 /**
7267 * Get Client request stats
7268 * @return List of Client Request Stats
7269 * @hide
7270 */
7271 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007272 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7273 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007274 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007275 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007276 return null;
7277 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007278 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007279
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007280 final long identity = Binder.clearCallingIdentity();
7281 try {
7282 if (phone != null) {
7283 return phone.getClientRequestStats();
7284 }
7285
7286 return null;
7287 } finally {
7288 Binder.restoreCallingIdentity(identity);
7289 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007290 }
7291
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007292 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007293 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007294 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007295 }
Jack Yueb4124c2017-02-16 15:32:43 -08007296
7297 /**
Grace Chen70990072017-03-24 17:21:30 -07007298 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007299 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007300 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007301 * @param state State of SIM (power down, power up, pass through)
7302 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7303 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7304 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007305 *
7306 **/
7307 @Override
Grace Chen70990072017-03-24 17:21:30 -07007308 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007309 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007310 Phone phone = PhoneFactory.getPhone(slotIndex);
7311
vagdeviaf9a5b92018-08-15 16:01:53 -07007312 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7313
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007314 final long identity = Binder.clearCallingIdentity();
7315 try {
7316 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007317 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007318 }
7319 } finally {
7320 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007321 }
7322 }
Shuo Qiandd210312017-04-12 22:11:33 +00007323
Tyler Gunn65d45c22017-06-05 11:22:26 -07007324 private boolean isUssdApiAllowed(int subId) {
7325 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007326 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007327 if (configManager == null) {
7328 return false;
7329 }
7330 PersistableBundle pb = configManager.getConfigForSubId(subId);
7331 if (pb == null) {
7332 return false;
7333 }
7334 return pb.getBoolean(
7335 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7336 }
7337
Shuo Qiandd210312017-04-12 22:11:33 +00007338 /**
7339 * Check if phone is in emergency callback mode
7340 * @return true if phone is in emergency callback mode
7341 * @param subId sub id
7342 */
goneil9c5f4872017-12-05 14:07:56 -08007343 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007344 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007345 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007346 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347
7348 final long identity = Binder.clearCallingIdentity();
7349 try {
7350 if (phone != null) {
7351 return phone.isInEcm();
7352 } else {
7353 return false;
7354 }
7355 } finally {
7356 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007357 }
7358 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007359
7360 /**
7361 * Get the current signal strength information for the given subscription.
7362 * Because this information is not updated when the device is in a low power state
7363 * it should not be relied-upon to be current.
7364 * @param subId Subscription index
7365 * @return the most recent cached signal strength info from the modem
7366 */
7367 @Override
7368 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007369 final long identity = Binder.clearCallingIdentity();
7370 try {
7371 Phone p = getPhone(subId);
7372 if (p == null) {
7373 return null;
7374 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007376 return p.getSignalStrength();
7377 } finally {
7378 Binder.restoreCallingIdentity(identity);
7379 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007380 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007381
Pengquan Meng77b7f132018-08-22 14:49:57 -07007382 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007383 * Get the current modem radio state for the given slot.
7384 * @param slotIndex slot index.
7385 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007386 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007387 * @return the current radio power state from the modem
7388 */
7389 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007390 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007391 Phone phone = PhoneFactory.getPhone(slotIndex);
7392 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007393 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7394 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007395 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7396 }
7397
7398 final long identity = Binder.clearCallingIdentity();
7399 try {
7400 return phone.getRadioPowerState();
7401 } finally {
7402 Binder.restoreCallingIdentity(identity);
7403 }
7404 }
7405 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7406 }
7407
7408 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007409 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7410 *
7411 * <p>Requires one of the following permissions:
7412 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7413 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7414 * privileges.
7415 *
7416 * @param subId subscription id
7417 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7418 * {@code false}.
7419 */
7420 @Override
7421 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007422 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7423 null /* message */);
7424
Pengquan Menga1bb6272018-09-06 09:59:22 -07007425 boolean isEnabled = false;
7426 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007427 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007428 Phone phone = getPhone(subId);
7429 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007430 } catch (Exception e) {
7431 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7432 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007433 } finally {
7434 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007435 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007436 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007437 }
7438
7439
7440 /**
7441 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7442 *
7443 * <p> Requires permission:
7444 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7445 * privileges.
7446 *
7447 * @param subId subscription id
7448 * @param isEnabled {@code true} means enable, {@code false} means disable.
7449 */
7450 @Override
7451 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007452 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7453 mApp, subId, "setDataRoamingEnabled");
7454
Pengquan Menga1bb6272018-09-06 09:59:22 -07007455 final long identity = Binder.clearCallingIdentity();
7456 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007457 Phone phone = getPhone(subId);
7458 if (phone != null) {
7459 phone.setDataRoamingEnabled(isEnabled);
7460 }
7461 } finally {
7462 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007463 }
7464 }
7465
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007466 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007467 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007468 TelephonyPermissions
7469 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007470 mApp, subId, "isManualNetworkSelectionAllowed");
7471
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007472 boolean isAllowed = true;
7473 final long identity = Binder.clearCallingIdentity();
7474 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007475 Phone phone = getPhone(subId);
7476 if (phone != null) {
7477 isAllowed = phone.isCspPlmnEnabled();
7478 }
7479 } finally {
7480 Binder.restoreCallingIdentity(identity);
7481 }
7482 return isAllowed;
7483 }
7484
7485 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007486 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007487 // Verify that tha callingPackage belongs to the calling UID
7488 mApp.getSystemService(AppOpsManager.class)
7489 .checkPackage(Binder.getCallingUid(), callingPackage);
7490
Jordan Liu1e142fc2019-04-22 15:10:43 -07007491 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007492 try {
7493 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007494 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007495 } catch (SecurityException e) {
7496 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7497 // has carrier privileges on an active UICC
7498 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7499 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007500 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007501 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007502 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007503
7504 final long identity = Binder.clearCallingIdentity();
7505 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007506 UiccController uiccController = UiccController.getInstance();
7507 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007508 if (hasReadPermission) {
7509 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007510 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007511
7512 // Remove private info if the caller doesn't have access
7513 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7514 for (UiccCardInfo cardInfo : cardInfos) {
7515 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7516 // is available
7517 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7518 if (card == null || card.getUiccProfile() == null) {
7519 // assume no access if the card or profile is unavailable
7520 filteredInfos.add(cardInfo.getUnprivileged());
7521 continue;
7522 }
7523 UiccProfile profile = card.getUiccProfile();
7524 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7525 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7526 filteredInfos.add(cardInfo);
7527 } else {
7528 filteredInfos.add(cardInfo.getUnprivileged());
7529 }
7530 }
7531 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007532 } finally {
7533 Binder.restoreCallingIdentity(identity);
7534 }
7535 }
7536
7537 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007538 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007539 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007540
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007541 final long identity = Binder.clearCallingIdentity();
7542 try {
7543 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7544 if (slots == null) {
7545 Rlog.i(LOG_TAG, "slots is null.");
7546 return null;
7547 }
7548
7549 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7550 for (int i = 0; i < slots.length; i++) {
7551 UiccSlot slot = slots[i];
7552 if (slot == null) {
7553 continue;
7554 }
7555
Jordan Liu7be7e652019-05-06 18:55:02 +00007556 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007557 UiccCard card = slot.getUiccCard();
7558 if (card != null) {
7559 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007560 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007561 cardId = slot.getEid();
7562 if (TextUtils.isEmpty(cardId)) {
7563 cardId = slot.getIccId();
7564 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007565 }
7566
Jordan Liu857451f2019-05-09 16:35:35 -07007567 if (cardId != null) {
7568 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7569 // if cardId is an EID, it's all digits so this is fine
7570 cardId = IccUtils.stripTrailingFs(cardId);
7571 }
7572
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007573 int cardState = 0;
7574 switch (slot.getCardState()) {
7575 case CARDSTATE_ABSENT:
7576 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7577 break;
7578 case CARDSTATE_PRESENT:
7579 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7580 break;
7581 case CARDSTATE_ERROR:
7582 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7583 break;
7584 case CARDSTATE_RESTRICTED:
7585 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7586 break;
7587 default:
7588 break;
7589
7590 }
7591
7592 infos[i] = new UiccSlotInfo(
7593 slot.isActive(),
7594 slot.isEuicc(),
7595 cardId,
7596 cardState,
7597 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007598 slot.isExtendedApduSupported(),
7599 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 }
7601 return infos;
7602 } finally {
7603 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007604 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007605 }
7606
7607 @Override
7608 public boolean switchSlots(int[] physicalSlots) {
7609 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007610
7611 final long identity = Binder.clearCallingIdentity();
7612 try {
7613 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7614 } finally {
7615 Binder.restoreCallingIdentity(identity);
7616 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007617 }
Jack Yu4c988042018-02-27 15:30:01 -08007618
7619 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007620 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007621 final long identity = Binder.clearCallingIdentity();
7622 try {
7623 return UiccController.getInstance().getCardIdForDefaultEuicc();
7624 } finally {
7625 Binder.restoreCallingIdentity(identity);
7626 }
7627 }
7628
Pengquan Meng85728fb2018-03-12 16:31:21 -07007629 /**
goneil47ffb6e2018-04-06 15:40:58 -07007630 * A test API to reload the UICC profile.
7631 *
7632 * <p>Requires that the calling app has permission
7633 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7634 * @hide
7635 */
7636 @Override
7637 public void refreshUiccProfile(int subId) {
7638 enforceModifyPermission();
7639
7640 final long identity = Binder.clearCallingIdentity();
7641 try {
7642 Phone phone = getPhone(subId);
7643 if (phone == null) {
7644 return;
7645 }
7646 UiccCard uiccCard = phone.getUiccCard();
7647 if (uiccCard == null) {
7648 return;
7649 }
7650 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7651 if (uiccProfile == null) {
7652 return;
7653 }
7654 uiccProfile.refresh();
7655 } finally {
7656 Binder.restoreCallingIdentity(identity);
7657 }
7658 }
7659
7660 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007661 * Returns false if the mobile data is disabled by default, otherwise return true.
7662 */
7663 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007664 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007665 }
7666
7667 /**
7668 * Returns true if the data roaming is enabled by default, i.e the system property
7669 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7670 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7671 */
7672 private boolean getDefaultDataRoamingEnabled(int subId) {
7673 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007674 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007675 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007676 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7677 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7678 return isDataRoamingEnabled;
7679 }
7680
7681 /**
7682 * Returns the default network type for the given {@code subId}, if the default network type is
7683 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7684 */
7685 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007686 List<Integer> list = TelephonyProperties.default_network();
7687 int phoneId = mSubscriptionController.getPhoneId(subId);
7688 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7689 return list.get(phoneId);
7690 }
7691 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007692 }
fionaxua13278b2018-03-21 00:08:13 -07007693
7694 @Override
7695 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007696 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007697 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 final Phone phone = getPhone(subId);
7702 if (phone == null) {
7703 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7704 return;
7705 }
chen xueaba88a2019-03-15 13:15:10 -07007706 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7707 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007708 } finally {
7709 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007710 }
fionaxua13278b2018-03-21 00:08:13 -07007711 }
7712
7713 @Override
7714 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007715 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007716
7717 final long identity = Binder.clearCallingIdentity();
7718 try {
7719 final Phone phone = getPhone(subId);
7720 if (phone == null) {
7721 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7722 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7723 }
7724 return phone.getCarrierIdListVersion();
7725 } finally {
7726 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007727 }
fionaxua13278b2018-03-21 00:08:13 -07007728 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007729
7730 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007731 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7732 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007733 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007734 mApp, subId, callingPackage, callingFeatureId,
7735 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007736 return -1;
7737 }
7738
7739 final long identity = Binder.clearCallingIdentity();
7740 try {
7741 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7742 } finally {
7743 Binder.restoreCallingIdentity(identity);
7744 }
7745 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007746
7747 @Override
7748 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007749 TelephonyPermissions
7750 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007751 mApp, subId, "getCdmaRoamingMode");
7752
7753 final long identity = Binder.clearCallingIdentity();
7754 try {
7755 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7756 } finally {
7757 Binder.restoreCallingIdentity(identity);
7758 }
7759 }
7760
7761 @Override
7762 public boolean setCdmaRoamingMode(int subId, int mode) {
7763 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7764 mApp, subId, "setCdmaRoamingMode");
7765
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7769 } finally {
7770 Binder.restoreCallingIdentity(identity);
7771 }
7772 }
7773
7774 @Override
7775 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7776 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7777 mApp, subId, "setCdmaSubscriptionMode");
7778
7779 final long identity = Binder.clearCallingIdentity();
7780 try {
7781 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7782 } finally {
7783 Binder.restoreCallingIdentity(identity);
7784 }
7785 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007786
sqianc5eccab2018-10-19 18:46:41 -07007787 @Override
sqian8c685422019-02-22 15:55:18 -08007788 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007789 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007790 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007791 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7792 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007793 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7794 }
7795 final long identity = Binder.clearCallingIdentity();
7796 try {
sqian854d44b2018-12-12 16:48:18 -08007797 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7798 for (Phone phone: PhoneFactory.getPhones()) {
7799 if (phone.getEmergencyNumberTracker() != null
7800 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7801 emergencyNumberListInternal.put(
7802 phone.getSubId(),
7803 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7804 }
sqian11b7a0e2018-12-05 18:48:28 -08007805 }
sqian854d44b2018-12-12 16:48:18 -08007806 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007807 } finally {
7808 Binder.restoreCallingIdentity(identity);
7809 }
sqianc5eccab2018-10-19 18:46:41 -07007810 }
7811
7812 @Override
sqian8c685422019-02-22 15:55:18 -08007813 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007814 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007815 if (!exactMatch) {
7816 TelephonyPermissions
7817 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007818 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007819 }
7820 final long identity = Binder.clearCallingIdentity();
7821 try {
sqian854d44b2018-12-12 16:48:18 -08007822 for (Phone phone: PhoneFactory.getPhones()) {
7823 if (phone.getEmergencyNumberTracker() != null
7824 && phone.getEmergencyNumberTracker() != null) {
7825 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7826 number, exactMatch)) {
7827 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007828 }
7829 }
sqian11b7a0e2018-12-05 18:48:28 -08007830 }
7831 return false;
7832 } finally {
7833 Binder.restoreCallingIdentity(identity);
7834 }
7835 }
7836
sqianf4ca7ed2019-01-15 18:32:07 -08007837 /**
7838 * Update emergency number list for test mode.
7839 */
7840 @Override
7841 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7842 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7843 "updateEmergencyNumberListTestMode");
7844
7845 final long identity = Binder.clearCallingIdentity();
7846 try {
7847 for (Phone phone: PhoneFactory.getPhones()) {
7848 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7849 if (tracker != null) {
7850 tracker.executeEmergencyNumberTestModeCommand(action, num);
7851 }
7852 }
7853 } finally {
7854 Binder.restoreCallingIdentity(identity);
7855 }
7856 }
7857
7858 /**
7859 * Get the full emergency number list for test mode.
7860 */
7861 @Override
7862 public List<String> getEmergencyNumberListTestMode() {
7863 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7864 "getEmergencyNumberListTestMode");
7865
7866 final long identity = Binder.clearCallingIdentity();
7867 try {
7868 Set<String> emergencyNumbers = new HashSet<>();
7869 for (Phone phone: PhoneFactory.getPhones()) {
7870 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7871 if (tracker != null) {
7872 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7873 emergencyNumbers.add(num.getNumber());
7874 }
7875 }
7876 }
7877 return new ArrayList<>(emergencyNumbers);
7878 } finally {
7879 Binder.restoreCallingIdentity(identity);
7880 }
7881 }
7882
chen xud6b45bd2018-10-30 22:27:10 -07007883 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007884 public int getEmergencyNumberDbVersion(int subId) {
7885 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7886
7887 final long identity = Binder.clearCallingIdentity();
7888 try {
7889 final Phone phone = getPhone(subId);
7890 if (phone == null) {
7891 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7892 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7893 }
7894 return phone.getEmergencyNumberDbVersion();
7895 } finally {
7896 Binder.restoreCallingIdentity(identity);
7897 }
7898 }
7899
7900 @Override
7901 public void notifyOtaEmergencyNumberDbInstalled() {
7902 enforceModifyPermission();
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 for (Phone phone: PhoneFactory.getPhones()) {
7907 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7908 if (tracker != null) {
7909 tracker.updateOtaEmergencyNumberDatabase();
7910 }
7911 }
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
7915 }
7916
7917 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007918 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007919 enforceActiveEmergencySessionPermission();
7920
7921 final long identity = Binder.clearCallingIdentity();
7922 try {
7923 for (Phone phone: PhoneFactory.getPhones()) {
7924 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7925 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007926 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7927 }
7928 }
7929 } finally {
7930 Binder.restoreCallingIdentity(identity);
7931 }
7932 }
7933
7934 @Override
7935 public void resetOtaEmergencyNumberDbFilePath() {
7936 enforceActiveEmergencySessionPermission();
7937
7938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 for (Phone phone: PhoneFactory.getPhones()) {
7941 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7942 if (tracker != null) {
7943 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007944 }
7945 }
7946 } finally {
7947 Binder.restoreCallingIdentity(identity);
7948 }
7949 }
7950
7951 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007952 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7953 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7954 Phone phone = getPhone(subId);
7955 if (phone == null) {
7956 return null;
7957 }
7958 final long identity = Binder.clearCallingIdentity();
7959 try {
7960 UiccProfile profile = UiccController.getInstance()
7961 .getUiccProfileForPhone(phone.getPhoneId());
7962 if (profile != null) {
7963 return profile.getCertsFromCarrierPrivilegeAccessRules();
7964 }
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 return null;
7969 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007970
7971 /**
7972 * Enable or disable a modem stack.
7973 */
7974 @Override
7975 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7976 enforceModifyPermission();
7977
7978 final long identity = Binder.clearCallingIdentity();
7979 try {
7980 Phone phone = PhoneFactory.getPhone(slotIndex);
7981 if (phone == null) {
7982 return false;
7983 } else {
7984 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7985 }
7986 } finally {
7987 Binder.restoreCallingIdentity(identity);
7988 }
7989 }
Michelecea4cf22018-12-21 15:00:11 -08007990
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007991 /**
7992 * Whether a modem stack is enabled or not.
7993 */
7994 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007995 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7996 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007997 Phone phone = PhoneFactory.getPhone(slotIndex);
7998 if (phone == null) return false;
7999
8000 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008001 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8002 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008003 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8004 }
8005
8006 final long identity = Binder.clearCallingIdentity();
8007 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008008 try {
8009 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8010 } catch (NoSuchElementException ex) {
8011 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8012 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008013 } finally {
8014 Binder.restoreCallingIdentity(identity);
8015 }
8016 }
8017
Michelecea4cf22018-12-21 15:00:11 -08008018 @Override
Michele0ea7d782019-03-19 14:58:42 -07008019 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008020 enforceModifyPermission();
8021
8022 final long identity = Binder.clearCallingIdentity();
8023 try {
8024 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008025 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008026 .commit();
8027 } finally {
8028 Binder.restoreCallingIdentity(identity);
8029 }
8030 }
8031
8032 @Override
Michele0ea7d782019-03-19 14:58:42 -07008033 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008034 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008035 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008036 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8037 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008038 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008039 }
Michelecea4cf22018-12-21 15:00:11 -08008040
8041 final long identity = Binder.clearCallingIdentity();
8042 try {
Michele0ea7d782019-03-19 14:58:42 -07008043 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008044 } finally {
8045 Binder.restoreCallingIdentity(identity);
8046 }
8047 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008048
Michele0ea7d782019-03-19 14:58:42 -07008049 @TelephonyManager.IsMultiSimSupportedResult
8050 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008051 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8052 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8053 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008054 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8055 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008056 }
8057 // Check if the hardware supports multisim functionality. If usage of multisim is not
8058 // supported by the modem, indicate that it is restricted.
8059 PhoneCapability staticCapability =
8060 mPhoneConfigurationManager.getStaticPhoneCapability();
8061 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008062 loge("isMultiSimSupportedInternal: no static configuration available");
8063 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008064 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008065 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008066 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8067 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008068 }
8069 // Check if support of multiple SIMs is restricted by carrier
8070 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008071 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008072 }
8073
Michele0ea7d782019-03-19 14:58:42 -07008074 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008075 }
8076
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008077 /**
8078 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008079 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8080 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8081 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008082 * @param numOfSims number of active sims we want to switch to
8083 */
8084 @Override
8085 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008086 if (numOfSims == 1) {
8087 enforceModifyPermission();
8088 } else {
8089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8090 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8091 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008092 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008093
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008094 try {
Michele30b57b22019-03-01 12:01:14 -08008095 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008096 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008097 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8098 return;
8099 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008100 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8101 } finally {
8102 Binder.restoreCallingIdentity(identity);
8103 }
8104 }
8105
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008106 @Override
8107 public boolean isApplicationOnUicc(int subId, int appType) {
8108 enforceReadPrivilegedPermission("isApplicationOnUicc");
8109 Phone phone = getPhone(subId);
8110 if (phone == null) {
8111 return false;
8112 }
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
8115 UiccCard uiccCard = phone.getUiccCard();
8116 if (uiccCard == null) {
8117 return false;
8118 }
8119 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8120 if (uiccProfile == null) {
8121 return false;
8122 }
8123 if (TelephonyManager.APPTYPE_SIM <= appType
8124 && appType <= TelephonyManager.APPTYPE_ISIM) {
8125 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8126 }
8127 return false;
8128 } finally {
8129 Binder.restoreCallingIdentity(identity);
8130 }
8131 }
8132
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008133 /**
chen xub4baa772019-04-03 10:23:41 -07008134 * Get whether making changes to modem configurations will trigger reboot.
8135 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008136 */
8137 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008138 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8139 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008140 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008141 mApp, subId, callingPackage, callingFeatureId,
8142 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008143 return false;
8144 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008145 final long identity = Binder.clearCallingIdentity();
8146 try {
8147 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8148 } finally {
8149 Binder.restoreCallingIdentity(identity);
8150 }
8151 }
8152
Nathan Harold29f5f052019-02-15 13:41:57 -08008153 private void updateModemStateMetrics() {
8154 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8155 // TODO: check the state for each modem if the api is ready.
8156 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8157 }
8158
Pengquan Meng3889a572019-01-23 11:16:29 -08008159 @Override
8160 public int[] getSlotsMapping() {
8161 enforceReadPrivilegedPermission("getSlotsMapping");
8162
8163 final long identity = Binder.clearCallingIdentity();
8164 try {
8165 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8166 // All logical slots should have a mapping to a physical slot.
8167 int[] logicalSlotsMapping = new int[phoneCount];
8168 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8169 for (int i = 0; i < slotInfos.length; i++) {
8170 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8171 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8172 }
8173 }
8174 return logicalSlotsMapping;
8175 } finally {
8176 Binder.restoreCallingIdentity(identity);
8177 }
8178 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008179
8180 /**
8181 * Get the IRadio HAL Version
8182 */
8183 @Override
8184 public int getRadioHalVersion() {
8185 Phone phone = getDefaultPhone();
8186 if (phone == null) return -1;
8187 HalVersion hv = phone.getHalVersion();
8188 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8189 return hv.major * 100 + hv.minor;
8190 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008191
8192 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008193 * Get the current calling package name.
8194 * @return the current calling package name
8195 */
8196 @Override
8197 public String getCurrentPackageName() {
8198 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8199 }
8200
8201 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008202 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8203 * corresponding network requests on a subId.
8204 *
8205 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008206 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008207 * 2) APN is un-metered for this subscription, or
8208 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008209 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008210 *
8211 * @return whether data is allowed for a apn type.
8212 *
8213 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008214 */
8215 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008216 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008217 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8218 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008219
8220 // Now that all security checks passes, perform the operation as ourselves.
8221 final long identity = Binder.clearCallingIdentity();
8222 try {
8223 Phone phone = getPhone(subId);
8224 if (phone == null) return false;
8225
Jack Yu41407ee2019-05-13 16:54:09 -07008226 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008227 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8228 } finally {
8229 Binder.restoreCallingIdentity(identity);
8230 }
8231 }
8232
8233 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008234 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008235 enforceReadPrivilegedPermission("isApnMetered");
8236
8237 // Now that all security checks passes, perform the operation as ourselves.
8238 final long identity = Binder.clearCallingIdentity();
8239 try {
8240 Phone phone = getPhone(subId);
8241 if (phone == null) return true; // By default return true.
8242
Jack Yu41407ee2019-05-13 16:54:09 -07008243 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008244 } finally {
8245 Binder.restoreCallingIdentity(identity);
8246 }
8247 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008248
8249 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008250 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8251 int subscriptionId, IBooleanConsumer resultCallback) {
8252 enforceModifyPermission();
8253 long token = Binder.clearCallingIdentity();
8254 try {
8255 Phone phone = getPhone(subscriptionId);
8256 if (phone == null) {
8257 try {
8258 if (resultCallback != null) {
8259 resultCallback.accept(false);
8260 }
8261 } catch (RemoteException e) {
8262 // ignore
8263 }
8264 return;
8265 }
8266 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8267 Pair.create(specifiers, (x) -> {
8268 try {
8269 if (resultCallback != null) {
8270 resultCallback.accept(x);
8271 }
8272 } catch (RemoteException e) {
8273 // ignore
8274 }
8275 });
8276 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8277 } finally {
8278 Binder.restoreCallingIdentity(token);
8279 }
8280 }
8281
8282 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008283 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
8284 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8285 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8286 if (iccRecords == null) {
8287 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8288 return false;
8289 }
8290 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8291 }
8292
8293 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008294 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8295 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008296 if (callingPackage == null) {
8297 callingPackage = getCurrentPackageName();
8298 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008299 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8300 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008301 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8302 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008303 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8304 }
8305 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8306 Intent intent = new Intent();
8307 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8308 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8309 // Bring up choose default SMS subscription dialog right now
8310 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8311 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8312 mApp.startActivity(intent);
8313 }
chen xud5ca2d52019-05-28 15:20:57 -07008314
8315 @Override
8316 public String getMmsUAProfUrl(int subId) {
8317 //TODO investigate if this API should require proper permission check in R b/133791609
8318 final long identity = Binder.clearCallingIdentity();
8319 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008320 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8321 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8322 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8323 return carrierUAProfUrl;
8324 }
chen xud5ca2d52019-05-28 15:20:57 -07008325 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8326 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8327 } finally {
8328 Binder.restoreCallingIdentity(identity);
8329 }
8330 }
8331
8332 @Override
8333 public String getMmsUserAgent(int subId) {
8334 //TODO investigate if this API should require proper permission check in R b/133791609
8335 final long identity = Binder.clearCallingIdentity();
8336 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008337 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8338 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8339 if (!TextUtils.isEmpty(carrierUserAgent)) {
8340 return carrierUserAgent;
8341 }
chen xud5ca2d52019-05-28 15:20:57 -07008342 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8343 .getString(com.android.internal.R.string.config_mms_user_agent);
8344 } finally {
8345 Binder.restoreCallingIdentity(identity);
8346 }
8347 }
Jack Yub07d4972019-05-28 16:12:25 -07008348
8349 @Override
8350 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8351 enforceModifyPermission();
8352
8353 // Now that all security checks passes, perform the operation as ourselves.
8354 final long identity = Binder.clearCallingIdentity();
8355 try {
8356 Phone phone = getPhone(subId);
8357 if (phone == null) return false;
8358
8359 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8360 } finally {
8361 Binder.restoreCallingIdentity(identity);
8362 }
8363 }
8364
8365 @Override
8366 public boolean isDataAllowedInVoiceCall(int subId) {
8367 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8368
8369 // Now that all security checks passes, perform the operation as ourselves.
8370 final long identity = Binder.clearCallingIdentity();
8371 try {
8372 Phone phone = getPhone(subId);
8373 if (phone == null) return false;
8374
8375 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8376 } finally {
8377 Binder.restoreCallingIdentity(identity);
8378 }
8379 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008380
changbetty97defcf2019-12-24 15:40:37 +08008381 @Override
8382 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8383 enforceModifyPermission();
8384
8385 // Now that all security checks passes, perform the operation as ourselves.
8386 final long identity = Binder.clearCallingIdentity();
8387 try {
8388 Phone phone = getPhone(subId);
8389 if (phone == null) return false;
8390
8391 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8392 } finally {
8393 Binder.restoreCallingIdentity(identity);
8394 }
8395 }
8396
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008397 /**
8398 * Updates whether conference event pacakge handling is enabled.
8399 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8400 * otherwise.
8401 */
8402 @Override
8403 public void setCepEnabled(boolean isCepEnabled) {
8404 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8405
8406 final long identity = Binder.clearCallingIdentity();
8407 try {
8408 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8409 for (Phone phone : PhoneFactory.getPhones()) {
8410 Phone defaultPhone = phone.getImsPhone();
8411 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8412 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8413 ImsPhoneCallTracker imsPhoneCallTracker =
8414 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8415 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8416 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8417 + imsPhone.getMsisdn());
8418 }
8419 }
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
allenwtsu46dcc572020-01-08 18:24:03 +08008424
8425 /**
8426 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8427 *
8428 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8429 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8430 * before being read.
8431 */
8432 @Override
8433 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8434 isCompressed) {
8435 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8436 mApp, subId, "notifyRcsAutoConfigurationReceived");
8437 try {
8438 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8439 if (configBinder == null) {
8440 Rlog.e(LOG_TAG, "null result for getImsConfig");
8441 } else {
8442 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8443 }
8444 } catch (RemoteException e) {
8445 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8446 }
8447 }
zoey chenf95ca592019-12-30 16:11:23 +08008448
8449 @Override
8450 public boolean isIccLockEnabled(int subId) {
8451 enforceReadPrivilegedPermission("isIccLockEnabled");
8452
8453 // Now that all security checks passes, perform the operation as ourselves.
8454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 Phone phone = getPhone(subId);
8457 if (phone != null && phone.getIccCard() != null) {
8458 return phone.getIccCard().getIccLockEnabled();
8459 } else {
8460 return false;
8461 }
8462 } finally {
8463 Binder.restoreCallingIdentity(identity);
8464 }
8465 }
8466
8467 /**
8468 * Set the ICC pin lock enabled or disabled..
8469 *
8470 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8471 * 0 or a positive integer as the attempts remaining value.
8472 *
8473 */
8474 @Override
8475 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8476 enforceModifyPermission();
8477
8478 Phone phone = getPhone(subId);
8479 if (phone == null) {
8480 return 0;
8481 }
8482 // Now that all security checks passes, perform the operation as ourselves.
8483 final long identity = Binder.clearCallingIdentity();
8484 try {
8485 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8486 new Pair<Boolean, String>(enabled, password), phone, null);
8487 return attemptsRemaining;
8488
8489 } catch (Exception e) {
8490 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8491 } finally {
8492 Binder.restoreCallingIdentity(identity);
8493 }
8494 return 0;
8495 }
8496
8497 /**
8498 * Change the ICC password used in ICC pin lock.
8499 *
8500 * @return Integer.MAX_VALUE if enable/disable IccLock successfully. If failed it will return
8501 * 0 or a positive integer as the attempts remaining value.
8502 *
8503 */
8504 @Override
8505 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8506 enforceModifyPermission();
8507
8508 Phone phone = getPhone(subId);
8509 if (phone == null) {
8510 return 0;
8511 }
8512 // Now that all security checks passes, perform the operation as ourselves.
8513 final long identity = Binder.clearCallingIdentity();
8514 try {
8515 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8516 new Pair<String, String>(oldPassword, newPassword), phone, null);
8517 return attemptsRemaining;
8518
8519 } catch (Exception e) {
8520 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8521 } finally {
8522 Binder.restoreCallingIdentity(identity);
8523 }
8524 return 0;
8525 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008526
8527 @Override
8528 public boolean canConnectTo5GInDsdsMode() {
8529 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8530 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008531}