blob: 9ddbe479530248b6abf68c34ba0c868f0bc78bd4 [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;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700108import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebinger77b832e2019-10-17 17:03:22 -0700109import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800110import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800111import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800113import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700114import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800115import android.util.ArraySet;
Hall Liuaa4283b2020-05-21 17:09:35 -0700116import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700117import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800118import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800119
Andrew Lee312e8172014-10-23 17:01:36 -0700120import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800121import com.android.ims.internal.IImsServiceFeatureCallback;
sqian80370722020-01-29 15:02:51 -0800122import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700123import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700124import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700125import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800126import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700127import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700128import com.android.internal.telephony.CommandException;
sqian80370722020-01-29 15:02:51 -0800129import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700130import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800131import com.android.internal.telephony.HalVersion;
Hall Liud0d1dc92020-01-20 13:42:00 -0800132import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700133import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800134import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700135import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800136import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700137import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700138import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700139import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700141import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800142import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700143import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700144import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700145import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700146import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700147import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700148import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700149import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700150import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800151import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800152import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800153import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700154import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800155import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700156import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800157import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700158import com.android.internal.telephony.imsphone.ImsPhone;
159import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800160import com.android.internal.telephony.metrics.TelephonyMetrics;
Taesu Leef8fbed92019-10-07 18:47:02 +0900161import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700162import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-12-06 18:16:37 +0800163import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800165import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700166import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700168import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800169import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000170import com.android.internal.telephony.uicc.UiccSlot;
zoey chen84e2b212019-12-18 17:07:20 +0800171import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700172import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800173import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700174import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700175import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800176import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700178import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang050bb052020-01-13 23:33:09 -0800179import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800180
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700181import java.io.FileDescriptor;
182import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700183import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800184import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800185import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800186import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800187import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100188import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700190import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800192import java.util.concurrent.atomic.AtomicBoolean;
Hall Liud0d1dc92020-01-20 13:42:00 -0800193import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700194
195/**
196 * Implementation of the ITelephony interface.
197 */
Santos Cordon117fee72014-05-16 17:56:12 -0700198public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199 private static final String LOG_TAG = "PhoneInterfaceManager";
200 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
201 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800202 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700203
204 // Message codes used with mMainThreadHandler
205 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700206 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
207 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700208 private static final int CMD_OPEN_CHANNEL = 9;
209 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
210 private static final int CMD_CLOSE_CHANNEL = 11;
211 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800212 private static final int CMD_NV_READ_ITEM = 13;
213 private static final int EVENT_NV_READ_ITEM_DONE = 14;
214 private static final int CMD_NV_WRITE_ITEM = 15;
215 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
216 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
217 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700218 private static final int CMD_RESET_MODEM_CONFIG = 19;
219 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800220 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
221 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
222 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
223 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800224 private static final int CMD_SEND_ENVELOPE = 25;
225 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000226 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
227 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700228 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
229 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
230 private static final int CMD_EXCHANGE_SIM_IO = 31;
231 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800232 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
233 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700234 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
235 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700236 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
237 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700238 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
239 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
240 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
241 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700242 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
243 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
244 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
245 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700246 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800247 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
248 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000249 private static final int CMD_SWITCH_SLOTS = 50;
250 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700251 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
252 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
253 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
254 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
255 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
256 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
257 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
258 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700259 private static final int CMD_GET_ALL_CELL_INFO = 60;
260 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
261 private static final int CMD_GET_CELL_LOCATION = 62;
262 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700263 private static final int CMD_MODEM_REBOOT = 64;
264 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700265 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
266 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800267 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
268 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700269 private static final int CMD_GET_MODEM_STATUS = 70;
270 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhaod698b842019-09-06 17:06:54 -0700271 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
272 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700273 private static final int CMD_ERASE_MODEM_CONFIG = 74;
274 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chenf95ca592019-12-30 16:11:23 +0800275 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
276 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
277 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
278 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liud0d1dc92020-01-20 13:42:00 -0800279 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
280 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800281 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
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
Peter Wangdafb9ac2020-01-15 14:13:38 -0800310 /** User Activity */
311 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
313
Derek Tan97ebb422014-09-05 16:55:38 -0700314 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
315 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800316 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800317 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700318
Michelecea4cf22018-12-21 15:00:11 -0800319 // String to store multi SIM allowed
320 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
321
Derek Tan740e1672017-06-27 14:56:27 -0700322 // The AID of ISD-R.
323 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
324
yinxub1bed742017-04-17 11:45:04 -0700325 private NetworkScanRequestTracker mNetworkScanRequestTracker;
326
David Kelly5e06a7f2018-03-12 14:10:59 +0000327 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
328 private static final int MANUFACTURER_CODE_LENGTH = 8;
329
Derek Tan89e89d42014-07-08 17:00:10 -0700330 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700331 * Experiment flag to enable erase modem config on reset network, default value is false
332 */
333 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
334 "reset_network_erase_modem_config_enabled";
335
336 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700337 * A request object to use for transmitting data to an ICC.
338 */
339 private static final class IccAPDUArgument {
340 public int channel, cla, command, p1, p2, p3;
341 public String data;
342
343 public IccAPDUArgument(int channel, int cla, int command,
344 int p1, int p2, int p3, String data) {
345 this.channel = channel;
346 this.cla = cla;
347 this.command = command;
348 this.p1 = p1;
349 this.p2 = p2;
350 this.p3 = p3;
351 this.data = data;
352 }
353 }
354
355 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700356 * A request object to use for transmitting data to an ICC.
357 */
358 private static final class ManualNetworkSelectionArgument {
359 public OperatorInfo operatorInfo;
360 public boolean persistSelection;
361
362 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
363 this.operatorInfo = operatorInfo;
364 this.persistSelection = persistSelection;
365 }
366 }
367
368 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700369 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
370 * request after sending. The main thread will notify the request when it is complete.
371 */
372 private static final class MainThreadRequest {
373 /** The argument to use for the request */
374 public Object argument;
375 /** The result of the request that is run on the main thread */
376 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800377 // The subscriber id that this request applies to. Defaults to
378 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
379 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700380
Nathan Harold92bed182018-10-12 18:16:49 -0700381 // In cases where subId is unavailable, the caller needs to specify the phone.
382 public Phone phone;
383
vagdeviaf9a5b92018-08-15 16:01:53 -0700384 public WorkSource workSource;
385
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700386 public MainThreadRequest(Object argument) {
387 this.argument = argument;
388 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800389
Nathan Harold92bed182018-10-12 18:16:49 -0700390 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
391 this.argument = argument;
392 if (phone != null) {
393 this.phone = phone;
394 }
395 this.workSource = workSource;
396 }
397
vagdeviaf9a5b92018-08-15 16:01:53 -0700398 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800399 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800400 if (subId != null) {
401 this.subId = subId;
402 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700403 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800404 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700405 }
406
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800407 private static final class IncomingThirdPartyCallArgs {
408 public final ComponentName component;
409 public final String callId;
410 public final String callerDisplayName;
411
412 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
413 String callerDisplayName) {
414 this.component = component;
415 this.callId = callId;
416 this.callerDisplayName = callerDisplayName;
417 }
418 }
419
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700420 /**
421 * A handler that processes messages on the main thread in the phone process. Since many
422 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
423 * inbound binder threads to the main thread in the phone process. The Binder thread
424 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
425 * on, which will be notified when the operation completes and will contain the result of the
426 * request.
427 *
428 * <p>If a MainThreadRequest object is provided in the msg.obj field,
429 * note that request.result must be set to something non-null for the calling thread to
430 * unblock.
431 */
432 private final class MainThreadHandler extends Handler {
433 @Override
434 public void handleMessage(Message msg) {
435 MainThreadRequest request;
436 Message onCompleted;
437 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800438 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700439 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800440 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700441
442 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700443 case CMD_HANDLE_USSD_REQUEST: {
444 request = (MainThreadRequest) msg.obj;
445 final Phone phone = getPhoneFromRequest(request);
446 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
447 String ussdRequest = ussdObject.first;
448 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700449
Pengquan Menga1bb6272018-09-06 09:59:22 -0700450 if (!isUssdApiAllowed(request.subId)) {
451 // Carrier does not support use of this API, return failure.
452 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
453 UssdResponse response = new UssdResponse(ussdRequest, null);
454 Bundle returnData = new Bundle();
455 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
456 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700457
Pengquan Menga1bb6272018-09-06 09:59:22 -0700458 request.result = true;
459 notifyRequester(request);
460 return;
461 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700462
Pengquan Menga1bb6272018-09-06 09:59:22 -0700463 try {
464 request.result = phone != null
465 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
466 } catch (CallStateException cse) {
467 request.result = false;
468 }
469 // Wake up the requesting thread
470 notifyRequester(request);
471 break;
pkanwar32d516d2016-10-14 19:37:38 -0700472 }
473
Yorke Lee716f67e2015-06-17 15:39:16 -0700474 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700475 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 final Phone phone = getPhoneFromRequest(request);
477 request.result = phone != null ?
478 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
479 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700481 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700483 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700485 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700486 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800488 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700489 if (uiccCard == null) {
490 loge("iccTransmitApduLogicalChannel: No UICC");
491 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700492 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700494 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
495 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700496 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700497 iccArgument.channel, iccArgument.cla, iccArgument.command,
498 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700499 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 break;
502
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700503 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 ar = (AsyncResult) msg.obj;
505 request = (MainThreadRequest) ar.userObj;
506 if (ar.exception == null && ar.result != null) {
507 request.result = ar.result;
508 } else {
509 request.result = new IccIoResult(0x6F, 0, (byte[])null);
510 if (ar.result == null) {
511 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800512 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700513 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800514 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 } else {
516 loge("iccTransmitApduLogicalChannel: Unknown exception");
517 }
518 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700519 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700520 break;
521
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700522 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
523 request = (MainThreadRequest) msg.obj;
524 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800525 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 if (uiccCard == null) {
527 loge("iccTransmitApduBasicChannel: No UICC");
528 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700529 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 } else {
531 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
532 request);
533 uiccCard.iccTransmitApduBasicChannel(
534 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
535 iccArgument.p3, iccArgument.data, onCompleted);
536 }
537 break;
538
539 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
540 ar = (AsyncResult) msg.obj;
541 request = (MainThreadRequest) ar.userObj;
542 if (ar.exception == null && ar.result != null) {
543 request.result = ar.result;
544 } else {
545 request.result = new IccIoResult(0x6F, 0, (byte[])null);
546 if (ar.result == null) {
547 loge("iccTransmitApduBasicChannel: Empty response");
548 } else if (ar.exception instanceof CommandException) {
549 loge("iccTransmitApduBasicChannel: CommandException: " +
550 ar.exception);
551 } else {
552 loge("iccTransmitApduBasicChannel: Unknown exception");
553 }
554 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700555 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700556 break;
557
558 case CMD_EXCHANGE_SIM_IO:
559 request = (MainThreadRequest) msg.obj;
560 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800561 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700562 if (uiccCard == null) {
563 loge("iccExchangeSimIO: No UICC");
564 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700565 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 } else {
567 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
568 request);
569 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
570 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
571 iccArgument.data, onCompleted);
572 }
573 break;
574
575 case EVENT_EXCHANGE_SIM_IO_DONE:
576 ar = (AsyncResult) msg.obj;
577 request = (MainThreadRequest) ar.userObj;
578 if (ar.exception == null && ar.result != null) {
579 request.result = ar.result;
580 } else {
581 request.result = new IccIoResult(0x6f, 0, (byte[])null);
582 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700583 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700584 break;
585
Derek Tan4d5e5c12014-02-04 11:54:58 -0800586 case CMD_SEND_ENVELOPE:
587 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800588 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700589 if (uiccCard == null) {
590 loge("sendEnvelopeWithStatus: No UICC");
591 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700592 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 } else {
594 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
595 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
596 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800597 break;
598
599 case EVENT_SEND_ENVELOPE_DONE:
600 ar = (AsyncResult) msg.obj;
601 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700602 if (ar.exception == null && ar.result != null) {
603 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800604 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700605 request.result = new IccIoResult(0x6F, 0, (byte[])null);
606 if (ar.result == null) {
607 loge("sendEnvelopeWithStatus: Empty response");
608 } else if (ar.exception instanceof CommandException) {
609 loge("sendEnvelopeWithStatus: CommandException: " +
610 ar.exception);
611 } else {
612 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
613 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800614 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700615 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 break;
617
Shishir Agrawal566b7612013-10-28 14:41:00 -0700618 case CMD_OPEN_CHANNEL:
619 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800620 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800621 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700622 if (uiccCard == null) {
623 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800624 request.result = new IccOpenLogicalChannelResponse(-1,
625 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700626 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 } else {
628 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800629 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
630 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700632 break;
633
634 case EVENT_OPEN_CHANNEL_DONE:
635 ar = (AsyncResult) msg.obj;
636 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700637 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700638 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 int[] result = (int[]) ar.result;
640 int channelId = result[0];
641 byte[] selectResponse = null;
642 if (result.length > 1) {
643 selectResponse = new byte[result.length - 1];
644 for (int i = 1; i < result.length; ++i) {
645 selectResponse[i - 1] = (byte) result[i];
646 }
647 }
648 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700649 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700650 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700651 if (ar.result == null) {
652 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700654 if (ar.exception != null) {
655 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
656 }
657
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700658 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700659 if (ar.exception instanceof CommandException) {
660 CommandException.Error error =
661 ((CommandException) (ar.exception)).getCommandError();
662 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700663 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700664 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700666 }
667 }
668 openChannelResp = new IccOpenLogicalChannelResponse(
669 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700670 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700671 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700672 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700673 break;
674
675 case CMD_CLOSE_CHANNEL:
676 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800677 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700678 if (uiccCard == null) {
679 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900680 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700681 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 } else {
683 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
684 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
685 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700686 break;
687
688 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800689 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
690 break;
691
692 case CMD_NV_READ_ITEM:
693 request = (MainThreadRequest) msg.obj;
694 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800695 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
696 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800697 break;
698
699 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700700 ar = (AsyncResult) msg.obj;
701 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800702 if (ar.exception == null && ar.result != null) {
703 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800705 request.result = "";
706 if (ar.result == null) {
707 loge("nvReadItem: Empty response");
708 } else if (ar.exception instanceof CommandException) {
709 loge("nvReadItem: CommandException: " +
710 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700711 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800712 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 }
714 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700715 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 break;
717
Jake Hambye994d462014-02-03 13:10:13 -0800718 case CMD_NV_WRITE_ITEM:
719 request = (MainThreadRequest) msg.obj;
720 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
721 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800722 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700723 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800724 break;
725
726 case EVENT_NV_WRITE_ITEM_DONE:
727 handleNullReturnEvent(msg, "nvWriteItem");
728 break;
729
730 case CMD_NV_WRITE_CDMA_PRL:
731 request = (MainThreadRequest) msg.obj;
732 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800733 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800734 break;
735
736 case EVENT_NV_WRITE_CDMA_PRL_DONE:
737 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
738 break;
739
chen xu6dac5ab2018-10-26 17:39:23 -0700740 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800741 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700742 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800743 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800744 break;
745
chen xu6dac5ab2018-10-26 17:39:23 -0700746 case EVENT_RESET_MODEM_CONFIG_DONE:
747 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
Jake Hamby7c27be32014-03-03 13:25:59 -0800750 case CMD_GET_PREFERRED_NETWORK_TYPE:
751 request = (MainThreadRequest) msg.obj;
752 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700753 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 break;
755
756 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
757 ar = (AsyncResult) msg.obj;
758 request = (MainThreadRequest) ar.userObj;
759 if (ar.exception == null && ar.result != null) {
760 request.result = ar.result; // Integer
761 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530762 // request.result must be set to something non-null
763 // for the calling thread to unblock
764 request.result = new int[]{-1};
Jake Hamby7c27be32014-03-03 13:25:59 -0800765 if (ar.result == null) {
766 loge("getPreferredNetworkType: Empty response");
767 } else if (ar.exception instanceof CommandException) {
768 loge("getPreferredNetworkType: CommandException: " +
769 ar.exception);
770 } else {
771 loge("getPreferredNetworkType: Unknown exception");
772 }
773 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700774 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800775 break;
776
777 case CMD_SET_PREFERRED_NETWORK_TYPE:
778 request = (MainThreadRequest) msg.obj;
779 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
780 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700781 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800782 break;
783
784 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
785 handleNullReturnEvent(msg, "setPreferredNetworkType");
786 break;
787
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000788 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
789 request = (MainThreadRequest)msg.obj;
790 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800791 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000792 break;
793
794 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
795 ar = (AsyncResult)msg.obj;
796 request = (MainThreadRequest)ar.userObj;
797 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700798 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000799 break;
800
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800801 case CMD_SET_VOICEMAIL_NUMBER:
802 request = (MainThreadRequest) msg.obj;
803 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
804 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800805 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
806 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800807 break;
808
809 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
810 handleNullReturnEvent(msg, "setVoicemailNumber");
811 break;
812
Stuart Scott54788802015-03-30 13:18:01 -0700813 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
814 request = (MainThreadRequest) msg.obj;
815 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
816 request);
817 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
818 break;
819
820 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
821 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
822 break;
823
Shishir Agrawal302c8692015-06-19 13:49:39 -0700824 case CMD_PERFORM_NETWORK_SCAN:
825 request = (MainThreadRequest) msg.obj;
826 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
827 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
828 break;
829
sqian80370722020-01-29 15:02:51 -0800830 case CMD_GET_CALL_FORWARDING:
831 request = (MainThreadRequest) msg.obj;
832 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
833 int callForwardingReason = (Integer) request.argument;
834 getPhoneFromRequest(request).getCallForwardingOption(
835 callForwardingReason, onCompleted);
836 break;
837
838 case EVENT_GET_CALL_FORWARDING_DONE:
839 ar = (AsyncResult) msg.obj;
840 request = (MainThreadRequest) ar.userObj;
841 CallForwardingInfo callForwardingInfo = null;
842 if (ar.exception == null && ar.result != null) {
843 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
844 for (CallForwardInfo callForwardInfo : callForwardInfos) {
845 // Service Class is a bit mask per 3gpp 27.007. Search for
846 // any service for voice call.
847 if ((callForwardInfo.serviceClass
848 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
849 callForwardingInfo = new CallForwardingInfo(
850 callForwardInfo.serviceClass, callForwardInfo.reason,
851 callForwardInfo.number,
852 callForwardInfo.timeSeconds);
853 break;
854 }
855 }
856 // Didn't find a call forward info for voice call.
857 if (callForwardingInfo == null) {
858 callForwardingInfo = new CallForwardingInfo(
859 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
860 0 /* reason */, null /* number */, 0 /* timeout */);
861 }
862 } else {
863 if (ar.result == null) {
864 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
865 }
866 if (ar.exception != null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
868 }
869 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
870 if (ar.exception instanceof CommandException) {
871 CommandException.Error error =
872 ((CommandException) (ar.exception)).getCommandError();
873 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
874 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
875 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
876 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
877 }
878 }
879 callForwardingInfo = new CallForwardingInfo(
880 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
881 }
882 request.result = callForwardingInfo;
883 notifyRequester(request);
884 break;
885
886 case CMD_SET_CALL_FORWARDING:
887 request = (MainThreadRequest) msg.obj;
888 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
889 CallForwardingInfo callForwardingInfoToSet =
890 (CallForwardingInfo) request.argument;
891 getPhoneFromRequest(request).setCallForwardingOption(
892 callForwardingInfoToSet.getStatus(),
893 callForwardingInfoToSet.getReason(),
894 callForwardingInfoToSet.getNumber(),
895 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
896 break;
897
898 case EVENT_SET_CALL_FORWARDING_DONE:
899 ar = (AsyncResult) msg.obj;
900 request = (MainThreadRequest) ar.userObj;
901 if (ar.exception == null) {
902 request.result = true;
903 } else {
904 request.result = false;
905 loge("setCallForwarding exception: " + ar.exception);
906 }
907 notifyRequester(request);
908 break;
909
910 case CMD_GET_CALL_WAITING:
911 request = (MainThreadRequest) msg.obj;
912 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
913 getPhoneFromRequest(request).getCallWaiting(onCompleted);
914 break;
915
916 case EVENT_GET_CALL_WAITING_DONE:
917 ar = (AsyncResult) msg.obj;
918 request = (MainThreadRequest) ar.userObj;
919 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
920 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800921 int[] callForwardResults = (int[]) ar.result;
sqian80370722020-01-29 15:02:51 -0800922 // Service Class is a bit mask per 3gpp 27.007.
923 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 if (callForwardResults.length > 1
925 && ((callForwardResults[1]
926 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
927 callForwardingStatus = callForwardResults[0] == 0
sqian80370722020-01-29 15:02:51 -0800928 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
929 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
930 } else {
931 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
932 }
933 } else {
934 if (ar.result == null) {
935 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
936 }
937 if (ar.exception != null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
939 }
940 if (ar.exception instanceof CommandException) {
941 CommandException.Error error =
942 ((CommandException) (ar.exception)).getCommandError();
943 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
944 callForwardingStatus =
945 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
946 }
947 }
948 }
949 request.result = callForwardingStatus;
950 notifyRequester(request);
951 break;
952
953 case CMD_SET_CALL_WAITING:
954 request = (MainThreadRequest) msg.obj;
955 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
956 boolean isEnable = (Boolean) request.argument;
957 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
958 break;
959
960 case EVENT_SET_CALL_WAITING_DONE:
961 ar = (AsyncResult) msg.obj;
962 request = (MainThreadRequest) ar.userObj;
963 if (ar.exception == null) {
964 request.result = true;
965 } else {
966 request.result = false;
967 loge("setCallWaiting exception: " + ar.exception);
968 }
969 notifyRequester(request);
970 break;
971
Shishir Agrawal302c8692015-06-19 13:49:39 -0700972 case EVENT_PERFORM_NETWORK_SCAN_DONE:
973 ar = (AsyncResult) msg.obj;
974 request = (MainThreadRequest) ar.userObj;
975 CellNetworkScanResult cellScanResult;
976 if (ar.exception == null && ar.result != null) {
977 cellScanResult = new CellNetworkScanResult(
978 CellNetworkScanResult.STATUS_SUCCESS,
979 (List<OperatorInfo>) ar.result);
980 } else {
981 if (ar.result == null) {
982 loge("getCellNetworkScanResults: Empty response");
983 }
984 if (ar.exception != null) {
985 loge("getCellNetworkScanResults: Exception: " + ar.exception);
986 }
987 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
988 if (ar.exception instanceof CommandException) {
989 CommandException.Error error =
990 ((CommandException) (ar.exception)).getCommandError();
991 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
992 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
993 } else if (error == CommandException.Error.GENERIC_FAILURE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
995 }
996 }
997 cellScanResult = new CellNetworkScanResult(errorCode, null);
998 }
999 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001000 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001001 break;
1002
1003 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1004 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001005 ManualNetworkSelectionArgument selArg =
1006 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001007 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1008 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001009 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1010 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001011 break;
1012
1013 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001014 ar = (AsyncResult) msg.obj;
1015 request = (MainThreadRequest) ar.userObj;
1016 if (ar.exception == null) {
1017 request.result = true;
1018 } else {
1019 request.result = false;
1020 loge("setNetworkSelectionModeManual " + ar.exception);
1021 }
1022 notifyRequester(request);
1023 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001024 break;
1025
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001026 case CMD_GET_MODEM_ACTIVITY_INFO:
1027 request = (MainThreadRequest) msg.obj;
1028 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001029 if (defaultPhone != null) {
1030 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
sqian1a1be542020-03-05 11:37:28 -08001031 } else {
1032 ResultReceiver result = (ResultReceiver) request.argument;
1033 Bundle bundle = new Bundle();
1034 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1035 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1036 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001037 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001038 break;
1039
1040 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1041 ar = (AsyncResult) msg.obj;
1042 request = (MainThreadRequest) ar.userObj;
sqian1a1be542020-03-05 11:37:28 -08001043 ResultReceiver result = (ResultReceiver) request.argument;
1044
1045 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001046 if (ar.exception == null && ar.result != null) {
sqian1a1be542020-03-05 11:37:28 -08001047 // Update the last modem activity info and the result of the request.
1048 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1049 if (isModemActivityInfoValid(info)) {
1050 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1051 int[] txTimeMs = info.getTransmitTimeMillis();
1052 int[] lastModemTxTimeMs = mLastModemActivityInfo
1053 .getTransmitTimeMillis();
1054 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1055 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1056 }
1057 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1058 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1059 + mLastModemActivityInfo.getSleepTimeMillis());
1060 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1061 + mLastModemActivityInfo.getIdleTimeMillis());
1062 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1063 mLastModemActivityInfo.setReceiveTimeMillis(
1064 info.getReceiveTimeMillis()
1065 + mLastModemActivityInfo.getReceiveTimeMillis());
1066 }
1067 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1068 mLastModemActivityInfo.getSleepTimeMillis(),
1069 mLastModemActivityInfo.getIdleTimeMillis(),
1070 mLastModemActivityInfo.getTransmitTimeMillis(),
1071 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001072 } else {
1073 if (ar.result == null) {
1074 loge("queryModemActivityInfo: Empty response");
1075 } else if (ar.exception instanceof CommandException) {
1076 loge("queryModemActivityInfo: CommandException: " +
1077 ar.exception);
1078 } else {
1079 loge("queryModemActivityInfo: Unknown exception");
1080 }
1081 }
sqian1a1be542020-03-05 11:37:28 -08001082 Bundle bundle = new Bundle();
1083 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1084 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001085 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001086 break;
1087
Meng Wang1a7c35a2016-05-05 20:56:15 -07001088 case CMD_SET_ALLOWED_CARRIERS:
1089 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001090 CarrierRestrictionRules argument =
1091 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001092 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001093 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 break;
1095
1096 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1097 ar = (AsyncResult) msg.obj;
1098 request = (MainThreadRequest) ar.userObj;
1099 if (ar.exception == null && ar.result != null) {
1100 request.result = ar.result;
1101 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001102 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1103 if (ar.exception instanceof CommandException) {
1104 loge("setAllowedCarriers: CommandException: " + ar.exception);
1105 CommandException.Error error =
1106 ((CommandException) (ar.exception)).getCommandError();
1107 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1108 request.result =
1109 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1110 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001111 } else {
1112 loge("setAllowedCarriers: Unknown exception");
1113 }
1114 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001115 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001116 break;
1117
1118 case CMD_GET_ALLOWED_CARRIERS:
1119 request = (MainThreadRequest) msg.obj;
1120 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001121 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001122 break;
1123
1124 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1125 ar = (AsyncResult) msg.obj;
1126 request = (MainThreadRequest) ar.userObj;
1127 if (ar.exception == null && ar.result != null) {
1128 request.result = ar.result;
1129 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001130 request.result = new IllegalStateException(
1131 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001132 if (ar.result == null) {
1133 loge("getAllowedCarriers: Empty response");
1134 } else if (ar.exception instanceof CommandException) {
1135 loge("getAllowedCarriers: CommandException: " +
1136 ar.exception);
1137 } else {
1138 loge("getAllowedCarriers: Unknown exception");
1139 }
1140 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001141 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001142 break;
1143
Nathan Haroldb3014052017-01-25 15:57:32 -08001144 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1145 ar = (AsyncResult) msg.obj;
1146 request = (MainThreadRequest) ar.userObj;
1147 if (ar.exception == null && ar.result != null) {
1148 request.result = ar.result;
1149 } else {
1150 request.result = new IllegalArgumentException(
1151 "Failed to retrieve Forbidden Plmns");
1152 if (ar.result == null) {
1153 loge("getForbiddenPlmns: Empty response");
1154 } else {
1155 loge("getForbiddenPlmns: Unknown exception");
1156 }
1157 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001158 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001159 break;
1160
1161 case CMD_GET_FORBIDDEN_PLMNS:
1162 request = (MainThreadRequest) msg.obj;
1163 uiccCard = getUiccCardFromRequest(request);
1164 if (uiccCard == null) {
1165 loge("getForbiddenPlmns() UiccCard is null");
1166 request.result = new IllegalArgumentException(
1167 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001168 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001169 break;
1170 }
1171 Integer appType = (Integer) request.argument;
1172 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1173 if (uiccApp == null) {
1174 loge("getForbiddenPlmns() no app with specified type -- "
1175 + appType);
1176 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001177 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001178 break;
1179 } else {
1180 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1181 + " specified type -- " + appType);
1182 }
1183 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1184 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1185 onCompleted);
1186 break;
1187
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001188 case CMD_SWITCH_SLOTS:
1189 request = (MainThreadRequest) msg.obj;
1190 int[] physicalSlots = (int[]) request.argument;
1191 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1192 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1193 break;
1194
1195 case EVENT_SWITCH_SLOTS_DONE:
1196 ar = (AsyncResult) msg.obj;
1197 request = (MainThreadRequest) ar.userObj;
1198 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001199 notifyRequester(request);
1200 break;
1201 case CMD_GET_NETWORK_SELECTION_MODE:
1202 request = (MainThreadRequest) msg.obj;
1203 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1204 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1205 break;
1206
1207 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1208 ar = (AsyncResult) msg.obj;
1209 request = (MainThreadRequest) ar.userObj;
1210 if (ar.exception != null) {
1211 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1212 } else {
1213 int mode = ((int[]) ar.result)[0];
1214 if (mode == 0) {
1215 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1216 } else {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1218 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001219 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001220 notifyRequester(request);
1221 break;
1222 case CMD_GET_CDMA_ROAMING_MODE:
1223 request = (MainThreadRequest) msg.obj;
1224 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1225 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1226 break;
1227 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1228 ar = (AsyncResult) msg.obj;
1229 request = (MainThreadRequest) ar.userObj;
1230 if (ar.exception != null) {
1231 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1232 } else {
1233 request.result = ((int[]) ar.result)[0];
1234 }
1235 notifyRequester(request);
1236 break;
1237 case CMD_SET_CDMA_ROAMING_MODE:
1238 request = (MainThreadRequest) msg.obj;
1239 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1240 int mode = (int) request.argument;
1241 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1242 break;
1243 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1244 ar = (AsyncResult) msg.obj;
1245 request = (MainThreadRequest) ar.userObj;
1246 request.result = ar.exception == null;
1247 notifyRequester(request);
1248 break;
1249 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1250 request = (MainThreadRequest) msg.obj;
1251 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1252 int subscriptionMode = (int) request.argument;
1253 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1254 break;
1255 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1256 ar = (AsyncResult) msg.obj;
1257 request = (MainThreadRequest) ar.userObj;
1258 request.result = ar.exception == null;
1259 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001260 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001261 case CMD_GET_ALL_CELL_INFO:
1262 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001264 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 case EVENT_GET_ALL_CELL_INFO_DONE:
1267 ar = (AsyncResult) msg.obj;
1268 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001269 // If a timeout occurs, the response will be null
1270 request.result = (ar.exception == null && ar.result != null)
1271 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001272 synchronized (request) {
1273 request.notifyAll();
1274 }
1275 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001276 case CMD_REQUEST_CELL_INFO_UPDATE:
1277 request = (MainThreadRequest) msg.obj;
1278 request.phone.requestCellInfoUpdate(request.workSource,
1279 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1280 break;
1281 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1282 ar = (AsyncResult) msg.obj;
1283 request = (MainThreadRequest) ar.userObj;
1284 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1285 try {
1286 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001287 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wang6c08ecd2019-09-30 17:13:54 -07001288 cb.onError(
1289 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1290 ar.exception.getClass().getName(),
1291 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001292 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001293 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wang6c08ecd2019-09-30 17:13:54 -07001294 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else {
1296 // use the result as returned
1297 cb.onCellInfo((List<CellInfo>) ar.result);
1298 }
1299 } catch (RemoteException re) {
1300 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1301 }
1302 break;
1303 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001304 request = (MainThreadRequest) msg.obj;
1305 WorkSource ws = (WorkSource) request.argument;
1306 Phone phone = getPhoneFromRequest(request);
Meng Wangd64acad2019-12-09 13:13:01 -08001307 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001308 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001309 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 ar = (AsyncResult) msg.obj;
1311 request = (MainThreadRequest) ar.userObj;
1312 if (ar.exception == null) {
1313 request.result = ar.result;
1314 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001315 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001316 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wangd64acad2019-12-09 13:13:01 -08001317 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 }
1319
1320 synchronized (request) {
1321 request.notifyAll();
1322 }
1323 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001324 case CMD_MODEM_REBOOT:
1325 request = (MainThreadRequest) msg.obj;
1326 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001327 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001328 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001329 case EVENT_CMD_MODEM_REBOOT_DONE:
1330 handleNullReturnEvent(msg, "rebootModem");
1331 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001332 case CMD_REQUEST_ENABLE_MODEM:
1333 request = (MainThreadRequest) msg.obj;
1334 boolean enable = (boolean) request.argument;
1335 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001336 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001337 PhoneConfigurationManager.getInstance()
1338 .enablePhone(request.phone, enable, onCompleted);
1339 break;
1340 case EVENT_ENABLE_MODEM_DONE:
1341 ar = (AsyncResult) msg.obj;
1342 request = (MainThreadRequest) ar.userObj;
1343 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001344 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001345 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 if ((boolean) request.result) {
1347 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1348 updateModemStateMetrics();
1349 } else {
1350 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1351 + ar.exception);
1352 }
1353 notifyRequester(request);
1354 break;
1355 case CMD_GET_MODEM_STATUS:
1356 request = (MainThreadRequest) msg.obj;
1357 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1358 PhoneConfigurationManager.getInstance()
1359 .getPhoneStatusFromModem(request.phone, onCompleted);
1360 break;
1361 case EVENT_GET_MODEM_STATUS_DONE:
1362 ar = (AsyncResult) msg.obj;
1363 request = (MainThreadRequest) ar.userObj;
1364 int id = request.phone.getPhoneId();
1365 if (ar.exception == null && ar.result != null) {
1366 request.result = ar.result;
1367 //update the cache as modem status has changed
1368 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1369 (boolean) request.result);
1370 } else {
1371 // Return true if modem status cannot be retrieved. For most cases,
1372 // modem status is on. And for older version modems, GET_MODEM_STATUS
1373 // and disable modem are not supported. Modem is always on.
1374 // TODO: this should be fixed in R to support a third
1375 // status UNKNOWN b/131631629
1376 request.result = true;
1377 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1378 + ar.exception);
1379 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001380 notifyRequester(request);
1381 break;
Hall Liud0d1dc92020-01-20 13:42:00 -08001382 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1383 request = (MainThreadRequest) msg.obj;
1384 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1385 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1386 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1387 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1388 break;
1389 }
1390 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1391 ar = (AsyncResult) msg.obj;
1392 request = (MainThreadRequest) ar.userObj;
1393 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1394 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1395 args.second.accept(ar.exception == null);
1396 notifyRequester(request);
1397 break;
1398 }
yincheng zhaod698b842019-09-06 17:06:54 -07001399 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1400 ar = (AsyncResult) msg.obj;
1401 request = (MainThreadRequest) ar.userObj;
1402 if (ar.exception == null && ar.result != null) {
1403 request.result = ar.result;
1404 } else {
1405 request.result = -1;
1406 loge("Failed to set Forbidden Plmns");
1407 if (ar.result == null) {
1408 loge("setForbidenPlmns: Empty response");
1409 } else if (ar.exception != null) {
1410 loge("setForbiddenPlmns: Exception: " + ar.exception);
1411 request.result = -1;
1412 } else {
1413 loge("setForbiddenPlmns: Unknown exception");
1414 }
1415 }
1416 notifyRequester(request);
1417 break;
1418 case CMD_SET_FORBIDDEN_PLMNS:
1419 request = (MainThreadRequest) msg.obj;
1420 uiccCard = getUiccCardFromRequest(request);
1421 if (uiccCard == null) {
1422 loge("setForbiddenPlmns: UiccCard is null");
1423 request.result = -1;
1424 notifyRequester(request);
1425 break;
1426 }
1427 Pair<Integer, List<String>> setFplmnsArgs =
1428 (Pair<Integer, List<String>>) request.argument;
1429 appType = setFplmnsArgs.first;
1430 List<String> fplmns = setFplmnsArgs.second;
1431 uiccApp = uiccCard.getApplicationByType(appType);
1432 if (uiccApp == null) {
1433 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1434 request.result = -1;
1435 loge("Failed to get UICC App");
1436 notifyRequester(request);
1437 } else {
1438 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1439 ((SIMRecords) uiccApp.getIccRecords())
1440 .setForbiddenPlmns(onCompleted, fplmns);
1441 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001442 break;
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001443 case CMD_ERASE_MODEM_CONFIG:
1444 request = (MainThreadRequest) msg.obj;
1445 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1446 defaultPhone.eraseModemConfig(onCompleted);
1447 break;
1448 case EVENT_ERASE_MODEM_CONFIG_DONE:
1449 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhaod698b842019-09-06 17:06:54 -07001450 break;
zoey chenf95ca592019-12-30 16:11:23 +08001451
1452 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1453 request = (MainThreadRequest) msg.obj;
1454 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1455 Pair<String, String> changed = (Pair<String, String>) request.argument;
1456 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1457 changed.first, changed.second, onCompleted);
1458 break;
1459 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1460 ar = (AsyncResult) msg.obj;
1461 request = (MainThreadRequest) ar.userObj;
1462 if (ar.exception == null) {
1463 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1464 } else {
1465 request.result = msg.arg1;
1466 }
1467 notifyRequester(request);
1468 break;
1469
1470 case CMD_SET_ICC_LOCK_ENABLED:
1471 request = (MainThreadRequest) msg.obj;
1472 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1473 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1474 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1475 enabled.first, enabled.second, onCompleted);
1476 break;
1477 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1478 ar = (AsyncResult) msg.obj;
1479 request = (MainThreadRequest) ar.userObj;
1480 if (ar.exception == null) {
1481 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1482 } else {
1483 request.result = msg.arg1;
1484 }
1485 notifyRequester(request);
1486 break;
1487
Peter Wangdafb9ac2020-01-15 14:13:38 -08001488 case MSG_NOTIFY_USER_ACTIVITY:
1489 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001490 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1492 getDefaultPhone().getContext().sendBroadcastAsUser(
1493 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1494 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001495 default:
1496 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1497 break;
1498 }
1499 }
Jake Hambye994d462014-02-03 13:10:13 -08001500
Pengquan Menga1bb6272018-09-06 09:59:22 -07001501 private void notifyRequester(MainThreadRequest request) {
1502 synchronized (request) {
1503 request.notifyAll();
1504 }
1505 }
1506
Jake Hambye994d462014-02-03 13:10:13 -08001507 private void handleNullReturnEvent(Message msg, String command) {
1508 AsyncResult ar = (AsyncResult) msg.obj;
1509 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1510 if (ar.exception == null) {
1511 request.result = true;
1512 } else {
1513 request.result = false;
1514 if (ar.exception instanceof CommandException) {
1515 loge(command + ": CommandException: " + ar.exception);
1516 } else {
1517 loge(command + ": Unknown exception");
1518 }
1519 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001520 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001521 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001522 }
1523
1524 /**
1525 * Posts the specified command to be executed on the main thread,
1526 * waits for the request to complete, and returns the result.
1527 * @see #sendRequestAsync
1528 */
1529 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001530 return sendRequest(
1531 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001532 }
1533
1534 /**
1535 * Posts the specified command to be executed on the main thread,
1536 * waits for the request to complete, and returns the result.
1537 * @see #sendRequestAsync
1538 */
1539 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1540 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001541 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001542 }
1543
1544 /**
1545 * Posts the specified command to be executed on the main thread,
1546 * waits for the request to complete, and returns the result.
1547 * @see #sendRequestAsync
1548 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001549 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001550 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001551 }
1552
1553 /**
1554 * Posts the specified command to be executed on the main thread,
1555 * waits for the request to complete, and returns the result.
1556 * @see #sendRequestAsync
1557 */
Nathan Harold92bed182018-10-12 18:16:49 -07001558 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1559 return sendRequest(command, argument, subId, null, workSource);
1560 }
1561
1562 /**
1563 * Posts the specified command to be executed on the main thread,
1564 * waits for the request to complete, and returns the result.
1565 * @see #sendRequestAsync
1566 */
1567 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1568 return sendRequest(
1569 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1570 }
1571
1572 /**
1573 * Posts the specified command to be executed on the main thread,
1574 * waits for the request to complete, and returns the result.
1575 * @see #sendRequestAsync
1576 */
1577 private Object sendRequest(
1578 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001579 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1580 throw new RuntimeException("This method will deadlock if called from the main thread.");
1581 }
1582
Nathan Harold92bed182018-10-12 18:16:49 -07001583 MainThreadRequest request = null;
1584 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1585 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1586 } else if (phone != null) {
1587 request = new MainThreadRequest(argument, phone, workSource);
1588 } else {
1589 request = new MainThreadRequest(argument, subId, workSource);
1590 }
1591
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001592 Message msg = mMainThreadHandler.obtainMessage(command, request);
1593 msg.sendToTarget();
1594
1595 // Wait for the request to complete
1596 synchronized (request) {
1597 while (request.result == null) {
1598 try {
1599 request.wait();
1600 } catch (InterruptedException e) {
1601 // Do nothing, go back and wait until the request is complete
1602 }
1603 }
1604 }
1605 return request.result;
1606 }
1607
1608 /**
1609 * Asynchronous ("fire and forget") version of sendRequest():
1610 * Posts the specified command to be executed on the main thread, and
1611 * returns immediately.
1612 * @see #sendRequest
1613 */
1614 private void sendRequestAsync(int command) {
1615 mMainThreadHandler.sendEmptyMessage(command);
1616 }
1617
1618 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001619 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001620 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 */
1622 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 sendRequestAsync(command, argument, null, null);
1624 }
1625
1626 /**
1627 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1628 * @see {@link #sendRequest(int,Object)}
1629 */
1630 private void sendRequestAsync(
1631 int command, Object argument, Phone phone, WorkSource workSource) {
1632 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001633 Message msg = mMainThreadHandler.obtainMessage(command, request);
1634 msg.sendToTarget();
1635 }
1636
1637 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001638 * Initialize the singleton PhoneInterfaceManager instance.
1639 * This is only done once, at startup, from PhoneApp.onCreate().
1640 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001641 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001642 synchronized (PhoneInterfaceManager.class) {
1643 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 } else {
1646 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1647 }
1648 return sInstance;
1649 }
1650 }
1651
1652 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001653 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001654 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001655 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger05f52c22019-12-05 13:03:21 -08001656 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001657 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1659 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001660 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001661 mTelephonySharedPreferences =
1662 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001663 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001664 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001665 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001666
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001667 publish();
1668 }
1669
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001670 private Phone getDefaultPhone() {
1671 Phone thePhone = getPhone(getDefaultSubscription());
1672 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1673 }
1674
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001675 private void publish() {
1676 if (DBG) log("publish: " + this);
1677
Peter Wangc035ce42020-01-08 21:00:22 -08001678 TelephonyFrameworkInitializer
1679 .getTelephonyServiceManager()
1680 .getTelephonyServiceRegisterer()
1681 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001682 }
1683
Stuart Scott584921c2015-01-15 17:10:34 -08001684 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001685 if (request.phone != null) {
1686 return request.phone;
1687 } else {
1688 return getPhoneFromSubId(request.subId);
1689 }
1690 }
1691
1692 private Phone getPhoneFromSubId(int subId) {
1693 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1694 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001695 }
1696
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001697 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1698 Phone phone = getPhoneFromRequest(request);
1699 return phone == null ? null :
1700 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1701 }
1702
Wink Saville36469e72014-06-11 15:17:00 -07001703 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001704 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001705 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001706 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001707
Naina Nalluri8ff344d2019-09-17 14:10:30 -07001708 private void sendEraseModemConfig(Phone phone) {
1709 if (phone != null) {
1710 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1711 mApp, phone.getSubId(), "eraseModemConfig");
1712 final long identity = Binder.clearCallingIdentity();
1713 try {
1714 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1715 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1716 } finally {
1717 Binder.restoreCallingIdentity(identity);
1718 }
1719 }
1720 }
1721
Peter Wang050bb052020-01-13 23:33:09 -08001722 private boolean isImsAvailableOnDevice() {
1723 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1724 if (pm == null) {
1725 // For some reason package manger is not available.. This will fail internally anyway,
1726 // so do not throw error and allow.
1727 return true;
1728 }
1729 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1730 }
1731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001732 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001733 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001734 }
1735
Wink Savilleb564aae2014-10-23 10:18:09 -07001736 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001737 if (DBG) log("dial: " + number);
1738 // No permission check needed here: This is just a wrapper around the
1739 // ACTION_DIAL intent, which is available to any app since it puts up
1740 // the UI before it does anything.
1741
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001742 final long identity = Binder.clearCallingIdentity();
1743 try {
1744 String url = createTelUrl(number);
1745 if (url == null) {
1746 return;
1747 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001748
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001749 // PENDING: should we just silently fail if phone is offhook or ringing?
1750 PhoneConstants.State state = mCM.getState(subId);
1751 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1752 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1753 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1754 mApp.startActivity(intent);
1755 }
1756 } finally {
1757 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001758 }
1759 }
1760
1761 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001762 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001763 }
1764
Wink Savilleb564aae2014-10-23 10:18:09 -07001765 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001766 if (DBG) log("call: " + number);
1767
1768 // This is just a wrapper around the ACTION_CALL intent, but we still
1769 // need to do a permission check since we're calling startActivity()
1770 // from the context of the phone app.
1771 enforceCallPermission();
1772
Jordan Liu1617b712019-07-10 15:06:26 -07001773 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001774 != AppOpsManager.MODE_ALLOWED) {
1775 return;
1776 }
1777
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001778 final long identity = Binder.clearCallingIdentity();
1779 try {
1780 String url = createTelUrl(number);
1781 if (url == null) {
1782 return;
1783 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001784
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001785 boolean isValid = false;
1786 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1787 if (slist != null) {
1788 for (SubscriptionInfo subInfoRecord : slist) {
1789 if (subInfoRecord.getSubscriptionId() == subId) {
1790 isValid = true;
1791 break;
1792 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001793 }
Wink Saville08874612014-08-31 19:19:58 -07001794 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001795 if (!isValid) {
1796 return;
1797 }
Wink Saville08874612014-08-31 19:19:58 -07001798
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001799 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1800 intent.putExtra(SUBSCRIPTION_KEY, subId);
1801 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1802 mApp.startActivity(intent);
1803 } finally {
1804 Binder.restoreCallingIdentity(identity);
1805 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001806 }
1807
Wink Savilleb564aae2014-10-23 10:18:09 -07001808 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001809 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001810 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1811 }
1812
Wink Savilleb564aae2014-10-23 10:18:09 -07001813 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001814 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001815 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1816 }
1817
Wink Savilleb564aae2014-10-23 10:18:09 -07001818 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001819 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001820
1821 final long identity = Binder.clearCallingIdentity();
1822 try {
1823 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1824 checkSimPin.start();
1825 return checkSimPin.unlockSim(null, pin);
1826 } finally {
1827 Binder.restoreCallingIdentity(identity);
1828 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001829 }
1830
Wink Savilleb564aae2014-10-23 10:18:09 -07001831 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001833
1834 final long identity = Binder.clearCallingIdentity();
1835 try {
1836 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1837 checkSimPuk.start();
1838 return checkSimPuk.unlockSim(puk, pin);
1839 } finally {
1840 Binder.restoreCallingIdentity(identity);
1841 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001842 }
1843
1844 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001845 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001846 * a synchronous one.
1847 */
1848 private static class UnlockSim extends Thread {
1849
1850 private final IccCard mSimCard;
1851
1852 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001853 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1854 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001855
1856 // For replies from SimCard interface
1857 private Handler mHandler;
1858
1859 // For async handler to identify request type
1860 private static final int SUPPLY_PIN_COMPLETE = 100;
1861
1862 public UnlockSim(IccCard simCard) {
1863 mSimCard = simCard;
1864 }
1865
1866 @Override
1867 public void run() {
1868 Looper.prepare();
1869 synchronized (UnlockSim.this) {
1870 mHandler = new Handler() {
1871 @Override
1872 public void handleMessage(Message msg) {
1873 AsyncResult ar = (AsyncResult) msg.obj;
1874 switch (msg.what) {
1875 case SUPPLY_PIN_COMPLETE:
1876 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1877 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001878 mRetryCount = msg.arg1;
1879 if (ar.exception != null) {
1880 if (ar.exception instanceof CommandException &&
1881 ((CommandException)(ar.exception)).getCommandError()
1882 == CommandException.Error.PASSWORD_INCORRECT) {
1883 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001884 } //When UiccCardApp dispose,handle message and return exception
1885 else if (ar.exception instanceof CommandException &&
1886 ((CommandException) (ar.exception)).getCommandError()
1887 == CommandException.Error.ABORTED) {
1888 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001889 } else {
1890 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1891 }
1892 } else {
1893 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1894 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001895 mDone = true;
1896 UnlockSim.this.notifyAll();
1897 }
1898 break;
1899 }
1900 }
1901 };
1902 UnlockSim.this.notifyAll();
1903 }
1904 Looper.loop();
1905 }
1906
1907 /*
1908 * Use PIN or PUK to unlock SIM card
1909 *
1910 * If PUK is null, unlock SIM card with PIN
1911 *
1912 * If PUK is not null, unlock SIM card with PUK and set PIN code
1913 */
Wink Saville9de0f752013-10-22 19:04:03 -07001914 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001915
1916 while (mHandler == null) {
1917 try {
1918 wait();
1919 } catch (InterruptedException e) {
1920 Thread.currentThread().interrupt();
1921 }
1922 }
1923 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1924
1925 if (puk == null) {
1926 mSimCard.supplyPin(pin, callback);
1927 } else {
1928 mSimCard.supplyPuk(puk, pin, callback);
1929 }
1930
1931 while (!mDone) {
1932 try {
1933 Log.d(LOG_TAG, "wait for done");
1934 wait();
1935 } catch (InterruptedException e) {
1936 // Restore the interrupted status
1937 Thread.currentThread().interrupt();
1938 }
1939 }
1940 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001941 int[] resultArray = new int[2];
1942 resultArray[0] = mResult;
1943 resultArray[1] = mRetryCount;
1944 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001945 }
1946 }
1947
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001948 /**
1949 * This method has been removed due to privacy and stability concerns.
1950 */
1951 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001953 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1954 return;
Wink Saville36469e72014-06-11 15:17:00 -07001955 }
1956
Nathan Harold1f889d82020-06-04 17:05:26 -07001957 @Override
1958 public void updateServiceLocationWithPackageName(String callingPackage) {
1959 mApp.getSystemService(AppOpsManager.class)
1960 .checkPackage(Binder.getCallingUid(), callingPackage);
1961
1962 final int targetSdk = getTargetSdk(callingPackage);
1963 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1964 // Callers targeting S have no business invoking this method.
1965 return;
1966 }
1967
1968 LocationAccessPolicy.LocationPermissionResult locationResult =
1969 LocationAccessPolicy.checkLocationPermission(mApp,
1970 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1971 .setCallingPackage(callingPackage)
1972 .setCallingFeatureId(null)
1973 .setCallingPid(Binder.getCallingPid())
1974 .setCallingUid(Binder.getCallingUid())
1975 .setMethod("updateServiceLocation")
1976 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1977 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1978 .build());
1979 // Apps that lack location permission have no business calling this method;
1980 // however, because no permission was declared in the public API, denials must
1981 // all be "soft".
1982 switch (locationResult) {
1983 case DENIED_HARD: /* fall through */
1984 case DENIED_SOFT:
1985 return;
1986 }
1987
1988 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001989 final long identity = Binder.clearCallingIdentity();
1990 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001991 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001993 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 }
1995 } finally {
1996 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001997 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001998 }
1999
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002000 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002001 @Override
2002 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002003 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002004 }
2005
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002006
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002007 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002008 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2009 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2010 callingFeatureId);
2011 }
2012
2013 @Deprecated
2014 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002015 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002016 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2017 }
2018
2019 @Override
2020 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2021 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002022 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002023 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002024 return false;
2025 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002026
2027 final long identity = Binder.clearCallingIdentity();
2028 try {
2029 return isRadioOnForSubscriber(subId);
2030 } finally {
2031 Binder.restoreCallingIdentity(identity);
2032 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002033 }
2034
2035 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002036 final long identity = Binder.clearCallingIdentity();
2037 try {
2038 final Phone phone = getPhone(subId);
2039 if (phone != null) {
2040 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2041 } else {
2042 return false;
2043 }
2044 } finally {
2045 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002046 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002047 }
2048
2049 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002050 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002051 }
Wink Saville36469e72014-06-11 15:17:00 -07002052
Wink Savilleb564aae2014-10-23 10:18:09 -07002053 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002054 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002055
2056 final long identity = Binder.clearCallingIdentity();
2057 try {
2058 final Phone phone = getPhone(subId);
2059 if (phone != null) {
2060 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2061 }
2062 } finally {
2063 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002064 }
Wink Saville36469e72014-06-11 15:17:00 -07002065 }
2066
2067 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002068 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002069 }
2070
Wink Savilleb564aae2014-10-23 10:18:09 -07002071 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002073
2074 final long identity = Binder.clearCallingIdentity();
2075 try {
2076 final Phone phone = getPhone(subId);
2077 if (phone == null) {
2078 return false;
2079 }
2080 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2081 toggleRadioOnOffForSubscriber(subId);
2082 }
2083 return true;
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002086 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002087 }
Wink Saville36469e72014-06-11 15:17:00 -07002088
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002089 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002090 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002091 /*
2092 * If any of the Radios are available, it will need to be
2093 * shutdown. So return true if any Radio is available.
2094 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002095 final long identity = Binder.clearCallingIdentity();
2096 try {
2097 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2098 Phone phone = PhoneFactory.getPhone(i);
2099 if (phone != null && phone.isRadioAvailable()) return true;
2100 }
2101 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2102 return false;
2103 } finally {
2104 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002105 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002106 }
2107
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002108 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002109 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110 enforceModifyPermission();
2111
2112 final long identity = Binder.clearCallingIdentity();
2113 try {
2114 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2115 logv("Shutting down Phone " + i);
2116 shutdownRadioUsingPhoneId(i);
2117 }
2118 } finally {
2119 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002120 }
2121 }
2122
2123 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002124 Phone phone = PhoneFactory.getPhone(phoneId);
2125 if (phone != null && phone.isRadioAvailable()) {
2126 phone.shutdownRadio();
2127 }
2128 }
2129
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002130 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002131 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002132
2133 final long identity = Binder.clearCallingIdentity();
2134 try {
2135 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2136 if (defaultPhone != null) {
2137 defaultPhone.setRadioPower(turnOn);
2138 return true;
2139 } else {
2140 loge("There's no default phone.");
2141 return false;
2142 }
2143 } finally {
2144 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002145 }
Wink Saville36469e72014-06-11 15:17:00 -07002146 }
2147
Wink Savilleb564aae2014-10-23 10:18:09 -07002148 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002150
2151 final long identity = Binder.clearCallingIdentity();
2152 try {
2153 final Phone phone = getPhone(subId);
2154 if (phone != null) {
2155 phone.setRadioPower(turnOn);
2156 return true;
2157 } else {
2158 return false;
2159 }
2160 } finally {
2161 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002162 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002163 }
2164
Wink Saville36469e72014-06-11 15:17:00 -07002165 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002166 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002167 public boolean enableDataConnectivity() {
2168 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002169
2170 final long identity = Binder.clearCallingIdentity();
2171 try {
2172 int subId = mSubscriptionController.getDefaultDataSubId();
2173 final Phone phone = getPhone(subId);
2174 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002175 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002176 return true;
2177 } else {
2178 return false;
2179 }
2180 } finally {
2181 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002182 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002183 }
2184
Wink Saville36469e72014-06-11 15:17:00 -07002185 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002186 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002187 public boolean disableDataConnectivity() {
2188 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002189
2190 final long identity = Binder.clearCallingIdentity();
2191 try {
2192 int subId = mSubscriptionController.getDefaultDataSubId();
2193 final Phone phone = getPhone(subId);
2194 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002195 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002196 return true;
2197 } 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
Sanket Padawe356d7632015-06-22 14:03:32 -07002205 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002206 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207 final long identity = Binder.clearCallingIdentity();
2208 try {
2209 final Phone phone = getPhone(subId);
2210 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002211 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002212 } else {
2213 return false;
2214 }
2215 } finally {
2216 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002217 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002218 }
2219
2220 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002221 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002222 }
2223
pkanwarae03a6b2016-11-06 20:37:09 -08002224 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002225 enforceCallPermission();
2226
2227 final long identity = Binder.clearCallingIdentity();
2228 try {
2229 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2230 return;
2231 }
2232 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2233 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2234 } finally {
2235 Binder.restoreCallingIdentity(identity);
2236 }
pkanwar32d516d2016-10-14 19:37:38 -07002237 };
2238
Wink Savilleb564aae2014-10-23 10:18:09 -07002239 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002240 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241
2242 final long identity = Binder.clearCallingIdentity();
2243 try {
2244 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2245 return false;
2246 }
2247 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2248 } finally {
2249 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002250 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002251 }
2252
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002254 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002255 }
2256
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002257 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002258 final long identity = Binder.clearCallingIdentity();
2259 try {
2260 Phone phone = PhoneFactory.getPhone(slotIndex);
2261 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2262 PhoneConstantConversions.convertCallState(phone.getState());
2263 } finally {
2264 Binder.restoreCallingIdentity(identity);
2265 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002266 }
2267
Sanket Padawe356d7632015-06-22 14:03:32 -07002268 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002269 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002270 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2271 }
2272
2273 @Override
2274 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002275 final long identity = Binder.clearCallingIdentity();
2276 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002277 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002278 if (phone != null) {
2279 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2280 } else {
2281 return PhoneConstantConversions.convertDataState(
2282 PhoneConstants.DataState.DISCONNECTED);
2283 }
2284 } finally {
2285 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002286 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002287 }
2288
Sanket Padawe356d7632015-06-22 14:03:32 -07002289 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002290 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002291 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2292 }
2293
2294 @Override
2295 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002296 final long identity = Binder.clearCallingIdentity();
2297 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002298 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002299 if (phone != null) {
2300 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2301 } else {
2302 return TelephonyManager.DATA_ACTIVITY_NONE;
2303 }
2304 } finally {
2305 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002306 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002307 }
2308
2309 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002310 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002311 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002312 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002313
2314 LocationAccessPolicy.LocationPermissionResult locationResult =
2315 LocationAccessPolicy.checkLocationPermission(mApp,
2316 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2317 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002318 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002319 .setCallingPid(Binder.getCallingPid())
2320 .setCallingUid(Binder.getCallingUid())
2321 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002322 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002323 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2324 .build());
2325 switch (locationResult) {
2326 case DENIED_HARD:
2327 throw new SecurityException("Not allowed to access cell location");
2328 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002329 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2330 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002331 }
2332
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002333 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002334 final long identity = Binder.clearCallingIdentity();
2335 try {
2336 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002337 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002338 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002339 } finally {
2340 Binder.restoreCallingIdentity(identity);
2341 }
Svetoslav64fad262015-04-14 14:35:21 -07002342 }
2343
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002344 @Override
Jack Yu01425032020-02-22 19:38:58 -08002345 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002346 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2347 // registered cell info, so return a NULL country instead.
2348 final long identity = Binder.clearCallingIdentity();
2349 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002350 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2351 // Get default phone in this case.
2352 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2353 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002354 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002355 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002356 if (phone == null) return "";
2357 ServiceStateTracker sst = phone.getServiceStateTracker();
2358 if (sst == null) return "";
2359 LocaleTracker lt = sst.getLocaleTracker();
2360 if (lt == null) return "";
2361 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2362 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2363 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002364 } finally {
2365 Binder.restoreCallingIdentity(identity);
2366 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002367 }
2368
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002369 /**
2370 * This method was removed due to potential issues caused by performing partial
2371 * updates of service state, and lack of a credible use case.
2372 *
2373 * This has the ability to break the telephony implementation by disabling notification of
2374 * changes in device connectivity. DO NOT USE THIS!
2375 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002376 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002377 public void enableLocationUpdates() {
2378 mApp.enforceCallingOrSelfPermission(
2379 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002380 }
2381
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002382 /**
2383 * This method was removed due to potential issues caused by performing partial
2384 * updates of service state, and lack of a credible use case.
2385 *
2386 * This has the ability to break the telephony implementation by disabling notification of
2387 * changes in device connectivity. DO NOT USE THIS!
2388 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002389 @Override
2390 public void disableLocationUpdates() {
2391 mApp.enforceCallingOrSelfPermission(
2392 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002393 }
2394
Nathan Harold31d7ff32018-10-15 20:20:30 -07002395 /**
2396 * Returns the target SDK version number for a given package name.
2397 *
Nathan Haroldec184742019-07-10 17:04:16 -07002398 * This call MUST be invoked before clearing the calling UID.
2399 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 * @return target SDK if the package is found or INT_MAX.
2401 */
2402 private int getTargetSdk(String packageName) {
2403 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002404 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002405 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002406 if (ai != null) return ai.targetSdkVersion;
2407 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002408 loge("Failed to get package info for pkg="
2409 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002410 }
2411 return Integer.MAX_VALUE;
2412 }
2413
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002414 @Override
2415 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002416 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2417 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002418 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002419 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2420 throw new SecurityException(
2421 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2422 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002423
Jordan Liu1617b712019-07-10 15:06:26 -07002424 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2426 return null;
2427 }
Svetoslav64fad262015-04-14 14:35:21 -07002428
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002429 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002430
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002431 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002432 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002433
Nathan Haroldf180aac2018-06-01 18:43:55 -07002434 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2435 for (CellInfo ci : info) {
2436 if (ci instanceof CellInfoGsm) {
2437 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2438 } else if (ci instanceof CellInfoWcdma) {
2439 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002442 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
2444
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002445 private List<CellInfo> getCachedCellInfo() {
2446 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2447 for (Phone phone : PhoneFactory.getPhones()) {
2448 List<CellInfo> info = phone.getAllCellInfo();
2449 if (info != null) cellInfos.addAll(info);
2450 }
2451 return cellInfos;
2452 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002453
2454 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002455 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002456 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002457 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002458
2459 LocationAccessPolicy.LocationPermissionResult locationResult =
2460 LocationAccessPolicy.checkLocationPermission(mApp,
2461 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2462 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002463 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002464 .setCallingPid(Binder.getCallingPid())
2465 .setCallingUid(Binder.getCallingUid())
2466 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002467 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002468 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2469 .build());
2470 switch (locationResult) {
2471 case DENIED_HARD:
2472 throw new SecurityException("Not allowed to access cell info");
2473 case DENIED_SOFT:
2474 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002475 }
2476
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002477 final int targetSdk = getTargetSdk(callingPackage);
2478 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2479 return getCachedCellInfo();
2480 }
2481
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002482 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002483 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002484 final long identity = Binder.clearCallingIdentity();
2485 try {
2486 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2487 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002488 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002489 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002490 if (info != null) cellInfos.addAll(info);
2491 }
2492 return cellInfos;
2493 } finally {
2494 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002495 }
2496 }
2497
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002498 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002499 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2500 String callingFeatureId) {
2501 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2502 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002503 }
2504
2505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002506 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2507 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002508 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002509 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 }
2511
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002512 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2513 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002514 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002515 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002516
2517 LocationAccessPolicy.LocationPermissionResult locationResult =
2518 LocationAccessPolicy.checkLocationPermission(mApp,
2519 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2520 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002521 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002522 .setCallingPid(Binder.getCallingPid())
2523 .setCallingUid(Binder.getCallingUid())
2524 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002525 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2526 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002527 .build());
2528 switch (locationResult) {
2529 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002530 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2531 // Safetynet logging for b/154934934
2532 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2533 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002534 throw new SecurityException("Not allowed to access cell info");
2535 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002536 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2537 // Safetynet logging for b/154934934
2538 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2539 }
Nathan Harold5320c422019-05-09 10:26:08 -07002540 try {
2541 cb.onCellInfo(new ArrayList<CellInfo>());
2542 } catch (RemoteException re) {
2543 // Drop without consequences
2544 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002545 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002546 }
2547
Nathan Harolda939a962019-05-09 10:13:47 -07002548
2549 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002550 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2551
2552 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2553 }
2554
2555 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002556 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002557 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002558 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002559
2560 final long identity = Binder.clearCallingIdentity();
2561 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002562 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002563 } finally {
2564 Binder.restoreCallingIdentity(identity);
2565 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002566 }
2567
Shishir Agrawala9f32182016-04-12 12:00:16 -07002568 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002569 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002570 Phone phone = PhoneFactory.getPhone(slotIndex);
2571 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002572 return null;
2573 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002574 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002575 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002576 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002577 return null;
2578 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002579
2580 final long identity = Binder.clearCallingIdentity();
2581 try {
2582 return phone.getImei();
2583 } finally {
2584 Binder.restoreCallingIdentity(identity);
2585 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002586 }
2587
2588 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002589 public String getTypeAllocationCodeForSlot(int slotIndex) {
2590 Phone phone = PhoneFactory.getPhone(slotIndex);
2591 String tac = null;
2592 if (phone != null) {
2593 String imei = phone.getImei();
2594 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2595 }
2596 return tac;
2597 }
2598
2599 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002600 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002601 Phone phone = PhoneFactory.getPhone(slotIndex);
2602 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002603 return null;
2604 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002605
Jeff Davidson913390f2018-02-23 17:11:49 -08002606 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002607 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002608 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002609 return null;
2610 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002611
2612 final long identity = Binder.clearCallingIdentity();
2613 try {
2614 return phone.getMeid();
2615 } finally {
2616 Binder.restoreCallingIdentity(identity);
2617 }
Jack Yu2af8d712017-03-15 17:14:14 -07002618 }
2619
2620 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002621 public String getManufacturerCodeForSlot(int slotIndex) {
2622 Phone phone = PhoneFactory.getPhone(slotIndex);
2623 String manufacturerCode = null;
2624 if (phone != null) {
2625 String meid = phone.getMeid();
2626 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2627 }
2628 return manufacturerCode;
2629 }
2630
2631 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002632 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2633 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002634 Phone phone = PhoneFactory.getPhone(slotIndex);
2635 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002636 return null;
2637 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002638 int subId = phone.getSubId();
2639 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002640 mApp, subId, callingPackage, callingFeatureId,
2641 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002642 return null;
2643 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002644
2645 final long identity = Binder.clearCallingIdentity();
2646 try {
2647 return phone.getDeviceSvn();
2648 } finally {
2649 Binder.restoreCallingIdentity(identity);
2650 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002651 }
2652
fionaxu43304da2017-11-27 22:51:16 -08002653 @Override
2654 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002655 final long identity = Binder.clearCallingIdentity();
2656 try {
2657 final Phone phone = getPhone(subId);
2658 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2659 } finally {
2660 Binder.restoreCallingIdentity(identity);
2661 }
fionaxu43304da2017-11-27 22:51:16 -08002662 }
2663
2664 @Override
2665 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002666 final long identity = Binder.clearCallingIdentity();
2667 try {
2668 final Phone phone = getPhone(subId);
2669 return phone == null ? null : phone.getCarrierName();
2670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
fionaxu43304da2017-11-27 22:51:16 -08002673 }
2674
calvinpanffe225e2018-11-01 19:43:06 +08002675 @Override
chen xu0026ca62019-03-06 15:28:50 -08002676 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 final Phone phone = getPhone(subId);
2680 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002681 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002682 } finally {
2683 Binder.restoreCallingIdentity(identity);
2684 }
2685 }
2686
2687 @Override
chen xu0026ca62019-03-06 15:28:50 -08002688 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002692 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002693 } finally {
2694 Binder.restoreCallingIdentity(identity);
2695 }
2696 }
2697
chen xu651eec72018-11-11 19:03:44 -08002698 @Override
chen xu864e11c2018-12-06 22:10:03 -08002699 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2700 if (!isSubscriptionMccMnc) {
2701 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2702 }
chen xu651eec72018-11-11 19:03:44 -08002703 final Phone phone = PhoneFactory.getPhone(slotIndex);
2704 if (phone == null) {
2705 return TelephonyManager.UNKNOWN_CARRIER_ID;
2706 }
2707 final long identity = Binder.clearCallingIdentity();
2708 try {
2709 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2710 } finally {
2711 Binder.restoreCallingIdentity(identity);
2712 }
2713 }
2714
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002715 //
2716 // Internal helper methods.
2717 //
2718
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002719 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002720 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2721 *
2722 * @throws SecurityException if the caller does not have the required permission
2723 */
2724 private void enforceModifyPermission() {
2725 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2726 }
2727
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002728 /**
2729 * Make sure the caller is system.
2730 *
2731 * @throws SecurityException if the caller is not system.
2732 */
2733 private void enforceSystemCaller() {
2734 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2735 throw new SecurityException("Caller must be system");
2736 }
2737 }
2738
Shuo Qianf2b2df42019-11-13 17:43:31 -08002739 private void enforceActiveEmergencySessionPermission() {
2740 mApp.enforceCallingOrSelfPermission(
2741 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2742 }
2743
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002744 /**
2745 * Make sure the caller has the CALL_PHONE permission.
2746 *
2747 * @throws SecurityException if the caller does not have the required permission
2748 */
2749 private void enforceCallPermission() {
2750 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2751 }
2752
paulhu423b5f22019-08-23 19:17:33 +08002753 private void enforceSettingsPermission() {
2754 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002755 }
2756
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002757 private String createTelUrl(String number) {
2758 if (TextUtils.isEmpty(number)) {
2759 return null;
2760 }
2761
Jake Hambye994d462014-02-03 13:10:13 -08002762 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002763 }
2764
Ihab Awadf9e92732013-12-05 18:02:52 -08002765 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2767 }
2768
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002769 private static void logv(String msg) {
2770 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2771 }
2772
Ihab Awadf9e92732013-12-05 18:02:52 -08002773 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002774 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2775 }
2776
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002777 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002778 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002779 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002780 }
2781
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002783 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002784 final long identity = Binder.clearCallingIdentity();
2785 try {
2786 final Phone phone = PhoneFactory.getPhone(slotIndex);
2787 if (phone == null) {
2788 return PhoneConstants.PHONE_TYPE_NONE;
2789 } else {
2790 return phone.getPhoneType();
2791 }
2792 } finally {
2793 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002795 }
2796
2797 /**
2798 * Returns the CDMA ERI icon index to display
2799 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002800 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002801 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2802 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2803 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002804 }
2805
Sanket Padawe356d7632015-06-22 14:03:32 -07002806 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002807 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2808 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002809 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002810 mApp, subId, callingPackage, callingFeatureId,
2811 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002812 return -1;
2813 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002814
2815 final long identity = Binder.clearCallingIdentity();
2816 try {
2817 final Phone phone = getPhone(subId);
2818 if (phone != null) {
2819 return phone.getCdmaEriIconIndex();
2820 } else {
2821 return -1;
2822 }
2823 } finally {
2824 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002825 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002826 }
2827
2828 /**
2829 * Returns the CDMA ERI icon mode,
2830 * 0 - ON
2831 * 1 - FLASHING
2832 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002834 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2835 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2836 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002837 }
2838
Sanket Padawe356d7632015-06-22 14:03:32 -07002839 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002840 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2841 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002843 mApp, subId, callingPackage, callingFeatureId,
2844 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002845 return -1;
2846 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002847
2848 final long identity = Binder.clearCallingIdentity();
2849 try {
2850 final Phone phone = getPhone(subId);
2851 if (phone != null) {
2852 return phone.getCdmaEriIconMode();
2853 } else {
2854 return -1;
2855 }
2856 } finally {
2857 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002859 }
2860
2861 /**
2862 * Returns the CDMA ERI text,
2863 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002865 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2866 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2867 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002868 }
2869
Sanket Padawe356d7632015-06-22 14:03:32 -07002870 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002871 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2872 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002873 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002874 mApp, subId, callingPackage, callingFeatureId,
2875 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002876 return null;
2877 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002878
2879 final long identity = Binder.clearCallingIdentity();
2880 try {
2881 final Phone phone = getPhone(subId);
2882 if (phone != null) {
2883 return phone.getCdmaEriText();
2884 } else {
2885 return null;
2886 }
2887 } finally {
2888 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002889 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002890 }
2891
2892 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002893 * Returns the CDMA MDN.
2894 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002895 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002896 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002897 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2898 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002899
2900 final long identity = Binder.clearCallingIdentity();
2901 try {
2902 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002903 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002904 return phone.getLine1Number();
2905 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002906 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002907 return null;
2908 }
2909 } finally {
2910 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002911 }
2912 }
2913
2914 /**
2915 * Returns the CDMA MIN.
2916 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002917 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002918 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2920 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002921
2922 final long identity = Binder.clearCallingIdentity();
2923 try {
2924 final Phone phone = getPhone(subId);
2925 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2926 return phone.getCdmaMin();
2927 } else {
2928 return null;
2929 }
2930 } finally {
2931 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002932 }
2933 }
2934
Hall Liud892bec2018-11-30 14:51:45 -08002935 @Override
2936 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2937 INumberVerificationCallback callback, String callingPackage) {
2938 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2939 != PERMISSION_GRANTED) {
2940 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2941 }
2942 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2943
2944 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2945 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2946 throw new SecurityException("Calling package must be configured in the device config");
2947 }
2948
2949 if (range == null) {
2950 throw new NullPointerException("Range must be non-null");
2951 }
2952
2953 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002954 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002955
2956 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2957 }
2958
Junda Liuca05d5d2014-08-14 22:36:34 -07002959 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002960 * Returns true if CDMA provisioning needs to run.
2961 */
2962 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002963 final long identity = Binder.clearCallingIdentity();
2964 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002965 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002969 }
2970
2971 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002972 * Sets the voice mail number of a given subId.
2973 */
2974 @Override
2975 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002976 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2977 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002978
2979 final long identity = Binder.clearCallingIdentity();
2980 try {
2981 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2982 new Pair<String, String>(alphaTag, number), new Integer(subId));
2983 return success;
2984 } finally {
2985 Binder.restoreCallingIdentity(identity);
2986 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002987 }
2988
Ta-wei Yen87c49842016-05-13 21:19:52 -07002989 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002990 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2991 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002992 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2993 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002994 if (!TextUtils.equals(callingPackage, systemDialer)) {
2995 throw new SecurityException("caller must be system dialer");
2996 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002997
2998 final long identity = Binder.clearCallingIdentity();
2999 try {
3000 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3001 if (phoneAccountHandle == null) {
3002 return null;
3003 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003007 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003008 }
3009
3010 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003011 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3012 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003014 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003015 mApp, subId, callingPackage, callingFeatureId,
3016 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003017 return null;
3018 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003020 final long identity = Binder.clearCallingIdentity();
3021 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003022 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003023 } finally {
3024 Binder.restoreCallingIdentity(identity);
3025 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003026 }
3027
3028 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003029 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3030 VisualVoicemailSmsFilterSettings settings) {
3031 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032
3033 final long identity = Binder.clearCallingIdentity();
3034 try {
3035 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003036 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003037 } finally {
3038 Binder.restoreCallingIdentity(identity);
3039 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003040 }
3041
3042 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003043 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3044 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003045
3046 final long identity = Binder.clearCallingIdentity();
3047 try {
3048 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003049 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003050 } finally {
3051 Binder.restoreCallingIdentity(identity);
3052 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003053 }
3054
3055 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003056 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3057 String callingPackage, int subId) {
3058 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059
3060 final long identity = Binder.clearCallingIdentity();
3061 try {
3062 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003063 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003064 } finally {
3065 Binder.restoreCallingIdentity(identity);
3066 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003067 }
3068
3069 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003070 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003071 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003072
3073 final long identity = Binder.clearCallingIdentity();
3074 try {
3075 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003076 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003077 } finally {
3078 Binder.restoreCallingIdentity(identity);
3079 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003080 }
3081
3082 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003083 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3084 String callingAttributionTag, int subId, String number, int port, String text,
3085 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003086 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003087 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003088 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003089 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003090 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3091 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003092 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003093
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003094 /**
fionaxu0152e512016-11-14 13:36:14 -08003095 * Sets the voice activation state of a given subId.
3096 */
3097 @Override
3098 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3100 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003101
3102 final long identity = Binder.clearCallingIdentity();
3103 try {
3104 final Phone phone = getPhone(subId);
3105 if (phone != null) {
3106 phone.setVoiceActivationState(activationState);
3107 } else {
3108 loge("setVoiceActivationState fails with invalid subId: " + subId);
3109 }
3110 } finally {
3111 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003112 }
3113 }
3114
3115 /**
3116 * Sets the data activation state of a given subId.
3117 */
3118 @Override
3119 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3121 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003122
3123 final long identity = Binder.clearCallingIdentity();
3124 try {
3125 final Phone phone = getPhone(subId);
3126 if (phone != null) {
3127 phone.setDataActivationState(activationState);
3128 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003129 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130 }
3131 } finally {
3132 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003133 }
3134 }
3135
3136 /**
3137 * Returns the voice activation state of a given subId.
3138 */
3139 @Override
3140 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003141 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003142
fionaxu0152e512016-11-14 13:36:14 -08003143 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144 final long identity = Binder.clearCallingIdentity();
3145 try {
3146 if (phone != null) {
3147 return phone.getVoiceActivationState();
3148 } else {
3149 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3150 }
3151 } finally {
3152 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003153 }
3154 }
3155
3156 /**
3157 * Returns the data activation state of a given subId.
3158 */
3159 @Override
3160 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003161 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003162
fionaxu0152e512016-11-14 13:36:14 -08003163 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164 final long identity = Binder.clearCallingIdentity();
3165 try {
3166 if (phone != null) {
3167 return phone.getDataActivationState();
3168 } else {
3169 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3170 }
3171 } finally {
3172 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003173 }
3174 }
3175
3176 /**
Wink Saville36469e72014-06-11 15:17:00 -07003177 * Returns the unread count of voicemails for a subId
3178 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003180 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3181 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003182 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003183 mApp, subId, callingPackage, callingFeatureId,
3184 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003185 return 0;
3186 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003187 final long identity = Binder.clearCallingIdentity();
3188 try {
3189 final Phone phone = getPhone(subId);
3190 if (phone != null) {
3191 return phone.getVoiceMessageCount();
3192 } else {
3193 return 0;
3194 }
3195 } finally {
3196 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003197 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003198 }
3199
3200 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003201 * returns true, if the device is in a state where both voice and data
3202 * are supported simultaneously. This can change based on location or network condition.
3203 */
3204 @Override
3205 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003206 final long identity = Binder.clearCallingIdentity();
3207 try {
3208 final Phone phone = getPhone(subId);
3209 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3210 } finally {
3211 Binder.restoreCallingIdentity(identity);
3212 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003213 }
3214
3215 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003216 * Send the dialer code if called from the current default dialer or the caller has
3217 * carrier privilege.
3218 * @param inputCode The dialer code to send
3219 */
3220 @Override
3221 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003222 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003223 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003224 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3225 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003226 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003227 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003228 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003229 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003230
3231 final long identity = Binder.clearCallingIdentity();
3232 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003233 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003234 } finally {
3235 Binder.restoreCallingIdentity(identity);
3236 }
fionaxu235cc5e2017-03-06 22:25:57 -08003237 }
3238
Pengquan Menga1bb6272018-09-06 09:59:22 -07003239 @Override
3240 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003241 TelephonyPermissions
3242 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3243 mApp, subId, "getNetworkSelectionMode");
3244 final long identity = Binder.clearCallingIdentity();
3245 try {
3246 if (!isActiveSubscription(subId)) {
3247 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3248 }
3249 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3250 } finally {
3251 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003252 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003253 }
3254
Brad Ebinger35c841c2018-10-01 10:40:55 -07003255 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003256 public boolean isInEmergencySmsMode() {
3257 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3258 final long identity = Binder.clearCallingIdentity();
3259 try {
3260 for (Phone phone : PhoneFactory.getPhones()) {
3261 if (phone.isInEmergencySmsMode()) {
3262 return true;
3263 }
3264 }
3265 } finally {
3266 Binder.restoreCallingIdentity(identity);
3267 }
3268 return false;
3269 }
3270
shilu366312e2019-12-17 09:28:10 -08003271 /**
3272 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3273 * @param subId The subscription to use to check the configuration.
3274 * @param c The callback that will be used to send the result.
3275 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003276 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003277 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3278 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003279 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3280 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003281
Brad Ebinger77b832e2019-10-17 17:03:22 -07003282 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3283 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3284 "IMS not available on device.");
3285 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003286 final long token = Binder.clearCallingIdentity();
3287 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003288 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003289 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003290 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003291 } catch (ImsException e) {
3292 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003293 } finally {
3294 Binder.restoreCallingIdentity(token);
3295 }
3296 }
3297
shilu366312e2019-12-17 09:28:10 -08003298 /**
3299 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3300 * @param subId The subscription to use to check the configuration.
3301 * @param c The callback that will be used to send the result.
3302 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003303 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003304 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003305 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3306 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003307 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3308 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3309 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003310 final long token = Binder.clearCallingIdentity();
3311 try {
3312 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3313 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3314 .removeRegistrationCallbackForSubscription(c, subId);
3315 } catch (ImsException e) {
3316 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3317 + "is inactive, ignoring unregister.");
3318 // If the subscription is no longer active, just return, since the callback
3319 // will already have been removed internally.
3320 } finally {
3321 Binder.restoreCallingIdentity(token);
3322 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003323 }
3324
Brad Ebinger774ba362019-10-22 17:36:18 -07003325 /**
3326 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3327 */
3328 @Override
3329 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3330 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3331 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3332 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3333 "IMS not available on device.");
3334 }
3335 final long token = Binder.clearCallingIdentity();
3336 try {
3337 Phone phone = getPhone(subId);
3338 if (phone == null) {
3339 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3340 + subId + "'");
3341 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3342 }
3343 phone.getImsRegistrationState(regState -> {
3344 try {
3345 consumer.accept((regState == null)
3346 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3347 } catch (RemoteException e) {
3348 // Ignore if the remote process is no longer available to call back.
3349 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3350 }
3351 });
3352 } finally {
3353 Binder.restoreCallingIdentity(token);
3354 }
3355 }
3356
3357 /**
3358 * Get the transport type for the IMS service registration state.
3359 */
3360 @Override
3361 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003362 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3363 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003364 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3365 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3366 "IMS not available on device.");
3367 }
3368 final long token = Binder.clearCallingIdentity();
3369 try {
3370 Phone phone = getPhone(subId);
3371 if (phone == null) {
3372 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3373 + subId + "'");
3374 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3375 }
3376 phone.getImsRegistrationTech(regTech -> {
3377 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3378 int regTechConverted = (regTech == null)
3379 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3380 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3381 regTechConverted);
3382 try {
3383 consumer.accept(regTechConverted);
3384 } catch (RemoteException e) {
3385 // Ignore if the remote process is no longer available to call back.
3386 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3387 }
3388 });
3389 } finally {
3390 Binder.restoreCallingIdentity(token);
3391 }
3392 }
3393
shilu366312e2019-12-17 09:28:10 -08003394 /**
3395 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3396 * @param subId The subscription to use to check the configuration.
3397 * @param c The callback that will be used to send the result.
3398 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003399 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003400 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3401 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003402 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3403 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003404 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3405 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3406 "IMS not available on device.");
3407 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003408 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3409 final long token = Binder.clearCallingIdentity();
3410 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003411 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003412 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003413 } catch (ImsException e) {
3414 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003415 } finally {
3416 Binder.restoreCallingIdentity(token);
3417 }
3418 }
3419
shilu366312e2019-12-17 09:28:10 -08003420 /**
3421 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3422 * @param subId The subscription to use to check the configuration.
3423 * @param c The callback that will be used to send the result.
3424 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003425 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003426 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003427 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3428 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003429 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3430 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3431 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003432
3433 final long token = Binder.clearCallingIdentity();
3434 try {
3435 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3436 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003437 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003438 } catch (ImsException e) {
3439 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3440 + "is inactive, ignoring unregister.");
3441 // If the subscription is no longer active, just return, since the callback
3442 // will already have been removed internally.
3443 } finally {
3444 Binder.restoreCallingIdentity(token);
3445 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003446 }
3447
3448 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003449 public boolean isCapable(int subId, int capability, int regTech) {
3450 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003451 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3452 final long token = Binder.clearCallingIdentity();
3453 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003454 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003455 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003456 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3458 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003459 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003460 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3461 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003462 } finally {
3463 Binder.restoreCallingIdentity(token);
3464 }
3465 }
3466
3467 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003468 public boolean isAvailable(int subId, int capability, int regTech) {
3469 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003470 final long token = Binder.clearCallingIdentity();
3471 try {
3472 Phone phone = getPhone(subId);
3473 if (phone == null) return false;
3474 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003475 } catch (com.android.ims.ImsException e) {
3476 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3477 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003478 } finally {
3479 Binder.restoreCallingIdentity(token);
3480 }
3481 }
3482
Brad Ebinger77b832e2019-10-17 17:03:22 -07003483 /**
3484 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3485 * subscription.
3486 * @param subId The subscription to use to check the configuration.
3487 * @param callback The callback that will be used to send the result.
3488 * @param capability The MmTelFeature capability that will be used to send the result.
3489 * @param transportType The transport type of the MmTelFeature capability.
3490 */
3491 @Override
3492 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3493 int transportType) {
3494 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3495 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3496 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3497 "IMS not available on device.");
3498 }
3499 final long token = Binder.clearCallingIdentity();
3500 try {
3501 int slotId = getSlotIndex(subId);
3502 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3503 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3504 + subId + "'");
3505 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3506 }
3507 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3508 transportType, aBoolean -> {
3509 try {
3510 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3511 } catch (RemoteException e) {
3512 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3513 + "running. Ignore");
3514 }
3515 });
3516 } finally {
3517 Binder.restoreCallingIdentity(token);
3518 }
3519 }
3520
shilu366312e2019-12-17 09:28:10 -08003521 /**
3522 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3523 * @param subId The subscription to use to check the configuration.
3524 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 @Override
3526 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003527 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3528 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003529
Brad Ebinger35c841c2018-10-01 10:40:55 -07003530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3531 final long token = Binder.clearCallingIdentity();
3532 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003533 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003535 } catch (ImsException e) {
3536 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003537 } finally {
3538 Binder.restoreCallingIdentity(token);
3539 }
3540 }
3541
3542 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003543 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003545 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 final long identity = Binder.clearCallingIdentity();
3547 try {
3548 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003549 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003551 } catch (ImsException e) {
3552 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003553 } finally {
3554 Binder.restoreCallingIdentity(identity);
3555 }
3556 }
3557
shilu366312e2019-12-17 09:28:10 -08003558 /**
3559 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3560 * @param subId The subscription to use to check the configuration.
3561 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003562 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003563 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003564 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3565 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003566 final long identity = Binder.clearCallingIdentity();
3567 try {
3568 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003569 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3570 } catch (ImsException e) {
3571 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003572 } finally {
3573 Binder.restoreCallingIdentity(identity);
3574 }
3575 }
3576
3577 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003578 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003579 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003580 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 final long identity = Binder.clearCallingIdentity();
3582 try {
3583 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003584 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003585 } catch (ImsException e) {
3586 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003587 } finally {
3588 Binder.restoreCallingIdentity(identity);
3589 }
3590 }
3591
shilu366312e2019-12-17 09:28:10 -08003592 /**
3593 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3594 * @param subId The subscription to use to check the configuration.
3595 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 @Override
3597 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003598 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3599 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003600 final long identity = Binder.clearCallingIdentity();
3601 try {
3602 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003603 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003605 } catch (ImsException e) {
3606 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003607 } finally {
3608 Binder.restoreCallingIdentity(identity);
3609 }
3610 }
3611
3612 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003613 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003614 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003615 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 final long identity = Binder.clearCallingIdentity();
3617 try {
3618 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003619 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003620 } catch (ImsException e) {
3621 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003622 } finally {
3623 Binder.restoreCallingIdentity(identity);
3624 }
3625 }
3626
shilu366312e2019-12-17 09:28:10 -08003627 /**
3628 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3629 * @param subId The subscription to use to check the configuration.
3630 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 @Override
3632 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003633 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3634 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003635 final long identity = Binder.clearCallingIdentity();
3636 try {
3637 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003638 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003640 } catch (ImsException e) {
3641 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003642 } finally {
3643 Binder.restoreCallingIdentity(identity);
3644 }
3645 }
3646
3647 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003648 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003649 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003650 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003651 final long identity = Binder.clearCallingIdentity();
3652 try {
3653 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003654 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003655 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003656 } catch (ImsException e) {
3657 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003658 } finally {
3659 Binder.restoreCallingIdentity(identity);
3660 }
3661 }
3662
3663 @Override
3664 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3665 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3666 "setVoWiFiNonPersistent");
3667 final long identity = Binder.clearCallingIdentity();
3668 try {
3669 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003670 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003671 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003672 } catch (ImsException e) {
3673 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003674 } finally {
3675 Binder.restoreCallingIdentity(identity);
3676 }
3677 }
3678
shilu366312e2019-12-17 09:28:10 -08003679 /**
3680 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3681 * @param subId The subscription to use to check the configuration.
3682 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003683 @Override
3684 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003685 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3686 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003687 final long identity = Binder.clearCallingIdentity();
3688 try {
3689 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003690 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003691 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003692 } catch (ImsException e) {
3693 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003694 } finally {
3695 Binder.restoreCallingIdentity(identity);
3696 }
3697 }
3698
3699 @Override
3700 public void setVoWiFiModeSetting(int subId, int mode) {
3701 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3702 "setVoWiFiModeSetting");
3703 final long identity = Binder.clearCallingIdentity();
3704 try {
3705 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003706 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003708 } catch (ImsException e) {
3709 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 } finally {
3711 Binder.restoreCallingIdentity(identity);
3712 }
3713 }
3714
3715 @Override
3716 public int getVoWiFiRoamingModeSetting(int subId) {
3717 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3718 final long identity = Binder.clearCallingIdentity();
3719 try {
3720 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003721 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003722 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003723 } catch (ImsException e) {
3724 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003725 } finally {
3726 Binder.restoreCallingIdentity(identity);
3727 }
3728 }
3729
3730 @Override
3731 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3732 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3733 "setVoWiFiRoamingModeSetting");
3734 final long identity = Binder.clearCallingIdentity();
3735 try {
3736 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003737 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003739 } catch (ImsException e) {
3740 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003741 } finally {
3742 Binder.restoreCallingIdentity(identity);
3743 }
3744 }
3745
3746 @Override
3747 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3748 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3749 "setRttCapabilityEnabled");
3750 final long identity = Binder.clearCallingIdentity();
3751 try {
3752 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003753 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3754 } catch (ImsException e) {
3755 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003756 } finally {
3757 Binder.restoreCallingIdentity(identity);
3758 }
3759 }
3760
shilu366312e2019-12-17 09:28:10 -08003761 /**
3762 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3763 * @param subId The subscription to use to check the configuration.
3764 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003765 @Override
3766 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003767 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3768 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003769 final long identity = Binder.clearCallingIdentity();
3770 try {
3771 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003772 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003773 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003774 } catch (ImsException e) {
3775 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003776 } finally {
3777 Binder.restoreCallingIdentity(identity);
3778 }
3779 }
3780
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003781 @Override
3782 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3783 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3784 final long identity = Binder.clearCallingIdentity();
3785 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003786 if (!isImsAvailableOnDevice()) {
3787 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3788 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003789 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003791 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003792 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 } catch (ImsException e) {
3794 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003795 } finally {
3796 Binder.restoreCallingIdentity(identity);
3797 }
3798 }
3799
3800 @Override
3801 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3802 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3803 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003804 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3805 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3806 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003807 try {
3808 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003809 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003810 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003811 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003812 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3813 + "is inactive, ignoring unregister.");
3814 // If the subscription is no longer active, just return, since the callback will already
3815 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003816 } finally {
3817 Binder.restoreCallingIdentity(identity);
3818 }
3819 }
3820
allenwtsu99c623b2020-01-03 18:24:23 +08003821
3822 private void checkModifyPhoneStatePermission(int subId, String message) {
3823 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3824 message);
3825 }
3826
3827 private boolean isImsProvisioningRequired(int subId, int capability,
3828 boolean isMmtelCapability) {
3829 Phone phone = getPhone(subId);
3830 if (phone == null) {
3831 loge("phone instance null for subid " + subId);
3832 return false;
3833 }
3834 if (isMmtelCapability) {
3835 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3836 return false;
3837 }
3838 } else {
3839 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3840 return false;
3841 }
3842 }
3843 return true;
3844 }
3845
3846 @Override
3847 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3848 boolean isProvisioned) {
3849 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3850
3851 final long identity = Binder.clearCallingIdentity();
3852 try {
3853 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3854 if (!isImsProvisioningRequired(subId, capability, false)) {
3855 return;
3856 }
3857
3858 // this capability requires provisioning, route to the correct API.
3859 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3860 switch (capability) {
3861 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3862 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3863 ims.setEabProvisioned(isProvisioned);
3864 break;
3865 default: {
3866 throw new IllegalArgumentException("Tried to set provisioning for "
3867 + "rcs capability '" + capability + "', which does not require "
3868 + "provisioning.");
3869 }
3870 }
3871 } finally {
3872 Binder.restoreCallingIdentity(identity);
3873 }
3874
3875 }
3876
3877
3878 @Override
3879 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3880 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3881 final long identity = Binder.clearCallingIdentity();
3882 try {
3883 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3884 if (!isImsProvisioningRequired(subId, capability, false)) {
3885 return true;
3886 }
3887
3888 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3889 switch (capability) {
3890 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3891 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3892 return ims.isEabProvisionedOnDevice();
3893
3894 default: {
3895 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3896 + "capability '" + capability + "', which does not require "
3897 + "provisioning.");
3898 }
3899 }
3900
3901 } finally {
3902 Binder.restoreCallingIdentity(identity);
3903 }
3904 }
3905
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003906 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003907 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3908 boolean isProvisioned) {
3909 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3910 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3911 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3912 }
allenwtsu99c623b2020-01-03 18:24:23 +08003913 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003914 final long identity = Binder.clearCallingIdentity();
3915 try {
3916 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003917 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003918 return;
3919 }
3920
3921 // this capability requires provisioning, route to the correct API.
3922 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3923 switch (capability) {
3924 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3925 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3926 ims.setVolteProvisioned(isProvisioned);
3927 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3928 ims.setWfcProvisioned(isProvisioned);
3929 }
3930 break;
3931 }
3932 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3933 // There is currently no difference in VT provisioning type.
3934 ims.setVtProvisioned(isProvisioned);
3935 break;
3936 }
3937 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3938 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3939 // change the capability of the feature instead if needed.
3940 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3941 == isProvisioned) {
3942 // No change in provisioning.
3943 return;
3944 }
3945 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3946 try {
3947 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003948 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003949 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3950 + ", Exception" + e.getMessage());
3951 }
3952 break;
3953 }
3954 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003955 throw new IllegalArgumentException("Tried to set provisioning for "
3956 + "MmTel capability '" + capability + "', which does not require "
3957 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003958 }
3959 }
3960
3961 } finally {
3962 Binder.restoreCallingIdentity(identity);
3963 }
3964 }
3965
3966 @Override
3967 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3968 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3969 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3970 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3971 }
3972 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3973 final long identity = Binder.clearCallingIdentity();
3974 try {
3975 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003976 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003977 return true;
3978 }
3979
3980 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3981 switch (capability) {
3982 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3983 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3984 return ims.isVolteProvisionedOnDevice();
3985 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3986 return ims.isWfcProvisionedOnDevice();
3987 }
3988 // This should never happen, since we are checking tech above to make sure it
3989 // is either LTE or IWLAN.
3990 throw new IllegalArgumentException("Invalid radio technology for voice "
3991 + "capability.");
3992 }
3993 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3994 // There is currently no difference in VT provisioning type.
3995 return ims.isVtProvisionedOnDevice();
3996 }
3997 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3998 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3999 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4000 }
4001 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004002 throw new IllegalArgumentException(
4003 "Tried to get provisioning for MmTel capability '" + capability
4004 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004005 }
4006 }
4007
4008 } finally {
4009 Binder.restoreCallingIdentity(identity);
4010 }
4011 }
4012
4013 @Override
4014 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4015 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4016 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4017 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4018 }
4019 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4020 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4021 return (provisionedBits & capability) > 0;
4022 }
4023
4024 @Override
4025 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4026 boolean isProvisioned) {
4027 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4028 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4029 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4030 }
4031 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4032 "setProvisioningStatusForCapability");
4033 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4034 // If the current provisioning status for capability already matches isProvisioned,
4035 // do nothing.
4036 if (((provisionedBits & capability) > 0) == isProvisioned) {
4037 return;
4038 }
4039 if (isProvisioned) {
4040 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4041 } else {
4042 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4043 }
4044 }
4045
4046 /**
4047 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4048 * technology. The bitfield should mirror the bitfield defined by
4049 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4050 */
4051 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4052 String key = getMmTelProvisioningKey(subId, tech);
4053 // Default is no capabilities are provisioned.
4054 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4055 }
4056
4057 /**
4058 * Sets the MmTel capability provisioning bitfield (defined by
4059 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4060 * technology specified.
4061 *
4062 * Note: This is a synchronous command and should not be called on UI thread.
4063 */
4064 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4065 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4066 String key = getMmTelProvisioningKey(subId, tech);
4067 editor.putInt(key, newField);
4068 editor.commit();
4069 }
4070
4071 private static String getMmTelProvisioningKey(int subId, int tech) {
4072 // resulting key is provision_ims_mmtel_{subId}_{tech}
4073 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4074 }
4075
4076 /**
4077 * Query CarrierConfig to see if the specified capability requires provisioning for the
4078 * carrier associated with the subscription id.
4079 */
4080 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4081 int capability) {
4082 CarrierConfigManager configManager = new CarrierConfigManager(context);
4083 PersistableBundle c = configManager.getConfigForSubId(subId);
4084 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004085 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004086 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4087 false);
4088 boolean requireVoiceVtProvisioning = c.getBoolean(
4089 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4090
4091 // First check to make sure that the capability requires provisioning.
4092 switch (capability) {
4093 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4094 // intentional fallthrough
4095 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4096 if (requireVoiceVtProvisioning) {
4097 // Voice and Video requires provisioning
4098 return true;
4099 }
4100 break;
4101 }
4102 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4103 if (requireUtProvisioning) {
4104 // UT requires provisioning
4105 return true;
4106 }
4107 break;
4108 }
4109 }
4110 return false;
4111 }
4112
allenwtsu99c623b2020-01-03 18:24:23 +08004113 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4114 int capability) {
4115 CarrierConfigManager configManager = new CarrierConfigManager(context);
4116 PersistableBundle c = configManager.getConfigForSubId(subId);
4117
4118 boolean requireRcsProvisioning = c.getBoolean(
4119 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4120
4121 // First check to make sure that the capability requires provisioning.
4122 switch (capability) {
4123 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4124 // intentional fallthrough
4125 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4126 if (requireRcsProvisioning) {
4127 // OPTION or PRESENCE requires provisioning
4128 return true;
4129 }
4130 break;
4131 }
4132 }
4133 return false;
4134 }
4135
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004136 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004137 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4139 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4140 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004141 enforceReadPrivilegedPermission("getImsProvisioningInt");
4142 final long identity = Binder.clearCallingIdentity();
4143 try {
4144 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004145 int slotId = getSlotIndex(subId);
4146 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4147 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4148 + subId + "' for key:" + key);
4149 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4150 }
4151 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004152 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004153 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4154 + subId + "' for key:" + key);
4155 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004156 } finally {
4157 Binder.restoreCallingIdentity(identity);
4158 }
4159 }
4160
4161 @Override
4162 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004163 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4164 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4165 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004166 enforceReadPrivilegedPermission("getImsProvisioningString");
4167 final long identity = Binder.clearCallingIdentity();
4168 try {
4169 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 int slotId = getSlotIndex(subId);
4171 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4172 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4173 + subId + "' for key:" + key);
4174 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4175 }
4176 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004177 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4179 + subId + "' for key:" + key);
4180 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004181 } finally {
4182 Binder.restoreCallingIdentity(identity);
4183 }
4184 }
4185
4186 @Override
4187 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004188 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4189 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4190 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004191 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4192 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004193 final long identity = Binder.clearCallingIdentity();
4194 try {
4195 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004196 int slotId = getSlotIndex(subId);
4197 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4198 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4199 + subId + "' for key:" + key);
4200 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4201 }
4202 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004203 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004204 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4205 + "' for key:" + key);
4206 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 } finally {
4208 Binder.restoreCallingIdentity(identity);
4209 }
4210 }
4211
4212 @Override
4213 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004214 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4215 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4216 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004217 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4218 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004219 final long identity = Binder.clearCallingIdentity();
4220 try {
4221 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004222 int slotId = getSlotIndex(subId);
4223 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4224 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4225 + subId + "' for key:" + key);
4226 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4227 }
4228 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004230 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4231 + "' for key:" + key);
4232 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004233 } finally {
4234 Binder.restoreCallingIdentity(identity);
4235 }
4236 }
4237
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004238 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004239 int slotId = SubscriptionManager.getSlotIndex(subId);
4240 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004241 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4242 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004243 }
4244 return slotId;
4245 }
4246
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004247 private int getSlotIndex(int subId) {
4248 int slotId = SubscriptionManager.getSlotIndex(subId);
4249 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4250 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4251 }
4252 return slotId;
4253 }
4254
Wink Saville36469e72014-06-11 15:17:00 -07004255 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004256 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004257 */
4258 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004259 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4260 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004261 final int targetSdk = getTargetSdk(callingPackage);
4262 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004263 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004264 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004265 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004266 mApp, subId, callingPackage, callingFeatureId,
4267 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004268 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4269 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004270
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004271 final long identity = Binder.clearCallingIdentity();
4272 try {
4273 final Phone phone = getPhone(subId);
4274 if (phone != null) {
4275 return phone.getServiceState().getDataNetworkType();
4276 } else {
4277 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4278 }
4279 } finally {
4280 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004281 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004282 }
4283
4284 /**
4285 * Returns the data network type
4286 */
4287 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004288 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4289 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4290 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004291 }
4292
4293 /**
4294 * Returns the data network type for a subId
4295 */
4296 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004297 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4298 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004299 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004300 mApp, subId, callingPackage, callingFeatureId,
4301 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004302 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4303 }
4304
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004305 final long identity = Binder.clearCallingIdentity();
4306 try {
4307 final Phone phone = getPhone(subId);
4308 if (phone != null) {
4309 return phone.getServiceState().getDataNetworkType();
4310 } else {
4311 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4312 }
4313 } finally {
4314 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004315 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004316 }
4317
4318 /**
Wink Saville36469e72014-06-11 15:17:00 -07004319 * Returns the Voice network type for a subId
4320 */
4321 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004322 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4323 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004324 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004325 mApp, subId, callingPackage, callingFeatureId,
4326 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004327 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4328 }
4329
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004330 final long identity = Binder.clearCallingIdentity();
4331 try {
4332 final Phone phone = getPhone(subId);
4333 if (phone != null) {
4334 return phone.getServiceState().getVoiceNetworkType();
4335 } else {
4336 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4337 }
4338 } finally {
4339 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004340 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004341 }
4342
4343 /**
4344 * @return true if a ICC card is present
4345 */
4346 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004347 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004348 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4349 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004350 }
4351
4352 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004353 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004354 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004355 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004356 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004357 final long identity = Binder.clearCallingIdentity();
4358 try {
4359 final Phone phone = PhoneFactory.getPhone(slotIndex);
4360 if (phone != null) {
4361 return phone.getIccCard().hasIccCard();
4362 } else {
4363 return false;
4364 }
4365 } finally {
4366 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004367 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004368 }
4369
4370 /**
4371 * Return if the current radio is LTE on CDMA. This
4372 * is a tri-state return value as for a period of time
4373 * the mode may be unknown.
4374 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004375 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004376 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004377 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004378 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004379 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004380 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4381 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4382 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004383 }
4384
Sanket Padawe356d7632015-06-22 14:03:32 -07004385 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004386 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4387 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004388 try {
4389 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4390 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004391 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4392 }
4393
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004394 final long identity = Binder.clearCallingIdentity();
4395 try {
4396 final Phone phone = getPhone(subId);
4397 if (phone == null) {
4398 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4399 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004400 return TelephonyProperties.lte_on_cdma_device()
4401 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004402 }
4403 } finally {
4404 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004405 }
Wink Saville36469e72014-06-11 15:17:00 -07004406 }
4407
Wink Saville36469e72014-06-11 15:17:00 -07004408 /**
4409 * {@hide}
4410 * Returns Default subId, 0 in the case of single standby.
4411 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004412 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004413 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004414 }
4415
Shishir Agrawala9f32182016-04-12 12:00:16 -07004416 private int getSlotForDefaultSubscription() {
4417 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4418 }
4419
Wink Savilleb564aae2014-10-23 10:18:09 -07004420 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004421 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004422 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004423
Pengquan Menge92a50d2018-09-21 15:54:48 -07004424 private boolean isActiveSubscription(int subId) {
4425 return mSubscriptionController.isActiveSubId(subId);
4426 }
4427
Ihab Awadf2177b72013-11-25 13:33:23 -08004428 /**
4429 * @see android.telephony.TelephonyManager.WifiCallingChoices
4430 */
4431 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004432 final long identity = Binder.clearCallingIdentity();
4433 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004434 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004435 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4436 getWhenToMakeWifiCallsDefaultPreference());
4437 } finally {
4438 Binder.restoreCallingIdentity(identity);
4439 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004440 }
4441
4442 /**
4443 * @see android.telephony.TelephonyManager.WifiCallingChoices
4444 */
4445 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004446 final long identity = Binder.clearCallingIdentity();
4447 try {
4448 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004449 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004450 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4451 } finally {
4452 Binder.restoreCallingIdentity(identity);
4453 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004454 }
4455
Sailesh Nepald1e68152013-12-12 19:08:02 -08004456 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004457 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004458 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004459 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004460
Jordan Liu4c733742019-02-28 12:03:40 -08004461 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4462 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4463 if (phoneId == -1) {
4464 throw new IllegalArgumentException("Given slot index: " + slotIndex
4465 + " does not correspond to an active phone");
4466 }
4467 return PhoneFactory.getPhone(phoneId);
4468 }
4469
Shishir Agrawal566b7612013-10-28 14:41:00 -07004470 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004471 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4472 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004473 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4474 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004476 if (DBG) {
4477 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4478 }
4479 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4480 p2);
4481 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004482
Jordan Liu4c733742019-02-28 12:03:40 -08004483
4484 @Override
4485 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4486 int slotIndex, String callingPackage, String aid, int p2) {
4487 enforceModifyPermission();
4488 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4489 if (DBG) {
4490 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4491 }
4492 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4493 callingPackage, aid, p2);
4494 }
4495
4496 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4497 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004498 final long identity = Binder.clearCallingIdentity();
4499 try {
4500 if (TextUtils.equals(ISDR_AID, aid)) {
4501 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004502 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4503 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004504 if (bestComponent == null
4505 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4506 loge("The calling package is not allowed to access ISD-R.");
4507 throw new SecurityException(
4508 "The calling package is not allowed to access ISD-R.");
4509 }
Derek Tan740e1672017-06-27 14:56:27 -07004510 }
Derek Tan740e1672017-06-27 14:56:27 -07004511
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004512 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004513 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4514 null /* workSource */);
4515 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004516 return response;
4517 } finally {
4518 Binder.restoreCallingIdentity(identity);
4519 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004520 }
4521
4522 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004523 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004524 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4525 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004526 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4527 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4528 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004529
Jordan Liu4c733742019-02-28 12:03:40 -08004530 @Override
4531 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4532 enforceModifyPermission();
4533 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4534 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4535 channel);
4536 }
4537
4538 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004539 final long identity = Binder.clearCallingIdentity();
4540 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 if (channel < 0) {
4542 return false;
4543 }
Jordan Liu4c733742019-02-28 12:03:40 -08004544 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4545 null /* workSource */);
4546 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004547 return success;
4548 } finally {
4549 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004550 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004551 }
4552
4553 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004554 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004555 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004556 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4557 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004558 if (DBG) {
4559 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4560 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4561 + p3 + " data=" + data);
4562 }
4563 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4564 command, p1, p2, p3, data);
4565 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004566
Jordan Liu4c733742019-02-28 12:03:40 -08004567 @Override
4568 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4569 int command, int p1, int p2, int p3, String data) {
4570 enforceModifyPermission();
4571 if (DBG) {
4572 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4573 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4574 + p3 + " data=" + data);
4575 }
4576 return iccTransmitApduLogicalChannelWithPermission(
4577 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4578 data);
4579 }
4580
4581 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4582 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004583 final long identity = Binder.clearCallingIdentity();
4584 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004585 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004586 return "";
4587 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004588
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004589 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004590 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4591 null /* workSource */);
4592 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004593
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004594 // Append the returned status code to the end of the response payload.
4595 String s = Integer.toHexString(
4596 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4597 if (response.payload != null) {
4598 s = IccUtils.bytesToHexString(response.payload) + s;
4599 }
4600 return s;
4601 } finally {
4602 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004603 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004604 }
Jake Hambye994d462014-02-03 13:10:13 -08004605
Evan Charltonc66da362014-05-16 14:06:40 -07004606 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004607 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4608 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004609 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4610 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004611 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004612 if (DBG) {
4613 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4614 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4615 }
4616 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4617 cla, command, p1, p2, p3, data);
4618 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004619
Jordan Liu4c733742019-02-28 12:03:40 -08004620 @Override
4621 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4622 int command, int p1, int p2, int p3, String data) {
4623 enforceModifyPermission();
4624 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4625 if (DBG) {
4626 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4627 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4628 + " data=" + data);
4629 }
4630
4631 return iccTransmitApduBasicChannelWithPermission(
4632 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4633 p2, p3, data);
4634 }
4635
4636 // open APDU basic channel assuming the caller has sufficient permissions
4637 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4638 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004639 final long identity = Binder.clearCallingIdentity();
4640 try {
4641 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4642 && TextUtils.equals(ISDR_AID, data)) {
4643 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004644 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4645 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 if (bestComponent == null
4647 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4648 loge("The calling package is not allowed to select ISD-R.");
4649 throw new SecurityException(
4650 "The calling package is not allowed to select ISD-R.");
4651 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004652 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004653
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004654 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004655 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4656 null /* workSource */);
4657 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004658
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004659 // Append the returned status code to the end of the response payload.
4660 String s = Integer.toHexString(
4661 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4662 if (response.payload != null) {
4663 s = IccUtils.bytesToHexString(response.payload) + s;
4664 }
4665 return s;
4666 } finally {
4667 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004668 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004669 }
4670
4671 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004672 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004673 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004674 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4675 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004676
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004677 final long identity = Binder.clearCallingIdentity();
4678 try {
4679 if (DBG) {
4680 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4681 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4682 }
4683
4684 IccIoResult response =
4685 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4686 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4687 subId);
4688
4689 if (DBG) {
4690 log("Exchange SIM_IO [R]" + response);
4691 }
4692
4693 byte[] result = null;
4694 int length = 2;
4695 if (response.payload != null) {
4696 length = 2 + response.payload.length;
4697 result = new byte[length];
4698 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4699 } else {
4700 result = new byte[length];
4701 }
4702
4703 result[length - 1] = (byte) response.sw2;
4704 result[length - 2] = (byte) response.sw1;
4705 return result;
4706 } finally {
4707 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004708 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004709 }
4710
Nathan Haroldb3014052017-01-25 15:57:32 -08004711 /**
4712 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4713 * on a particular subscription
4714 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004715 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4716 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004717 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004718 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004719 return null;
4720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004721
4722 final long identity = Binder.clearCallingIdentity();
4723 try {
4724 if (appType != TelephonyManager.APPTYPE_USIM
4725 && appType != TelephonyManager.APPTYPE_SIM) {
4726 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4727 return null;
4728 }
4729 Object response = sendRequest(
4730 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4731 if (response instanceof String[]) {
4732 return (String[]) response;
4733 }
yincheng zhaod698b842019-09-06 17:06:54 -07004734 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004735 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004736 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 } finally {
4738 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004739 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004740 }
4741
yincheng zhaod698b842019-09-06 17:06:54 -07004742 /**
4743 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4744 * subscription.
4745 *
4746 * @param subId the id of the subscription.
4747 * @param appType the uicc app type, must be USIM or SIM.
4748 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4749 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004750 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004751 * @return number of fplmns that is successfully written to the SIM.
4752 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004753 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4754 String callingFeatureId) {
4755 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4756 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004757 if (DBG) logv("no permissions for setForbiddenplmns");
4758 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4759 }
4760 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4761 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4762 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4763 }
4764 if (fplmns == null) {
4765 throw new IllegalArgumentException("Fplmn List provided is null");
4766 }
4767 for (String fplmn : fplmns) {
4768 if (!CellIdentity.isValidPlmn(fplmn)) {
4769 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4770 }
4771 }
4772 final long identity = Binder.clearCallingIdentity();
4773 try {
4774 Object response = sendRequest(
4775 CMD_SET_FORBIDDEN_PLMNS,
4776 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4777 subId);
4778 return (int) response;
4779 } finally {
4780 Binder.restoreCallingIdentity(identity);
4781 }
4782 }
4783
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004784 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004785 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004786 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4787 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004788
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004789 final long identity = Binder.clearCallingIdentity();
4790 try {
4791 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4792 if (response.payload == null) {
4793 return "";
4794 }
Evan Charltonc66da362014-05-16 14:06:40 -07004795
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004796 // Append the returned status code to the end of the response payload.
4797 String s = Integer.toHexString(
4798 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4799 s = IccUtils.bytesToHexString(response.payload) + s;
4800 return s;
4801 } finally {
4802 Binder.restoreCallingIdentity(identity);
4803 }
Evan Charltonc66da362014-05-16 14:06:40 -07004804 }
4805
Jake Hambye994d462014-02-03 13:10:13 -08004806 /**
4807 * Read 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 * @return the NV item as a String, or null on error.
4812 */
4813 @Override
4814 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004815 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004816 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4817 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004818
4819 final long identity = Binder.clearCallingIdentity();
4820 try {
4821 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004822 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004823 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4824 return value;
4825 } finally {
4826 Binder.restoreCallingIdentity(identity);
4827 }
Jake Hambye994d462014-02-03 13:10:13 -08004828 }
4829
4830 /**
4831 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4832 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4833 *
4834 * @param itemID the ID of the item to read
4835 * @param itemValue the value to write, as a String
4836 * @return true on success; false on any failure
4837 */
4838 @Override
4839 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004840 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004841 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4842 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004843
4844 final long identity = Binder.clearCallingIdentity();
4845 try {
4846 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4847 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004848 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004849 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4850 return success;
4851 } finally {
4852 Binder.restoreCallingIdentity(identity);
4853 }
Jake Hambye994d462014-02-03 13:10:13 -08004854 }
4855
4856 /**
4857 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4858 * Used for device configuration by some CDMA operators.
4859 *
4860 * @param preferredRoamingList byte array containing the new PRL
4861 * @return true on success; false on any failure
4862 */
4863 @Override
4864 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004865 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4866 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004867
4868 final long identity = Binder.clearCallingIdentity();
4869 try {
4870 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4871 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4872 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4873 return success;
4874 } finally {
4875 Binder.restoreCallingIdentity(identity);
4876 }
Jake Hambye994d462014-02-03 13:10:13 -08004877 }
4878
4879 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004880 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004881 * Used for device configuration by some CDMA operators.
4882 *
chen xu6dac5ab2018-10-26 17:39:23 -07004883 * @param slotIndex - device slot.
4884 *
Jake Hambye994d462014-02-03 13:10:13 -08004885 * @return true on success; false on any failure
4886 */
4887 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004888 public boolean resetModemConfig(int slotIndex) {
4889 Phone phone = PhoneFactory.getPhone(slotIndex);
4890 if (phone != null) {
4891 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4892 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004893
chen xu6dac5ab2018-10-26 17:39:23 -07004894 final long identity = Binder.clearCallingIdentity();
4895 try {
4896 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4897 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4898 return success;
4899 } finally {
4900 Binder.restoreCallingIdentity(identity);
4901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004902 }
chen xu6dac5ab2018-10-26 17:39:23 -07004903 return false;
4904 }
4905
4906 /**
4907 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4908 *
4909 * @param slotIndex - device slot.
4910 *
4911 * @return true on success; false on any failure
4912 */
4913 @Override
4914 public boolean rebootModem(int slotIndex) {
4915 Phone phone = PhoneFactory.getPhone(slotIndex);
4916 if (phone != null) {
4917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4918 mApp, phone.getSubId(), "rebootModem");
4919
4920 final long identity = Binder.clearCallingIdentity();
4921 try {
4922 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4923 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4924 return success;
4925 } finally {
4926 Binder.restoreCallingIdentity(identity);
4927 }
4928 }
4929 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004930 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004931
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004932 public String[] getPcscfAddress(String apnType, String callingPackage,
4933 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004934 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004935 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4936 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004937 return new String[0];
4938 }
4939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004940 final long identity = Binder.clearCallingIdentity();
4941 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004942 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004943 } finally {
4944 Binder.restoreCallingIdentity(identity);
4945 }
Wink Saville36469e72014-06-11 15:17:00 -07004946 }
4947
Brad Ebinger51f743a2017-01-23 13:50:20 -08004948 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004949 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4950 * {@link #disableIms(int)}.
4951 * @param slotIndex device slot.
4952 */
4953 public void resetIms(int slotIndex) {
4954 enforceModifyPermission();
4955
4956 final long identity = Binder.clearCallingIdentity();
4957 try {
4958 if (mImsResolver == null) {
4959 // may happen if the does not support IMS.
4960 return;
4961 }
4962 mImsResolver.disableIms(slotIndex);
4963 mImsResolver.enableIms(slotIndex);
4964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
4967 }
4968
4969 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004970 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4971 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004972 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004978 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004979 // may happen if the device does not support IMS.
4980 return;
4981 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004982 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004986 }
4987
4988 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004989 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4990 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004991 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004992 public void disableIms(int slotId) {
4993 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004994
4995 final long identity = Binder.clearCallingIdentity();
4996 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004997 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004998 // may happen if the device does not support IMS.
4999 return;
5000 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005001 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002 } finally {
5003 Binder.restoreCallingIdentity(identity);
5004 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005005 }
5006
5007 /**
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005008 * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback
5009 * callback.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005010 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005011 @Override
5012 public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback,
5013 boolean oneShot) {
Brad Ebinger34bef922017-11-09 10:27:08 -08005014 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005015
5016 final long identity = Binder.clearCallingIdentity();
5017 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005018 if (mImsResolver == null) {
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005019 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5020 "Device does not support IMS");
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 }
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005022 if (oneShot) {
5023 mImsResolver.callBackIfExists(slotId, ImsFeature.FEATURE_MMTEL, callback);
5024 } else {
5025 mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback);
5026 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005027 } finally {
5028 Binder.restoreCallingIdentity(identity);
5029 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005030 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005031 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005032 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5033 */
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005034 @Override
5035 public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) {
Brad Ebingerab47dd42020-05-18 17:52:58 -07005036 enforceModifyPermission();
5037
5038 final long identity = Binder.clearCallingIdentity();
5039 try {
5040 if (mImsResolver == null) return;
Brad Ebingere3ae65a2020-09-11 12:45:11 -07005041 mImsResolver.unregisterImsFeatureCallback(callback);
Brad Ebingerab47dd42020-05-18 17:52:58 -07005042 } finally {
5043 Binder.restoreCallingIdentity(identity);
5044 }
5045 }
5046
5047 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005048 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005049 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005050 */
5051 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5052 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005053
5054 final long identity = Binder.clearCallingIdentity();
5055 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005056 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005057 // may happen if the device does not support IMS.
5058 return null;
5059 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005060 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005061 } finally {
5062 Binder.restoreCallingIdentity(identity);
5063 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005064 }
5065
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005066 /**
5067 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005068 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005069 */
5070 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5071 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005072
5073 final long identity = Binder.clearCallingIdentity();
5074 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005075 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005076 // may happen if the device does not support IMS.
5077 return null;
5078 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005079 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005080 } finally {
5081 Binder.restoreCallingIdentity(identity);
5082 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005083 }
5084
Brad Ebinger884c07b2018-02-15 16:17:40 -08005085 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005086 * Sets the ImsService Package Name that Telephony will bind to.
5087 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005088 * @param slotIndex the slot ID that the ImsService should bind for.
5089 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005090 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005091 * @param featureTypes An integer array of feature types associated with a packageName.
5092 * @param packageName The name of the package that the current configuration will be replaced
5093 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005094 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005095 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005096 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5097 int[] featureTypes, String packageName) {
5098 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5099 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005100 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5101 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005102 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005103
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005104 final long identity = Binder.clearCallingIdentity();
5105 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005106 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005107 // may happen if the device does not support IMS.
5108 return false;
5109 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005110 Map<Integer, String> featureConfig = new HashMap<>();
5111 for (int featureType : featureTypes) {
5112 featureConfig.put(featureType, packageName);
5113 }
5114 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5115 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005116 } finally {
5117 Binder.restoreCallingIdentity(identity);
5118 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005119 }
5120
5121 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005122 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005123 *
5124 * @param slotId The slot that the ImsService is associated with.
5125 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5126 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005127 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005128 * @return the package name of the ImsService configuration.
5129 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005130 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5131 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005132 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005133 TelephonyPermissions
5134 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5135 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5136 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005138 final long identity = Binder.clearCallingIdentity();
5139 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005140 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005141 // may happen if the device does not support IMS.
5142 return "";
5143 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005144 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005145 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5146 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005147 } finally {
5148 Binder.restoreCallingIdentity(identity);
5149 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005150 }
5151
Brad Ebinger77b832e2019-10-17 17:03:22 -07005152 /**
5153 * Get the MmTelFeature state associated with the requested subscription id.
5154 * @param subId The subscription that the MmTelFeature is associated with.
5155 * @param callback A callback with an integer containing the
5156 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5157 */
5158 @Override
5159 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5160 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5161 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5162 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5163 "IMS not available on device.");
5164 }
5165 final long token = Binder.clearCallingIdentity();
5166 try {
5167 int slotId = getSlotIndex(subId);
5168 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5169 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5170 + subId + "'");
5171 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5172 }
5173 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5174 try {
5175 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5176 } catch (RemoteException e) {
5177 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5178 + "Ignore");
5179 }
5180 });
5181 } finally {
5182 Binder.restoreCallingIdentity(token);
5183 }
5184 }
5185
Wink Saville36469e72014-06-11 15:17:00 -07005186 public void setImsRegistrationState(boolean registered) {
5187 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005188
5189 final long identity = Binder.clearCallingIdentity();
5190 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005191 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005192 } finally {
5193 Binder.restoreCallingIdentity(identity);
5194 }
Wink Saville36469e72014-06-11 15:17:00 -07005195 }
5196
5197 /**
Stuart Scott54788802015-03-30 13:18:01 -07005198 * Set the network selection mode to automatic.
5199 *
5200 */
5201 @Override
5202 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005203 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5204 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005205
5206 final long identity = Binder.clearCallingIdentity();
5207 try {
shilufc958392020-01-20 11:36:01 -08005208 if (!isActiveSubscription(subId)) {
5209 return;
5210 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005211 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5212 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5213 } finally {
5214 Binder.restoreCallingIdentity(identity);
5215 }
Stuart Scott54788802015-03-30 13:18:01 -07005216 }
5217
Pengquan Mengea84e042018-09-20 14:57:26 -07005218 /**
5219 * Ask the radio to connect to the input network and change selection mode to manual.
5220 *
5221 * @param subId the id of the subscription.
5222 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5223 * the operator to attach to.
5224 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5225 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5226 * normal network selection next time.
5227 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005228 */
5229 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005230 public boolean setNetworkSelectionModeManual(
5231 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005232 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5233 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005234
5235 if (!isActiveSubscription(subId)) {
5236 return false;
5237 }
5238
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005239 final long identity = Binder.clearCallingIdentity();
5240 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005241 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005242 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005243 if (DBG) {
5244 log("setNetworkSelectionModeManual: subId: " + subId
5245 + " operator: " + operatorInfo);
5246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5248 } finally {
5249 Binder.restoreCallingIdentity(identity);
5250 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005251 }
shilu84f6e8b2019-12-19 13:58:01 -08005252 /**
5253 * Get the manual network selection
5254 *
5255 * @param subId the id of the subscription.
5256 *
5257 * @return the previously saved user selected PLMN
5258 */
5259 @Override
5260 public String getManualNetworkSelectionPlmn(int subId) {
5261 TelephonyPermissions
5262 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5263 mApp, subId, "getManualNetworkSelectionPlmn");
5264
5265 final long identity = Binder.clearCallingIdentity();
5266 try {
5267 if (!isActiveSubscription(subId)) {
5268 return "";
5269 }
5270
5271 final Phone phone = getPhone(subId);
5272 if (phone == null) {
5273 return "";
5274 }
5275 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5276 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5277 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5278 } finally {
5279 Binder.restoreCallingIdentity(identity);
5280 }
5281 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005282
5283 /**
5284 * Scans for available networks.
5285 */
5286 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005287 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5288 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005289 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5290 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005291 LocationAccessPolicy.LocationPermissionResult locationResult =
5292 LocationAccessPolicy.checkLocationPermission(mApp,
5293 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5294 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005295 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005296 .setCallingPid(Binder.getCallingPid())
5297 .setCallingUid(Binder.getCallingUid())
5298 .setMethod("getCellNetworkScanResults")
5299 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5300 .build());
5301 switch (locationResult) {
5302 case DENIED_HARD:
5303 throw new SecurityException("Not allowed to access scan results -- location");
5304 case DENIED_SOFT:
5305 return null;
5306 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005307
Pengquan Menga1bb6272018-09-06 09:59:22 -07005308 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005309 try {
5310 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005311 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005313 } finally {
5314 Binder.restoreCallingIdentity(identity);
5315 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005316 }
5317
5318 /**
sqian80370722020-01-29 15:02:51 -08005319 * Get the call forwarding info, given the call forwarding reason.
5320 */
5321 @Override
5322 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5323 enforceReadPrivilegedPermission("getCallForwarding");
5324 long identity = Binder.clearCallingIdentity();
5325 try {
5326 if (DBG) {
5327 log("getCallForwarding: subId " + subId
5328 + " callForwardingReason" + callForwardingReason);
5329 }
5330 return (CallForwardingInfo) sendRequest(
5331 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5332 } finally {
5333 Binder.restoreCallingIdentity(identity);
5334 }
5335 }
5336
5337 /**
5338 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5339 * reason, the number to forward, and the timeout before the forwarding is attempted.
5340 */
5341 @Override
5342 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5343 enforceModifyPermission();
5344 long identity = Binder.clearCallingIdentity();
5345 try {
5346 if (DBG) {
5347 log("setCallForwarding: subId " + subId
5348 + " callForwardingInfo" + callForwardingInfo);
5349 }
5350 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5351 } finally {
5352 Binder.restoreCallingIdentity(identity);
5353 }
5354 }
5355
5356 /**
5357 * Get the call forwarding info, given the call forwarding reason.
5358 */
5359 @Override
5360 public int getCallWaitingStatus(int subId) {
5361 enforceReadPrivilegedPermission("getCallForwarding");
5362 long identity = Binder.clearCallingIdentity();
5363 try {
5364 if (DBG) log("getCallWaitingStatus: subId " + subId);
5365 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5366 } finally {
5367 Binder.restoreCallingIdentity(identity);
5368 }
5369 }
5370
5371 /**
5372 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5373 * reason, the number to forward, and the timeout before the forwarding is attempted.
5374 */
5375 @Override
5376 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5377 enforceModifyPermission();
5378 long identity = Binder.clearCallingIdentity();
5379 try {
5380 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5381 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5382 } finally {
5383 Binder.restoreCallingIdentity(identity);
5384 }
5385 }
5386
5387 /**
yinxub1bed742017-04-17 11:45:04 -07005388 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005389 *
yinxub1bed742017-04-17 11:45:04 -07005390 * @param subId id of the subscription
5391 * @param request contains the radio access networks with bands/channels to scan
5392 * @param messenger callback messenger for scan results or errors
5393 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005394 * @return the id of the requested scan which can be used to stop the scan.
5395 */
5396 @Override
5397 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005398 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005399 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5400 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005401 LocationAccessPolicy.LocationPermissionResult locationResult =
5402 LocationAccessPolicy.checkLocationPermission(mApp,
5403 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5404 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005405 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005406 .setCallingPid(Binder.getCallingPid())
5407 .setCallingUid(Binder.getCallingUid())
5408 .setMethod("requestNetworkScan")
5409 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5410 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005411 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005412 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005413 if (e != null) {
5414 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5415 throw e;
5416 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005417 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 return TelephonyScanManager.INVALID_SCAN_ID;
5419 }
5420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 }
Hall Liu912dfd32019-04-25 14:02:26 -07005422 int callingUid = Binder.getCallingUid();
5423 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 return mNetworkScanRequestTracker.startNetworkScan(
5427 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005428 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
yinxu504e1392017-04-12 16:03:22 -07005432 }
5433
Hall Liub2ac8ef2019-02-28 15:56:23 -08005434 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005435 NetworkScanRequest request, int subId) {
5436 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5437 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5438 boolean hasNetworkScanPermission =
5439 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5440 == PERMISSION_GRANTED;
5441
5442 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5443 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5444 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005445 }
5446
5447 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5448 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005449 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5450 return new SecurityException("Specific channels must not be"
5451 + " scanned without location access.");
5452 }
5453 }
5454 }
5455
Hall Liub2ac8ef2019-02-28 15:56:23 -08005456 return null;
5457 }
5458
yinxu504e1392017-04-12 16:03:22 -07005459 /**
5460 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005461 *
5462 * @param subId id of the subscription
5463 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005464 */
5465 @Override
5466 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5468 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
Hall Liu912dfd32019-04-25 14:02:26 -07005470 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005473 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
5476 }
yinxu504e1392017-04-12 16:03:22 -07005477 }
5478
5479 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005480 * Get the calculated preferred network type.
5481 * Used for debugging incorrect network type.
5482 *
5483 * @return the preferred network type, defined in RILConstants.java.
5484 */
5485 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005486 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 final Phone defaultPhone = getDefaultPhone();
5488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005489 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005490 return RILConstants.PREFERRED_NETWORK_MODE;
5491 }
5492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
Junda Liu84d15a22014-07-02 11:21:04 -07005500 }
5501
5502 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005503 * Get the preferred network type.
5504 * Used for device configuration by some CDMA operators.
5505 *
5506 * @return the preferred network type, defined in RILConstants.java.
5507 */
5508 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005509 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005510 TelephonyPermissions
5511 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5512 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513
5514 final long identity = Binder.clearCallingIdentity();
5515 try {
5516 if (DBG) log("getPreferredNetworkType");
5517 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5518 int networkType = (result != null ? result[0] : -1);
5519 if (DBG) log("getPreferredNetworkType: " + networkType);
5520 return networkType;
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005524 }
5525
5526 /**
5527 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005528 *
5529 * @param networkType the preferred network type, defined in RILConstants.java.
5530 * @return true on success; false on any failure.
5531 */
5532 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005533 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5535 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005539 Settings.Global.putInt(mApp.getContentResolver(),
5540 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005541
5542 Boolean success = (Boolean) sendRequest(
5543 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5544 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5545 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005546 } finally {
5547 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005548 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005549 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005550
5551 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005552 * Get the allowed network types that store in the telephony provider.
5553 *
5554 * @param subId the id of the subscription.
5555 * @return allowedNetworkTypes the allowed network types.
5556 */
5557 @Override
5558 public long getAllowedNetworkTypes(int subId) {
5559 TelephonyPermissions
5560 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5561 mApp, subId, "getAllowedNetworkTypes");
5562
5563 final long identity = Binder.clearCallingIdentity();
5564 try {
5565 return SubscriptionManager.getLongSubscriptionProperty(
5566 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5567 } finally {
5568 Binder.restoreCallingIdentity(identity);
5569 }
5570 }
5571
5572 /**
5573 * Set the allowed network types.
5574 *
5575 * @param subId the id of the subscription.
5576 * @param allowedNetworkTypes the allowed network types.
5577 * @return true on success; false on any failure.
5578 */
5579 @Override
5580 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5582 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005583
calvinpan089c2a62020-03-12 14:17:55 +08005584 SubscriptionManager.setSubscriptionProperty(subId,
5585 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5586 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005587
calvinpan089c2a62020-03-12 14:17:55 +08005588 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5589 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5590 RILConstants.PREFERRED_NETWORK_MODE);
5591 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005592 }
5593
5594 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005595 * Get the allowed network types for certain reason.
5596 *
5597 * @param subId the id of the subscription.
5598 * @param reason the reason the allowed network type change is taking place
5599 * @return the allowed network types.
5600 */
5601 @Override
5602 public long getAllowedNetworkTypesForReason(int subId,
5603 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5604 TelephonyPermissions
5605 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5606 mApp, subId, "getAllowedNetworkTypesForReason");
5607 final long identity = Binder.clearCallingIdentity();
5608 try {
5609 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5610 } finally {
5611 Binder.restoreCallingIdentity(identity);
5612 }
5613 }
5614
5615 /**
5616 * Get the effective allowed network types on the device.
5617 * This API will return an intersection of allowed network types for all reasons,
5618 * including the configuration done through setAllowedNetworkTypes
5619 *
5620 * @param subId the id of the subscription.
5621 * @return the allowed network types
5622 */
5623 @Override
5624 public long getEffectiveAllowedNetworkTypes(int subId) {
5625 TelephonyPermissions
5626 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5627 mApp, subId, "getEffectiveAllowedNetworkTypes");
5628 final long identity = Binder.clearCallingIdentity();
5629 try {
5630 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5631 } finally {
5632 Binder.restoreCallingIdentity(identity);
5633 }
5634 }
5635
5636 /**
5637 * Set the allowed network types of the device and
5638 * provide the reason triggering the allowed network change.
5639 *
5640 * @param subId the id of the subscription.
5641 * @param reason the reason the allowed network type change is taking place
5642 * @param allowedNetworkTypes the allowed network types.
5643 * @return true on success; false on any failure.
5644 */
5645 @Override
5646 public boolean setAllowedNetworkTypesForReason(int subId,
5647 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5648 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5649 mApp, subId, "setAllowedNetworkTypesForReason");
5650 final long identity = Binder.clearCallingIdentity();
5651 try {
5652 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5653 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5654 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5655 RILConstants.PREFERRED_NETWORK_MODE);
5656 return setPreferredNetworkType(subId, preferredNetworkMode);
5657 } finally {
5658 Binder.restoreCallingIdentity(identity);
5659 }
5660 }
5661
5662 /**
Miaoa84611c2019-03-15 09:21:10 +08005663 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005664 *
Miaoa84611c2019-03-15 09:21:10 +08005665 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005666 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005667 * @hide
5668 */
5669 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005670 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005671 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005672 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005673 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 try {
Miaoa84611c2019-03-15 09:21:10 +08005675 if (phone != null) {
5676 return phone.hasMatchedTetherApnSetting();
5677 } else {
5678 return false;
5679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005680 } finally {
5681 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005682 }
Junda Liu475951f2014-11-07 16:45:03 -08005683 }
5684
5685 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005686 * Set mobile data enabled
5687 * Used by the user through settings etc to turn on/off mobile data
5688 *
5689 * @param enable {@code true} turn turn data on, else {@code false}
5690 */
5691 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005692 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005693 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5694 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005695
5696 final long identity = Binder.clearCallingIdentity();
5697 try {
5698 int phoneId = mSubscriptionController.getPhoneId(subId);
5699 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5700 Phone phone = PhoneFactory.getPhone(phoneId);
5701 if (phone != null) {
5702 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005703 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005704 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005705 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 }
5707 } finally {
5708 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005709 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005710 }
5711
5712 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005713 * Enable or disable always reporting signal strength changes from radio.
5714 *
5715 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5716 */
5717 @Override
5718 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5719 enforceModifyPermission();
5720 enforceSystemCaller();
5721
5722 final long identity = Binder.clearCallingIdentity();
5723 final Phone phone = getPhone(subId);
5724 try {
5725 if (phone != null) {
5726 if (DBG) {
5727 log("setAlwaysReportSignalStrength: subId=" + subId
5728 + " isEnable=" + isEnable);
5729 }
5730 phone.setAlwaysReportSignalStrength(isEnable);
5731 } else {
5732 loge("setAlwaysReportSignalStrength: no phone found for subId="
5733 + subId);
5734 }
5735 } finally {
5736 Binder.restoreCallingIdentity(identity);
5737 }
5738 }
5739
5740 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005741 * Get the user enabled state of Mobile Data.
5742 *
5743 * TODO: remove and use isUserDataEnabled.
5744 * This can't be removed now because some vendor codes
5745 * calls through ITelephony directly while they should
5746 * use TelephonyManager.
5747 *
5748 * @return true on enabled
5749 */
5750 @Override
5751 public boolean getDataEnabled(int subId) {
5752 return isUserDataEnabled(subId);
5753 }
5754
5755 /**
5756 * Get whether mobile data is enabled per user setting.
5757 *
5758 * There are other factors deciding whether mobile data is actually enabled, but they are
5759 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005760 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005761 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005762 *
5763 * @return {@code true} if data is enabled else {@code false}
5764 */
5765 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005766 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005767 try {
5768 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5769 null);
5770 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005771 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5772 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005773 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005774
5775 final long identity = Binder.clearCallingIdentity();
5776 try {
5777 int phoneId = mSubscriptionController.getPhoneId(subId);
5778 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5779 Phone phone = PhoneFactory.getPhone(phoneId);
5780 if (phone != null) {
5781 boolean retVal = phone.isUserDataEnabled();
5782 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5783 return retVal;
5784 } else {
5785 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5786 return false;
5787 }
5788 } finally {
5789 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005790 }
5791 }
5792
5793 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005794 * Checks if the device is capable of mobile data by considering whether whether the
5795 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5796 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005797 *
Shuo Qian985d1232020-01-08 14:30:06 -08005798 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005799 */
5800 @Override
5801 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005802 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005803
5804 final long identity = Binder.clearCallingIdentity();
5805 try {
5806 int phoneId = mSubscriptionController.getPhoneId(subId);
5807 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5808 Phone phone = PhoneFactory.getPhone(phoneId);
5809 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005810 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005811 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5812 return retVal;
5813 } else {
5814 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5815 return false;
5816 }
5817 } finally {
5818 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005819 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005820 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005821
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005822 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005823 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005824 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5825 // Skip the check if it's one of these special uids
5826 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5827 }
5828
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005829 //load access rules from carrier configs, and check those as well: b/139133814
5830 SubscriptionController subController = SubscriptionController.getInstance();
5831 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5832 || subController == null) return privilegeFromSim;
5833
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005834 PackageManager pkgMgr = phone.getContext().getPackageManager();
5835 String[] packages = pkgMgr.getPackagesForUid(uid);
5836
5837 final long identity = Binder.clearCallingIdentity();
5838 try {
5839 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5840 SubscriptionManager subManager = (SubscriptionManager)
5841 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5842 for (String pkg : packages) {
5843 if (subManager.canManageSubscription(subInfo, pkg)) {
5844 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5845 }
5846 }
5847 return privilegeFromSim;
5848 } finally {
5849 Binder.restoreCallingIdentity(identity);
5850 }
5851 }
5852
5853 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5854 String pkgName) {
5855 //load access rules from carrier configs, and check those as well: b/139133814
5856 SubscriptionController subController = SubscriptionController.getInstance();
5857 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5858 || subController == null) return privilegeFromSim;
5859
5860 final long identity = Binder.clearCallingIdentity();
5861 try {
5862 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5863 SubscriptionManager subManager = (SubscriptionManager)
5864 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5865 return subManager.canManageSubscription(subInfo, pkgName)
5866 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5867 } finally {
5868 Binder.restoreCallingIdentity(identity);
5869 }
5870 }
5871
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005872 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005873 public int getCarrierPrivilegeStatus(int subId) {
5874 final Phone phone = getPhone(subId);
5875 if (phone == null) {
5876 loge("getCarrierPrivilegeStatus: Invalid subId");
5877 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5878 }
5879 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005880 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005881 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005882 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5883 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005884
5885 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5886 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005887 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005888 }
Junda Liu29340342014-07-10 15:23:27 -07005889
5890 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005891 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005892 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005893 final Phone phone = getPhone(subId);
5894 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005895 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005896 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5897 }
5898 UiccProfile profile =
5899 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5900 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005901 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005902 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5903 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005904 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005905 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005906 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005907 }
5908
5909 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005910 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5911 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005912 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005913 }
5914
5915 int phoneId = SubscriptionManager.getPhoneId(subId);
5916 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005917 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005918 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005919 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5920 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005921 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5922 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5923 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005924 }
5925
5926 @Override
5927 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005928 if (TextUtils.isEmpty(pkgName))
5929 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005930 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5931 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5932 UiccCard card = UiccController.getInstance().getUiccCard(i);
5933 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005934 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005935 continue;
5936 }
5937
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005938 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5939 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5940 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005941 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5942 break;
5943 }
5944 }
5945
5946 return result;
Junda Liu29340342014-07-10 15:23:27 -07005947 }
Derek Tan89e89d42014-07-08 17:00:10 -07005948
5949 @Override
Junda Liue64de782015-04-16 17:19:16 -07005950 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5951 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5952 loge("phoneId " + phoneId + " is not valid.");
5953 return null;
5954 }
5955 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005956 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005957 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005958 return null ;
5959 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005960 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005961 }
5962
Amith Yamasani6e118872016-02-19 12:53:51 -08005963 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005964 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005965 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005966 List<String> privilegedPackages = new ArrayList<>();
5967 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005968 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5969 // has UICC in that slot.
5970 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005971 if (card.hasCarrierPrivilegeRules()) {
5972 if (packages == null) {
5973 // Only check packages in user 0 for now
5974 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005975 PackageManager.MATCH_DISABLED_COMPONENTS
5976 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005977 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005978 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005979 }
5980 for (int p = packages.size() - 1; p >= 0; p--) {
5981 PackageInfo pkgInfo = packages.get(p);
5982 if (pkgInfo != null && pkgInfo.packageName != null
5983 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005984 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005985 privilegedPackages.add(pkgInfo.packageName);
5986 }
5987 }
5988 }
5989 }
5990 return privilegedPackages;
5991 }
5992
chen xuf7e9fe82019-05-09 19:31:02 -07005993 @Override
5994 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00005995 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5996
5997 final long identity = Binder.clearCallingIdentity();
5998
chen xuf7e9fe82019-05-09 19:31:02 -07005999 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006000 try {
6001 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6002 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6003 }
6004 } finally {
6005 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006006 }
6007 return privilegedPackages;
6008 }
6009
Wink Savilleb564aae2014-10-23 10:18:09 -07006010 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006011 final Phone phone = getPhone(subId);
6012 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006013 if (card == null) {
6014 loge("getIccId: No UICC");
6015 return null;
6016 }
6017 String iccId = card.getIccId();
6018 if (TextUtils.isEmpty(iccId)) {
6019 loge("getIccId: ICC ID is null or empty.");
6020 return null;
6021 }
6022 return iccId;
6023 }
6024
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006025 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006026 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6027 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006028 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006029 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006030
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006031 final long identity = Binder.clearCallingIdentity();
6032 try {
6033 final String iccId = getIccId(subId);
6034 final Phone phone = getPhone(subId);
6035 if (phone == null) {
6036 return false;
6037 }
6038 final String subscriberId = phone.getSubscriberId();
6039
6040 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006041 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006042 + subscriberId + " to " + number);
6043 }
6044
6045 if (TextUtils.isEmpty(iccId)) {
6046 return false;
6047 }
6048
6049 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6050
6051 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6052 if (alphaTag == null) {
6053 editor.remove(alphaTagPrefKey);
6054 } else {
6055 editor.putString(alphaTagPrefKey, alphaTag);
6056 }
6057
6058 // Record both the line number and IMSI for this ICCID, since we need to
6059 // track all merged IMSIs based on line number
6060 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6061 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6062 if (number == null) {
6063 editor.remove(numberPrefKey);
6064 editor.remove(subscriberPrefKey);
6065 } else {
6066 editor.putString(numberPrefKey, number);
6067 editor.putString(subscriberPrefKey, subscriberId);
6068 }
6069
6070 editor.commit();
6071 return true;
6072 } finally {
6073 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006074 }
Derek Tan7226c842014-07-02 17:42:23 -07006075 }
6076
6077 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006078 public String getLine1NumberForDisplay(int subId, String callingPackage,
6079 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006080 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006081 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006082 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006083 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006084 return null;
6085 }
Derek Tan97ebb422014-09-05 16:55:38 -07006086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006087 final long identity = Binder.clearCallingIdentity();
6088 try {
6089 String iccId = getIccId(subId);
6090 if (iccId != null) {
6091 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6092 if (DBG_MERGE) {
6093 log("getLine1NumberForDisplay returning "
6094 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6095 }
6096 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006097 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006098 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6099 return null;
6100 } finally {
6101 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006102 }
Derek Tan7226c842014-07-02 17:42:23 -07006103 }
6104
6105 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006106 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6107 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006108 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006109 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006110 return null;
6111 }
Derek Tan97ebb422014-09-05 16:55:38 -07006112
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006113 final long identity = Binder.clearCallingIdentity();
6114 try {
6115 String iccId = getIccId(subId);
6116 if (iccId != null) {
6117 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6118 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6119 }
6120 return null;
6121 } finally {
6122 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006123 }
Derek Tan7226c842014-07-02 17:42:23 -07006124 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006125
6126 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006127 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6128 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006129 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6130 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006131 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006132 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006133 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006134 return null;
6135 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006136
Jordan Liub49b04b2019-05-06 14:45:15 -07006137 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6138 // the process, where TelephonyManager was instantiated.
6139 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006140 final long identity = Binder.clearCallingIdentity();
6141 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006142 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006143 final TelephonyManager tele = TelephonyManager.from(context);
6144 final SubscriptionManager sub = SubscriptionManager.from(context);
6145
6146 // Figure out what subscribers are currently active
6147 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006148
Jordan Liub49b04b2019-05-06 14:45:15 -07006149 // Only consider subs which match the current subId
6150 // This logic can be simplified. See b/131189269 for progress.
6151 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006152 activeSubscriberIds.add(tele.getSubscriberId(subId));
6153 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006154
6155 // First pass, find a number override for an active subscriber
6156 String mergeNumber = null;
6157 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6158 for (String key : prefs.keySet()) {
6159 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6160 final String subscriberId = (String) prefs.get(key);
6161 if (activeSubscriberIds.contains(subscriberId)) {
6162 final String iccId = key.substring(
6163 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6164 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6165 mergeNumber = (String) prefs.get(numberKey);
6166 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006167 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 + " for active subscriber " + subscriberId);
6169 }
6170 if (!TextUtils.isEmpty(mergeNumber)) {
6171 break;
6172 }
6173 }
6174 }
6175 }
6176
6177 // Shortcut when no active merged subscribers
6178 if (TextUtils.isEmpty(mergeNumber)) {
6179 return null;
6180 }
6181
6182 // Second pass, find all subscribers under that line override
6183 final ArraySet<String> result = new ArraySet<>();
6184 for (String key : prefs.keySet()) {
6185 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6186 final String number = (String) prefs.get(key);
6187 if (mergeNumber.equals(number)) {
6188 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6189 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6190 final String subscriberId = (String) prefs.get(subscriberKey);
6191 if (!TextUtils.isEmpty(subscriberId)) {
6192 result.add(subscriberId);
6193 }
6194 }
6195 }
6196 }
6197
6198 final String[] resultArray = result.toArray(new String[result.size()]);
6199 Arrays.sort(resultArray);
6200 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006201 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6203 }
6204 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006205 } finally {
6206 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006207 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006208 }
6209
6210 @Override
zoey chen38003472019-12-13 17:16:31 +08006211 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6212 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006213
6214 final long identity = Binder.clearCallingIdentity();
6215 try {
6216 final TelephonyManager telephonyManager = mApp.getSystemService(
6217 TelephonyManager.class);
6218 String subscriberId = telephonyManager.getSubscriberId(subId);
6219 if (subscriberId == null) {
6220 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006221 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006222 + subId);
6223 }
6224 return null;
6225 }
6226
6227 final SubscriptionInfo info = SubscriptionController.getInstance()
6228 .getSubscriptionInfo(subId);
6229 final ParcelUuid groupUuid = info.getGroupUuid();
6230 // If it doesn't belong to any group, return just subscriberId of itself.
6231 if (groupUuid == null) {
6232 return new String[]{subscriberId};
6233 }
6234
6235 // Get all subscriberIds from the group.
6236 final List<String> mergedSubscriberIds = new ArrayList<>();
6237 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006238 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006239 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006240 for (SubscriptionInfo subInfo : groupInfos) {
6241 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6242 if (subscriberId != null) {
6243 mergedSubscriberIds.add(subscriberId);
6244 }
6245 }
6246
6247 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6248 } finally {
6249 Binder.restoreCallingIdentity(identity);
6250
6251 }
6252 }
6253
6254 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006255 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006256 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006257 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006258
6259 final long identity = Binder.clearCallingIdentity();
6260 try {
6261 final Phone phone = getPhone(subId);
6262 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6263 } finally {
6264 Binder.restoreCallingIdentity(identity);
6265 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006266 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006267
6268 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006269 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006270 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6271 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006272 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6273 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006274
6275 final long identity = Binder.clearCallingIdentity();
6276 try {
6277 final Phone phone = getPhone(subId);
6278 if (phone == null) {
6279 return false;
6280 }
6281 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6282 cdmaNonRoamingList);
6283 } finally {
6284 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006285 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006286 }
6287
6288 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006289 @Deprecated
6290 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6291 enforceModifyPermission();
6292
6293 int returnValue = 0;
6294 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006295 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006296 if(result.exception == null) {
6297 if (result.result != null) {
6298 byte[] responseData = (byte[])(result.result);
6299 if(responseData.length > oemResp.length) {
6300 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6301 responseData.length + "bytes. Buffer Size is " +
6302 oemResp.length + "bytes.");
6303 }
6304 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6305 returnValue = responseData.length;
6306 }
6307 } else {
6308 CommandException ex = (CommandException) result.exception;
6309 returnValue = ex.getCommandError().ordinal();
6310 if(returnValue > 0) returnValue *= -1;
6311 }
6312 } catch (RuntimeException e) {
6313 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6314 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6315 if(returnValue > 0) returnValue *= -1;
6316 }
6317
6318 return returnValue;
6319 }
6320
6321 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006322 public void setRadioCapability(RadioAccessFamily[] rafs) {
6323 try {
6324 ProxyController.getInstance().setRadioCapability(rafs);
6325 } catch (RuntimeException e) {
6326 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6327 }
6328 }
6329
6330 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006331 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006332 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006333 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006334 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006335 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006336 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
6338 try {
chen xub97461a2018-10-26 14:17:57 -07006339 TelephonyPermissions
6340 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6341 mApp, phone.getSubId(), "getRadioAccessFamily");
6342 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006343 } finally {
6344 Binder.restoreCallingIdentity(identity);
6345 }
chen xub97461a2018-10-26 14:17:57 -07006346 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006347 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006348
6349 @Override
6350 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006351 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006352 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353
6354 final long identity = Binder.clearCallingIdentity();
6355 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006356 ImsManager.getInstance(defaultPhone.getContext(),
6357 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006358 } finally {
6359 Binder.restoreCallingIdentity(identity);
6360 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006361 }
6362
6363 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006364 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006365 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006366 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6367 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006368 return false;
6369 }
Svet Ganovb320e182015-04-16 12:30:10 -07006370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 final long identity = Binder.clearCallingIdentity();
6372 try {
6373 // Check the user preference and the system-level IMS setting. Even if the user has
6374 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6375 // In the long run, we may instead need to check if there exists a connection service
6376 // which can support video calling.
6377 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006378 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 return imsManager.isVtEnabledByPlatform()
6380 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6381 && imsManager.isVtEnabledByUser();
6382 } finally {
6383 Binder.restoreCallingIdentity(identity);
6384 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006385 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006386
Andrew Leea1239f22015-03-02 17:44:07 -08006387 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006388 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6389 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006391 mApp, subId, callingPackage, callingFeatureId,
6392 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006393 return false;
6394 }
6395
6396 final long identity = Binder.clearCallingIdentity();
6397 try {
6398 CarrierConfigManager configManager =
6399 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006400 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006401 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Andrew Leea1239f22015-03-02 17:44:07 -08006405 }
6406
6407 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006408 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006409 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006410 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 return false;
6412 }
6413
6414 final long identity = Binder.clearCallingIdentity();
6415 try {
6416 CarrierConfigManager configManager =
6417 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006418 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6420 } finally {
6421 Binder.restoreCallingIdentity(identity);
6422 }
Andrew Leea1239f22015-03-02 17:44:07 -08006423 }
6424
Andrew Lee9431b832015-03-09 18:46:45 -07006425 @Override
6426 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006427 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006428 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006429 }
6430
6431 @Override
6432 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006433 final long identity = Binder.clearCallingIdentity();
6434 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006435 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Andrew Lee9431b832015-03-09 18:46:45 -07006439 }
6440
Hall Liuf6668912018-10-31 17:05:23 -07006441 /**
6442 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6443 * support for the feature and device firmware support.
6444 *
6445 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6446 */
6447 @Override
6448 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006449 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006450 final Phone phone = getPhone(subscriptionId);
6451 if (phone == null) {
6452 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6453 return false;
6454 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006456 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006457 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6458 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006459 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006460 return isCarrierSupported && isDeviceSupported;
6461 } finally {
6462 Binder.restoreCallingIdentity(identity);
6463 }
Hall Liu98187582018-01-22 19:15:32 -08006464 }
6465
Hall Liuf6668912018-10-31 17:05:23 -07006466 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006467 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6468 * RTT setting, will return true if the device and carrier both support RTT.
6469 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006470 */
6471 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 final long identity = Binder.clearCallingIdentity();
6473 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006474 boolean isRttSupported = isRttSupported(subscriptionId);
6475 boolean isUserRttSettingOn = Settings.Secure.getInt(
6476 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6477 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6478 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6479 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 } finally {
6481 Binder.restoreCallingIdentity(identity);
6482 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006483 }
6484
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006485 @Deprecated
6486 @Override
6487 public String getDeviceId(String callingPackage) {
6488 return getDeviceIdWithFeature(callingPackage, null);
6489 }
6490
Sanket Padawe7310cc72015-01-14 09:53:20 -08006491 /**
6492 * Returns the unique device ID of phone, for example, the IMEI for
6493 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6494 *
6495 * <p>Requires Permission:
6496 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6497 */
6498 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006499 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006500 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006501 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006502 return null;
6503 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006504 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006505 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006506 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006507 return null;
6508 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006509
6510 final long identity = Binder.clearCallingIdentity();
6511 try {
6512 return phone.getDeviceId();
6513 } finally {
6514 Binder.restoreCallingIdentity(identity);
6515 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006516 }
6517
Ping Sunc67b7c22016-03-02 19:16:45 +08006518 /**
6519 * {@hide}
6520 * Returns the IMS Registration Status on a particular subid
6521 *
6522 * @param subId
6523 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006524 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006525 Phone phone = getPhone(subId);
6526 if (phone != null) {
6527 return phone.isImsRegistered();
6528 } else {
6529 return false;
6530 }
6531 }
6532
Santos Cordon7a1885b2015-02-03 11:15:19 -08006533 @Override
6534 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006535 final long identity = Binder.clearCallingIdentity();
6536 try {
6537 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6538 } finally {
6539 Binder.restoreCallingIdentity(identity);
6540 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006541 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006542
Tyler Gunnf70ed162019-04-03 15:28:53 -07006543 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006544 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006545 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006546 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006547 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006548 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6549 }
6550 final long identity = Binder.clearCallingIdentity();
6551 try {
6552 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6553 } finally {
6554 Binder.restoreCallingIdentity(identity);
6555 }
6556 }
6557
6558 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006559 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006560 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6561 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006562 final long identity = Binder.clearCallingIdentity();
6563 try {
6564 Phone phone = getPhone(subscriptionId);
6565 if (phone == null) {
6566 return null;
6567 }
6568 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6569 } finally {
6570 Binder.restoreCallingIdentity(identity);
6571 }
6572 }
6573
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006574 /**
6575 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006576 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006577 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006578 final long identity = Binder.clearCallingIdentity();
6579 try {
6580 Phone phone = getPhone(subId);
6581 if (phone != null) {
6582 return phone.isWifiCallingEnabled();
6583 } else {
6584 return false;
6585 }
6586 } finally {
6587 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006588 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006589 }
6590
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006591 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006592 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006593 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006594 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006595 final long identity = Binder.clearCallingIdentity();
6596 try {
6597 Phone phone = getPhone(subId);
6598 if (phone != null) {
6599 return phone.isVideoEnabled();
6600 } else {
6601 return false;
6602 }
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006605 }
6606 }
6607
6608 /**
6609 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6610 * defined in {@link ImsRegistrationImplBase}.
6611 */
6612 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006613 final long identity = Binder.clearCallingIdentity();
6614 try {
6615 Phone phone = getPhone(subId);
6616 if (phone != null) {
6617 return phone.getImsRegistrationTech();
6618 } else {
6619 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6620 }
6621 } finally {
6622 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006623 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006624 }
6625
Stuart Scott8eef64f2015-04-08 15:13:54 -07006626 @Override
6627 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006628 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006629 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6630 return;
6631 }
6632
Svet Ganovcc087f82015-05-12 20:35:54 -07006633 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006634
Svet Ganovcc087f82015-05-12 20:35:54 -07006635 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006636 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6637 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006638 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006639 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006640 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006641 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6642 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006643 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006644 // There has been issues when Sms raw table somehow stores orphan
6645 // fragments. They lead to garbled message when new fragments come
6646 // in and combined with those stale ones. In case this happens again,
6647 // user can reset all network settings which will clean up this table.
6648 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006649 // Clean up IMS settings as well here.
6650 int slotId = getSlotIndex(subId);
6651 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6652 ImsManager.getInstance(mApp, slotId).factoryReset();
6653 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006654
6655 // Erase modem config if erase modem on network setting is enabled.
6656 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6657 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6658 if (configValue != null && Boolean.parseBoolean(configValue)) {
6659 sendEraseModemConfig(getDefaultPhone());
6660 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006661 } finally {
6662 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006663 }
6664 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006665
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006666 private void cleanUpSmsRawTable(Context context) {
6667 ContentResolver resolver = context.getContentResolver();
6668 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6669 resolver.delete(uri, null, null);
6670 }
6671
Narayan Kamath1c496c22015-04-16 14:40:19 +01006672 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006673 public String getSimLocaleForSubscriber(int subId) {
6674 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6675 final Phone phone = getPhone(subId);
6676 if (phone == null) {
6677 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006678 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006679 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006680 final long identity = Binder.clearCallingIdentity();
6681 try {
chen xu5d3637b2019-01-21 23:31:38 -08006682 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006683 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006684 if (info == null) {
6685 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6686 return null;
6687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 // Try and fetch the locale from the carrier properties or from the SIM language
6689 // preferences (EF-PL and EF-LI)...
6690 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006691 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006692 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6693 if (localeFromDefaultSim != null) {
6694 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6695 if (DBG) log("Using locale from subId: " + subId + " locale: "
6696 + localeFromDefaultSim);
6697 return localeFromDefaultSim.toLanguageTag();
6698 } else {
6699 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 }
6701 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006702
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006703 // The SIM language preferences only store a language (e.g. fr = French), not an
6704 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6705 // the SIM and carrier preferences does not include a country we add the country
6706 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006707 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006709 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006710 return mccLocale.toLanguageTag();
6711 }
6712
6713 if (DBG) log("No locale found - returning null");
6714 return null;
6715 } finally {
6716 Binder.restoreCallingIdentity(identity);
6717 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006718 }
6719
6720 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006721 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006722 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006723 }
6724
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006725 /**
6726 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6727 */
6728 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006729 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006730 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006731 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006732
Chenjie Yu1ba97252018-01-11 18:16:20 -08006733 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006734 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006735
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006736 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006737 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6738 * representing the state of the modem.
6739 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006740 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6741 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006742 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006743 */
6744 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006745 public void requestModemActivityInfo(ResultReceiver result) {
6746 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006747 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006748
6749 final long identity = Binder.clearCallingIdentity();
6750 try {
sqian1a1be542020-03-05 11:37:28 -08006751 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006752 } finally {
6753 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006754 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006755 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006756
Siddharth Rayb8114062018-06-17 15:02:38 -07006757 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6758 // less than total activity duration.
6759 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6760 if (info == null) {
6761 return false;
6762 }
6763 int activityDurationMs =
6764 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6765 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006766 int[] txTimeMs = info.getTransmitTimeMillis();
6767 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6768 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006769 }
6770 return (info.isValid()
6771 && (info.getSleepTimeMillis() <= activityDurationMs)
6772 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006773 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006774 && (totalTxTimeMs <= activityDurationMs));
6775 }
6776
Jack Yu85bd38a2015-11-09 11:34:32 -08006777 /**
6778 * {@hide}
6779 * Returns the service state information on specified subscription.
6780 */
6781 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006782 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6783 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006784 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006785 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006786 return null;
6787 }
6788
Hall Liuf19c44f2018-11-27 14:38:17 -08006789 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6790 LocationAccessPolicy.checkLocationPermission(mApp,
6791 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6792 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006793 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006794 .setCallingPid(Binder.getCallingPid())
6795 .setCallingUid(Binder.getCallingUid())
6796 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006797 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006798 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6799 .build());
6800
6801 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6802 LocationAccessPolicy.checkLocationPermission(mApp,
6803 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6804 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006806 .setCallingPid(Binder.getCallingPid())
6807 .setCallingUid(Binder.getCallingUid())
6808 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006809 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006810 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6811 .build());
6812 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6813 boolean hasFinePermission =
6814 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6815 boolean hasCoarsePermission =
6816 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6817
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006818 final long identity = Binder.clearCallingIdentity();
6819 try {
6820 final Phone phone = getPhone(subId);
6821 if (phone == null) {
6822 return null;
6823 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006824
Hall Liuf19c44f2018-11-27 14:38:17 -08006825 ServiceState ss = phone.getServiceState();
6826
6827 // Scrub out the location info in ServiceState depending on what level of access
6828 // the caller has.
6829 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006830 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6831 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006832 } finally {
6833 Binder.restoreCallingIdentity(identity);
6834 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006835 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006836
6837 /**
6838 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6839 *
6840 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6841 * voicemail ringtone.
6842 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6843 * PhoneAccount.
6844 */
6845 @Override
6846 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 final long identity = Binder.clearCallingIdentity();
6848 try {
6849 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6850 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006851 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006853
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006854 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6855 } finally {
6856 Binder.restoreCallingIdentity(identity);
6857 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006858 }
6859
6860 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006861 * Sets the per-account voicemail ringtone.
6862 *
6863 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6864 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6865 *
6866 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6867 * voicemail ringtone.
6868 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6869 * PhoneAccount.
6870 */
6871 @Override
6872 public void setVoicemailRingtoneUri(String callingPackage,
6873 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006874 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006875 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006876 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6877 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6879 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6880 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006881 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006882
6883 final long identity = Binder.clearCallingIdentity();
6884 try {
6885 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6886 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006887 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006888 }
6889 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6890 } finally {
6891 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006892 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006893 }
6894
6895 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006896 * Returns whether vibration is set for voicemail notification in Phone settings.
6897 *
6898 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6899 * voicemail vibration setting.
6900 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6901 */
6902 @Override
6903 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006904 final long identity = Binder.clearCallingIdentity();
6905 try {
6906 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6907 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006908 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006910
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006911 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6912 } finally {
6913 Binder.restoreCallingIdentity(identity);
6914 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006915 }
6916
Youhan Wange64578a2016-05-02 15:32:42 -07006917 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006918 * Sets the per-account voicemail vibration.
6919 *
6920 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6921 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6922 *
6923 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6924 * voicemail vibration setting.
6925 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6926 * specific PhoneAccount.
6927 */
6928 @Override
6929 public void setVoicemailVibrationEnabled(String callingPackage,
6930 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006931 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006932 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006933 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6934 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006935 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6936 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6937 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006938 }
6939
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006940 final long identity = Binder.clearCallingIdentity();
6941 try {
6942 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6943 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006944 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006945 }
6946 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6947 } finally {
6948 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006949 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006950 }
6951
6952 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006953 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6954 *
6955 * @throws SecurityException if the caller does not have the required permission
6956 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006957 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006958 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006959 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006960 }
6961
6962 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006963 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6964 * permission.
6965 *
6966 * @throws SecurityException if the caller does not have the required permission
6967 */
6968 private void enforceSendSmsPermission() {
6969 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6970 }
6971
6972 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006973 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006974 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006975 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006976 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006977 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006978 final long identity = Binder.clearCallingIdentity();
6979 try {
6980 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 if (componentName == null) {
6983 throw new SecurityException(
6984 "Caller not current active visual voicemail package[null]");
6985 }
6986 String vvmPackage = componentName.getPackageName();
6987 if (!callingPackage.equals(vvmPackage)) {
6988 throw new SecurityException("Caller not current active visual voicemail package["
6989 + vvmPackage + "]");
6990 }
6991 } finally {
6992 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006993 }
6994 }
6995
6996 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006997 * Return the application ID for the app type.
6998 *
6999 * @param subId the subscription ID that this request applies to.
7000 * @param appType the uicc app type.
7001 * @return Application ID for specificied app type, or null if no uicc.
7002 */
7003 @Override
7004 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007005 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007006 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007007
7008 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007009 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007010 if (phone == null) {
7011 return null;
7012 }
7013 String aid = null;
7014 try {
7015 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7016 .getApplicationByType(appType).getAid();
7017 } catch (Exception e) {
7018 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7019 }
7020 return aid;
7021 } finally {
7022 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007023 }
Youhan Wange64578a2016-05-02 15:32:42 -07007024 }
7025
Youhan Wang4001d252016-05-11 10:29:41 -07007026 /**
7027 * Return the Electronic Serial Number.
7028 *
7029 * @param subId the subscription ID that this request applies to.
7030 * @return ESN or null if error.
7031 */
7032 @Override
7033 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007034 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007035 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036
7037 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007038 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007039 if (phone == null) {
7040 return null;
7041 }
7042 String esn = null;
7043 try {
7044 esn = phone.getEsn();
7045 } catch (Exception e) {
7046 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7047 }
7048 return esn;
7049 } finally {
7050 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007051 }
Youhan Wang4001d252016-05-11 10:29:41 -07007052 }
7053
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007054 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007055 * Return the Preferred Roaming List Version.
7056 *
7057 * @param subId the subscription ID that this request applies to.
7058 * @return PRLVersion or null if error.
7059 */
7060 @Override
7061 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007062 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007063 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007064
7065 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007066 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007067 if (phone == null) {
7068 return null;
7069 }
7070 String cdmaPrlVersion = null;
7071 try {
7072 cdmaPrlVersion = phone.getCdmaPrlVersion();
7073 } catch (Exception e) {
7074 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7075 }
7076 return cdmaPrlVersion;
7077 } finally {
7078 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007079 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007080 }
7081
7082 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007083 * Get snapshot of Telephony histograms
7084 * @return List of Telephony histograms
7085 * @hide
7086 */
7087 @Override
7088 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007089 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7090 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091
7092 final long identity = Binder.clearCallingIdentity();
7093 try {
7094 return RIL.getTelephonyRILTimingHistograms();
7095 } finally {
7096 Binder.restoreCallingIdentity(identity);
7097 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007098 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007099
7100 /**
7101 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007102 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7103 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007104 * Require system privileges. In the future we may add this to carrier APIs.
7105 *
Michele Berionne482f8202018-11-27 18:57:59 -08007106 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007107 */
7108 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007109 @TelephonyManager.SetCarrierRestrictionResult
7110 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007111 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007112 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007113
Michele Berionne482f8202018-11-27 18:57:59 -08007114 if (carrierRestrictionRules == null) {
7115 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007116 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007117
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007118 final long identity = Binder.clearCallingIdentity();
7119 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007120 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007121 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007122 } finally {
7123 Binder.restoreCallingIdentity(identity);
7124 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007125 }
7126
7127 /**
7128 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007129 * Get the allowed carrier list and the excluded carrier list, including the priority between
7130 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007131 * Require system privileges. In the future we may add this to carrier APIs.
7132 *
Michele Berionne482f8202018-11-27 18:57:59 -08007133 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007134 */
7135 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007136 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007137 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007138 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007139
7140 final long identity = Binder.clearCallingIdentity();
7141 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007142 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7143 if (response instanceof CarrierRestrictionRules) {
7144 return (CarrierRestrictionRules) response;
7145 }
7146 // Response is an Exception of some kind,
7147 // which is signalled to the user as a NULL retval
7148 return null;
7149 } catch (Exception e) {
7150 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7151 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007152 } finally {
7153 Binder.restoreCallingIdentity(identity);
7154 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007155 }
7156
fionaxu59545b42016-05-25 15:53:37 -07007157 /**
7158 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7159 * @param subId the subscription ID that this action applies to.
7160 * @param enabled control enable or disable metered apns.
7161 * {@hide}
7162 */
7163 @Override
7164 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7165 enforceModifyPermission();
7166 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167
7168 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007169 if (phone == null) {
7170 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7171 return;
7172 }
7173 try {
7174 phone.carrierActionSetMeteredApnsEnabled(enabled);
7175 } catch (Exception e) {
7176 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007177 } finally {
7178 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007179 }
7180 }
7181
7182 /**
7183 * Action set from carrier signalling broadcast receivers to enable/disable radio
7184 * @param subId the subscription ID that this action applies to.
7185 * @param enabled control enable or disable radio.
7186 * {@hide}
7187 */
7188 @Override
7189 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7190 enforceModifyPermission();
7191 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192
7193 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007194 if (phone == null) {
7195 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7196 return;
7197 }
7198 try {
7199 phone.carrierActionSetRadioEnabled(enabled);
7200 } catch (Exception e) {
7201 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007202 } finally {
7203 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007204 }
7205 }
7206
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007207 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007208 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7209 * network status based on which carrier apps could apply actions accordingly,
7210 * enable/disable default url handler for example.
7211 *
7212 * @param subId the subscription ID that this action applies to.
7213 * @param report control start/stop reporting the default network status.
7214 * {@hide}
7215 */
7216 @Override
7217 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7218 enforceModifyPermission();
7219 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007220
7221 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007222 if (phone == null) {
7223 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7224 return;
7225 }
7226 try {
7227 phone.carrierActionReportDefaultNetworkStatus(report);
7228 } catch (Exception e) {
7229 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007230 } finally {
7231 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007232 }
7233 }
7234
7235 /**
fionaxud9622282017-07-17 17:51:30 -07007236 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7237 * @param subId the subscription ID that this action applies to.
7238 * {@hide}
7239 */
7240 @Override
7241 public void carrierActionResetAll(int subId) {
7242 enforceModifyPermission();
7243 final Phone phone = getPhone(subId);
7244 if (phone == null) {
7245 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7246 return;
7247 }
7248 try {
7249 phone.carrierActionResetAll();
7250 } catch (Exception e) {
7251 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7252 }
7253 }
7254
7255 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007256 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7257 * bug report is being generated.
7258 */
7259 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007260 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007261 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7262 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007263 writer.println("Permission Denial: can't dump Phone from pid="
7264 + Binder.getCallingPid()
7265 + ", uid=" + Binder.getCallingUid()
7266 + "without permission "
7267 + android.Manifest.permission.DUMP);
7268 return;
7269 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007270 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007271 }
Jack Yueb89b242016-06-22 13:27:47 -07007272
Brad Ebingerdac2f002018-04-03 15:17:52 -07007273 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007274 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7275 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7276 @NonNull String[] args) {
7277 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7278 this, in.getFileDescriptor(), out.getFileDescriptor(),
7279 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007280 }
7281
Jack Yueb89b242016-06-22 13:27:47 -07007282 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007283 * Policy control of data connection. Usually used when data limit is passed.
7284 * @param enabled True if enabling the data, otherwise disabling.
7285 * @param subId Subscription index
7286 * {@hide}
7287 */
7288 @Override
7289 public void setPolicyDataEnabled(boolean enabled, int subId) {
7290 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007291
7292 final long identity = Binder.clearCallingIdentity();
7293 try {
7294 Phone phone = getPhone(subId);
7295 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007296 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007297 }
7298 } finally {
7299 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007300 }
7301 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007302
7303 /**
7304 * Get Client request stats
7305 * @return List of Client Request Stats
7306 * @hide
7307 */
7308 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007309 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7310 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007311 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007312 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007313 return null;
7314 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007315 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007316
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 final long identity = Binder.clearCallingIdentity();
7318 try {
7319 if (phone != null) {
7320 return phone.getClientRequestStats();
7321 }
7322
7323 return null;
7324 } finally {
7325 Binder.restoreCallingIdentity(identity);
7326 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007327 }
7328
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007329 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007330 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007331 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007332 }
Jack Yueb4124c2017-02-16 15:32:43 -08007333
7334 /**
Grace Chen70990072017-03-24 17:21:30 -07007335 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007336 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007337 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007338 * @param state State of SIM (power down, power up, pass through)
7339 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7340 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7341 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007342 *
7343 **/
7344 @Override
Grace Chen70990072017-03-24 17:21:30 -07007345 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007346 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007347 Phone phone = PhoneFactory.getPhone(slotIndex);
7348
vagdeviaf9a5b92018-08-15 16:01:53 -07007349 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7350
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007351 final long identity = Binder.clearCallingIdentity();
7352 try {
7353 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007354 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007355 }
7356 } finally {
7357 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007358 }
7359 }
Shuo Qiandd210312017-04-12 22:11:33 +00007360
Tyler Gunn65d45c22017-06-05 11:22:26 -07007361 private boolean isUssdApiAllowed(int subId) {
7362 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007363 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007364 if (configManager == null) {
7365 return false;
7366 }
7367 PersistableBundle pb = configManager.getConfigForSubId(subId);
7368 if (pb == null) {
7369 return false;
7370 }
7371 return pb.getBoolean(
7372 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7373 }
7374
Shuo Qiandd210312017-04-12 22:11:33 +00007375 /**
7376 * Check if phone is in emergency callback mode
7377 * @return true if phone is in emergency callback mode
7378 * @param subId sub id
7379 */
goneil9c5f4872017-12-05 14:07:56 -08007380 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007381 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007382 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007383 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007384
7385 final long identity = Binder.clearCallingIdentity();
7386 try {
7387 if (phone != null) {
7388 return phone.isInEcm();
7389 } else {
7390 return false;
7391 }
7392 } finally {
7393 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007394 }
7395 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007396
7397 /**
7398 * Get the current signal strength information for the given subscription.
7399 * Because this information is not updated when the device is in a low power state
7400 * it should not be relied-upon to be current.
7401 * @param subId Subscription index
7402 * @return the most recent cached signal strength info from the modem
7403 */
7404 @Override
7405 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007406 final long identity = Binder.clearCallingIdentity();
7407 try {
7408 Phone p = getPhone(subId);
7409 if (p == null) {
7410 return null;
7411 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007412
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007413 return p.getSignalStrength();
7414 } finally {
7415 Binder.restoreCallingIdentity(identity);
7416 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007417 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007418
Pengquan Meng77b7f132018-08-22 14:49:57 -07007419 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007420 * Get the current modem radio state for the given slot.
7421 * @param slotIndex slot index.
7422 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007423 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007424 * @return the current radio power state from the modem
7425 */
7426 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007427 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007428 Phone phone = PhoneFactory.getPhone(slotIndex);
7429 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007430 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7431 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007432 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7433 }
7434
7435 final long identity = Binder.clearCallingIdentity();
7436 try {
7437 return phone.getRadioPowerState();
7438 } finally {
7439 Binder.restoreCallingIdentity(identity);
7440 }
7441 }
7442 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7443 }
7444
7445 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007446 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7447 *
7448 * <p>Requires one of the following permissions:
7449 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7450 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7451 * privileges.
7452 *
7453 * @param subId subscription id
7454 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7455 * {@code false}.
7456 */
7457 @Override
7458 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007459 try {
7460 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7461 null);
7462 } catch (Exception e) {
7463 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7464 mApp, subId, "isDataRoamingEnabled");
7465 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007466
Pengquan Menga1bb6272018-09-06 09:59:22 -07007467 boolean isEnabled = false;
7468 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007469 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007470 Phone phone = getPhone(subId);
7471 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007472 } finally {
7473 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007474 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007475 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007476 }
7477
7478
7479 /**
7480 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7481 *
7482 * <p> Requires permission:
7483 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7484 * privileges.
7485 *
7486 * @param subId subscription id
7487 * @param isEnabled {@code true} means enable, {@code false} means disable.
7488 */
7489 @Override
7490 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007491 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7492 mApp, subId, "setDataRoamingEnabled");
7493
Pengquan Menga1bb6272018-09-06 09:59:22 -07007494 final long identity = Binder.clearCallingIdentity();
7495 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007496 Phone phone = getPhone(subId);
7497 if (phone != null) {
7498 phone.setDataRoamingEnabled(isEnabled);
7499 }
7500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007502 }
7503 }
7504
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007505 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007506 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007507 TelephonyPermissions
7508 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007509 mApp, subId, "isManualNetworkSelectionAllowed");
7510
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007511 boolean isAllowed = true;
7512 final long identity = Binder.clearCallingIdentity();
7513 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007514 Phone phone = getPhone(subId);
7515 if (phone != null) {
7516 isAllowed = phone.isCspPlmnEnabled();
7517 }
7518 } finally {
7519 Binder.restoreCallingIdentity(identity);
7520 }
7521 return isAllowed;
7522 }
7523
7524 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007525 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007526 // Verify that tha callingPackage belongs to the calling UID
7527 mApp.getSystemService(AppOpsManager.class)
7528 .checkPackage(Binder.getCallingUid(), callingPackage);
7529
Jordan Liu1e142fc2019-04-22 15:10:43 -07007530 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007531 try {
7532 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007533 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007534 } catch (SecurityException e) {
7535 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7536 // has carrier privileges on an active UICC
7537 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7538 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007539 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007540 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007541 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007542
7543 final long identity = Binder.clearCallingIdentity();
7544 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007545 UiccController uiccController = UiccController.getInstance();
7546 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007547 if (hasReadPermission) {
7548 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007549 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007550
7551 // Remove private info if the caller doesn't have access
7552 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7553 for (UiccCardInfo cardInfo : cardInfos) {
7554 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7555 // is available
7556 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7557 if (card == null || card.getUiccProfile() == null) {
7558 // assume no access if the card or profile is unavailable
7559 filteredInfos.add(cardInfo.getUnprivileged());
7560 continue;
7561 }
7562 UiccProfile profile = card.getUiccProfile();
7563 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7564 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7565 filteredInfos.add(cardInfo);
7566 } else {
7567 filteredInfos.add(cardInfo.getUnprivileged());
7568 }
7569 }
7570 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007571 } finally {
7572 Binder.restoreCallingIdentity(identity);
7573 }
7574 }
7575
7576 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007577 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007578 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007579
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007580 final long identity = Binder.clearCallingIdentity();
7581 try {
7582 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7583 if (slots == null) {
7584 Rlog.i(LOG_TAG, "slots is null.");
7585 return null;
7586 }
7587
7588 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7589 for (int i = 0; i < slots.length; i++) {
7590 UiccSlot slot = slots[i];
7591 if (slot == null) {
7592 continue;
7593 }
7594
Jordan Liu7be7e652019-05-06 18:55:02 +00007595 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007596 UiccCard card = slot.getUiccCard();
7597 if (card != null) {
7598 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007599 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007600 cardId = slot.getEid();
7601 if (TextUtils.isEmpty(cardId)) {
7602 cardId = slot.getIccId();
7603 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007604 }
7605
Jordan Liu857451f2019-05-09 16:35:35 -07007606 if (cardId != null) {
7607 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7608 // if cardId is an EID, it's all digits so this is fine
7609 cardId = IccUtils.stripTrailingFs(cardId);
7610 }
7611
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007612 int cardState = 0;
7613 switch (slot.getCardState()) {
7614 case CARDSTATE_ABSENT:
7615 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7616 break;
7617 case CARDSTATE_PRESENT:
7618 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7619 break;
7620 case CARDSTATE_ERROR:
7621 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7622 break;
7623 case CARDSTATE_RESTRICTED:
7624 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7625 break;
7626 default:
7627 break;
7628
7629 }
7630
7631 infos[i] = new UiccSlotInfo(
7632 slot.isActive(),
7633 slot.isEuicc(),
7634 cardId,
7635 cardState,
7636 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007637 slot.isExtendedApduSupported(),
7638 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007639 }
7640 return infos;
7641 } finally {
7642 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007643 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007644 }
7645
7646 @Override
7647 public boolean switchSlots(int[] physicalSlots) {
7648 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007649
7650 final long identity = Binder.clearCallingIdentity();
7651 try {
7652 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7653 } finally {
7654 Binder.restoreCallingIdentity(identity);
7655 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007656 }
Jack Yu4c988042018-02-27 15:30:01 -08007657
7658 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007659 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007660 final long identity = Binder.clearCallingIdentity();
7661 try {
7662 return UiccController.getInstance().getCardIdForDefaultEuicc();
7663 } finally {
7664 Binder.restoreCallingIdentity(identity);
7665 }
7666 }
7667
Pengquan Meng85728fb2018-03-12 16:31:21 -07007668 /**
goneil47ffb6e2018-04-06 15:40:58 -07007669 * A test API to reload the UICC profile.
7670 *
7671 * <p>Requires that the calling app has permission
7672 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7673 * @hide
7674 */
7675 @Override
7676 public void refreshUiccProfile(int subId) {
7677 enforceModifyPermission();
7678
7679 final long identity = Binder.clearCallingIdentity();
7680 try {
7681 Phone phone = getPhone(subId);
7682 if (phone == null) {
7683 return;
7684 }
7685 UiccCard uiccCard = phone.getUiccCard();
7686 if (uiccCard == null) {
7687 return;
7688 }
7689 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7690 if (uiccProfile == null) {
7691 return;
7692 }
7693 uiccProfile.refresh();
7694 } finally {
7695 Binder.restoreCallingIdentity(identity);
7696 }
7697 }
7698
7699 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007700 * Returns false if the mobile data is disabled by default, otherwise return true.
7701 */
7702 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007703 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007704 }
7705
7706 /**
7707 * Returns true if the data roaming is enabled by default, i.e the system property
7708 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7709 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7710 */
7711 private boolean getDefaultDataRoamingEnabled(int subId) {
7712 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007713 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007714 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007715 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7716 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7717 return isDataRoamingEnabled;
7718 }
7719
7720 /**
7721 * Returns the default network type for the given {@code subId}, if the default network type is
7722 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7723 */
7724 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007725 List<Integer> list = TelephonyProperties.default_network();
7726 int phoneId = mSubscriptionController.getPhoneId(subId);
7727 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7728 return list.get(phoneId);
7729 }
7730 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007731 }
fionaxua13278b2018-03-21 00:08:13 -07007732
7733 @Override
7734 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007735 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007736 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007737
7738 final long identity = Binder.clearCallingIdentity();
7739 try {
7740 final Phone phone = getPhone(subId);
7741 if (phone == null) {
7742 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7743 return;
7744 }
chen xueaba88a2019-03-15 13:15:10 -07007745 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7746 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007747 } finally {
7748 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007749 }
fionaxua13278b2018-03-21 00:08:13 -07007750 }
7751
7752 @Override
7753 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007754 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007755
7756 final long identity = Binder.clearCallingIdentity();
7757 try {
7758 final Phone phone = getPhone(subId);
7759 if (phone == null) {
7760 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7761 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7762 }
7763 return phone.getCarrierIdListVersion();
7764 } finally {
7765 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007766 }
fionaxua13278b2018-03-21 00:08:13 -07007767 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007768
7769 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007770 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7771 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007772 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007773 mApp, subId, callingPackage, callingFeatureId,
7774 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007775 return -1;
7776 }
7777
7778 final long identity = Binder.clearCallingIdentity();
7779 try {
7780 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7781 } finally {
7782 Binder.restoreCallingIdentity(identity);
7783 }
7784 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007785
7786 @Override
7787 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007788 TelephonyPermissions
7789 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007790 mApp, subId, "getCdmaRoamingMode");
7791
7792 final long identity = Binder.clearCallingIdentity();
7793 try {
7794 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
7797 }
7798 }
7799
7800 @Override
7801 public boolean setCdmaRoamingMode(int subId, int mode) {
7802 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7803 mApp, subId, "setCdmaRoamingMode");
7804
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
7811 }
7812
7813 @Override
7814 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7816 mApp, subId, "setCdmaSubscriptionMode");
7817
7818 final long identity = Binder.clearCallingIdentity();
7819 try {
7820 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
7824 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007825
sqianc5eccab2018-10-19 18:46:41 -07007826 @Override
sqian8c685422019-02-22 15:55:18 -08007827 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007828 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007829 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007830 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7831 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007832 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7833 }
7834 final long identity = Binder.clearCallingIdentity();
7835 try {
sqian854d44b2018-12-12 16:48:18 -08007836 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7837 for (Phone phone: PhoneFactory.getPhones()) {
7838 if (phone.getEmergencyNumberTracker() != null
7839 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7840 emergencyNumberListInternal.put(
7841 phone.getSubId(),
7842 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7843 }
sqian11b7a0e2018-12-05 18:48:28 -08007844 }
sqian854d44b2018-12-12 16:48:18 -08007845 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007846 } finally {
7847 Binder.restoreCallingIdentity(identity);
7848 }
sqianc5eccab2018-10-19 18:46:41 -07007849 }
7850
7851 @Override
sqian8c685422019-02-22 15:55:18 -08007852 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007853 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007854 if (!exactMatch) {
7855 TelephonyPermissions
7856 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007857 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007858 }
7859 final long identity = Binder.clearCallingIdentity();
7860 try {
sqian854d44b2018-12-12 16:48:18 -08007861 for (Phone phone: PhoneFactory.getPhones()) {
7862 if (phone.getEmergencyNumberTracker() != null
7863 && phone.getEmergencyNumberTracker() != null) {
7864 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7865 number, exactMatch)) {
7866 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007867 }
7868 }
sqian11b7a0e2018-12-05 18:48:28 -08007869 }
7870 return false;
7871 } finally {
7872 Binder.restoreCallingIdentity(identity);
7873 }
7874 }
7875
sqianf4ca7ed2019-01-15 18:32:07 -08007876 /**
7877 * Update emergency number list for test mode.
7878 */
7879 @Override
7880 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7881 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7882 "updateEmergencyNumberListTestMode");
7883
7884 final long identity = Binder.clearCallingIdentity();
7885 try {
7886 for (Phone phone: PhoneFactory.getPhones()) {
7887 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7888 if (tracker != null) {
7889 tracker.executeEmergencyNumberTestModeCommand(action, num);
7890 }
7891 }
7892 } finally {
7893 Binder.restoreCallingIdentity(identity);
7894 }
7895 }
7896
7897 /**
7898 * Get the full emergency number list for test mode.
7899 */
7900 @Override
7901 public List<String> getEmergencyNumberListTestMode() {
7902 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7903 "getEmergencyNumberListTestMode");
7904
7905 final long identity = Binder.clearCallingIdentity();
7906 try {
7907 Set<String> emergencyNumbers = new HashSet<>();
7908 for (Phone phone: PhoneFactory.getPhones()) {
7909 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7910 if (tracker != null) {
7911 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7912 emergencyNumbers.add(num.getNumber());
7913 }
7914 }
7915 }
7916 return new ArrayList<>(emergencyNumbers);
7917 } finally {
7918 Binder.restoreCallingIdentity(identity);
7919 }
7920 }
7921
chen xud6b45bd2018-10-30 22:27:10 -07007922 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007923 public int getEmergencyNumberDbVersion(int subId) {
7924 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7925
7926 final long identity = Binder.clearCallingIdentity();
7927 try {
7928 final Phone phone = getPhone(subId);
7929 if (phone == null) {
7930 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7931 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7932 }
7933 return phone.getEmergencyNumberDbVersion();
7934 } finally {
7935 Binder.restoreCallingIdentity(identity);
7936 }
7937 }
7938
7939 @Override
7940 public void notifyOtaEmergencyNumberDbInstalled() {
7941 enforceModifyPermission();
7942
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 for (Phone phone: PhoneFactory.getPhones()) {
7946 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7947 if (tracker != null) {
7948 tracker.updateOtaEmergencyNumberDatabase();
7949 }
7950 }
7951 } finally {
7952 Binder.restoreCallingIdentity(identity);
7953 }
7954 }
7955
7956 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007957 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007958 enforceActiveEmergencySessionPermission();
7959
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 for (Phone phone: PhoneFactory.getPhones()) {
7963 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7964 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007965 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7966 }
7967 }
7968 } finally {
7969 Binder.restoreCallingIdentity(identity);
7970 }
7971 }
7972
7973 @Override
7974 public void resetOtaEmergencyNumberDbFilePath() {
7975 enforceActiveEmergencySessionPermission();
7976
7977 final long identity = Binder.clearCallingIdentity();
7978 try {
7979 for (Phone phone: PhoneFactory.getPhones()) {
7980 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7981 if (tracker != null) {
7982 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08007983 }
7984 }
7985 } finally {
7986 Binder.restoreCallingIdentity(identity);
7987 }
7988 }
7989
7990 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007991 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7992 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7993 Phone phone = getPhone(subId);
7994 if (phone == null) {
7995 return null;
7996 }
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 UiccProfile profile = UiccController.getInstance()
8000 .getUiccProfileForPhone(phone.getPhoneId());
8001 if (profile != null) {
8002 return profile.getCertsFromCarrierPrivilegeAccessRules();
8003 }
8004 } finally {
8005 Binder.restoreCallingIdentity(identity);
8006 }
8007 return null;
8008 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008009
8010 /**
8011 * Enable or disable a modem stack.
8012 */
8013 @Override
8014 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8015 enforceModifyPermission();
8016
8017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 Phone phone = PhoneFactory.getPhone(slotIndex);
8020 if (phone == null) {
8021 return false;
8022 } else {
8023 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8024 }
8025 } finally {
8026 Binder.restoreCallingIdentity(identity);
8027 }
8028 }
Michelecea4cf22018-12-21 15:00:11 -08008029
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008030 /**
8031 * Whether a modem stack is enabled or not.
8032 */
8033 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008034 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8035 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008036 Phone phone = PhoneFactory.getPhone(slotIndex);
8037 if (phone == null) return false;
8038
8039 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008040 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8041 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008042 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8043 }
8044
8045 final long identity = Binder.clearCallingIdentity();
8046 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008047 try {
8048 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8049 } catch (NoSuchElementException ex) {
8050 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8051 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008052 } finally {
8053 Binder.restoreCallingIdentity(identity);
8054 }
8055 }
8056
Michelecea4cf22018-12-21 15:00:11 -08008057 @Override
Michele0ea7d782019-03-19 14:58:42 -07008058 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008059 enforceModifyPermission();
8060
8061 final long identity = Binder.clearCallingIdentity();
8062 try {
8063 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008064 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008065 .commit();
8066 } finally {
8067 Binder.restoreCallingIdentity(identity);
8068 }
8069 }
8070
8071 @Override
Michele0ea7d782019-03-19 14:58:42 -07008072 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008073 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008075 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8076 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008077 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008078 }
Michelecea4cf22018-12-21 15:00:11 -08008079
8080 final long identity = Binder.clearCallingIdentity();
8081 try {
Michele0ea7d782019-03-19 14:58:42 -07008082 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
8086 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008087
Michele0ea7d782019-03-19 14:58:42 -07008088 @TelephonyManager.IsMultiSimSupportedResult
8089 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008090 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8091 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8092 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008093 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8094 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008095 }
8096 // Check if the hardware supports multisim functionality. If usage of multisim is not
8097 // supported by the modem, indicate that it is restricted.
8098 PhoneCapability staticCapability =
8099 mPhoneConfigurationManager.getStaticPhoneCapability();
8100 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008101 loge("isMultiSimSupportedInternal: no static configuration available");
8102 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008103 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008104 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008105 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8106 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008107 }
8108 // Check if support of multiple SIMs is restricted by carrier
8109 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008110 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008111 }
8112
Michele0ea7d782019-03-19 14:58:42 -07008113 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008114 }
8115
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008116 /**
8117 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008118 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8119 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8120 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008121 * @param numOfSims number of active sims we want to switch to
8122 */
8123 @Override
8124 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008125 if (numOfSims == 1) {
8126 enforceModifyPermission();
8127 } else {
8128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8129 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8130 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008131 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008132
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008133 try {
Michele30b57b22019-03-01 12:01:14 -08008134 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008135 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008136 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8137 return;
8138 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008139 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8140 } finally {
8141 Binder.restoreCallingIdentity(identity);
8142 }
8143 }
8144
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008145 @Override
8146 public boolean isApplicationOnUicc(int subId, int appType) {
8147 enforceReadPrivilegedPermission("isApplicationOnUicc");
8148 Phone phone = getPhone(subId);
8149 if (phone == null) {
8150 return false;
8151 }
8152 final long identity = Binder.clearCallingIdentity();
8153 try {
8154 UiccCard uiccCard = phone.getUiccCard();
8155 if (uiccCard == null) {
8156 return false;
8157 }
8158 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8159 if (uiccProfile == null) {
8160 return false;
8161 }
8162 if (TelephonyManager.APPTYPE_SIM <= appType
8163 && appType <= TelephonyManager.APPTYPE_ISIM) {
8164 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8165 }
8166 return false;
8167 } finally {
8168 Binder.restoreCallingIdentity(identity);
8169 }
8170 }
8171
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008172 /**
chen xub4baa772019-04-03 10:23:41 -07008173 * Get whether making changes to modem configurations will trigger reboot.
8174 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008175 */
8176 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008177 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8178 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008179 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008180 mApp, subId, callingPackage, callingFeatureId,
8181 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008182 return false;
8183 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008184 final long identity = Binder.clearCallingIdentity();
8185 try {
8186 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
8190 }
8191
Nathan Harold29f5f052019-02-15 13:41:57 -08008192 private void updateModemStateMetrics() {
8193 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8194 // TODO: check the state for each modem if the api is ready.
8195 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8196 }
8197
Pengquan Meng3889a572019-01-23 11:16:29 -08008198 @Override
8199 public int[] getSlotsMapping() {
8200 enforceReadPrivilegedPermission("getSlotsMapping");
8201
8202 final long identity = Binder.clearCallingIdentity();
8203 try {
8204 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8205 // All logical slots should have a mapping to a physical slot.
8206 int[] logicalSlotsMapping = new int[phoneCount];
8207 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8208 for (int i = 0; i < slotInfos.length; i++) {
8209 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8210 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8211 }
8212 }
8213 return logicalSlotsMapping;
8214 } finally {
8215 Binder.restoreCallingIdentity(identity);
8216 }
8217 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008218
8219 /**
8220 * Get the IRadio HAL Version
8221 */
8222 @Override
8223 public int getRadioHalVersion() {
8224 Phone phone = getDefaultPhone();
8225 if (phone == null) return -1;
8226 HalVersion hv = phone.getHalVersion();
8227 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8228 return hv.major * 100 + hv.minor;
8229 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008230
8231 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008232 * Get the current calling package name.
8233 * @return the current calling package name
8234 */
8235 @Override
8236 public String getCurrentPackageName() {
8237 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8238 }
8239
8240 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008241 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8242 * corresponding network requests on a subId.
8243 *
8244 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008245 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008246 * 2) APN is un-metered for this subscription, or
8247 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008248 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008249 *
8250 * @return whether data is allowed for a apn type.
8251 *
8252 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008253 */
8254 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008255 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008256 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8257 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008258
8259 // Now that all security checks passes, perform the operation as ourselves.
8260 final long identity = Binder.clearCallingIdentity();
8261 try {
8262 Phone phone = getPhone(subId);
8263 if (phone == null) return false;
8264
Jack Yu41407ee2019-05-13 16:54:09 -07008265 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008266 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8267 } finally {
8268 Binder.restoreCallingIdentity(identity);
8269 }
8270 }
8271
8272 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008273 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008274 enforceReadPrivilegedPermission("isApnMetered");
8275
8276 // Now that all security checks passes, perform the operation as ourselves.
8277 final long identity = Binder.clearCallingIdentity();
8278 try {
8279 Phone phone = getPhone(subId);
8280 if (phone == null) return true; // By default return true.
8281
Jack Yu41407ee2019-05-13 16:54:09 -07008282 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008283 } finally {
8284 Binder.restoreCallingIdentity(identity);
8285 }
8286 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008287
8288 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008289 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8290 int subscriptionId, IBooleanConsumer resultCallback) {
8291 enforceModifyPermission();
8292 long token = Binder.clearCallingIdentity();
8293 try {
8294 Phone phone = getPhone(subscriptionId);
8295 if (phone == null) {
8296 try {
8297 if (resultCallback != null) {
8298 resultCallback.accept(false);
8299 }
8300 } catch (RemoteException e) {
8301 // ignore
8302 }
8303 return;
8304 }
8305 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8306 Pair.create(specifiers, (x) -> {
8307 try {
8308 if (resultCallback != null) {
8309 resultCallback.accept(x);
8310 }
8311 } catch (RemoteException e) {
8312 // ignore
8313 }
8314 });
8315 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8316 } finally {
8317 Binder.restoreCallingIdentity(token);
8318 }
8319 }
8320
8321 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008322 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008323 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008324 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8325 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8326 if (iccRecords == null) {
8327 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8328 return false;
8329 }
8330 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8331 }
8332
8333 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008334 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8335 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008336 if (callingPackage == null) {
8337 callingPackage = getCurrentPackageName();
8338 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008339 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8340 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008341 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8342 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008343 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8344 }
8345 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8346 Intent intent = new Intent();
8347 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8348 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8349 // Bring up choose default SMS subscription dialog right now
8350 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8351 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8352 mApp.startActivity(intent);
8353 }
chen xud5ca2d52019-05-28 15:20:57 -07008354
8355 @Override
8356 public String getMmsUAProfUrl(int subId) {
8357 //TODO investigate if this API should require proper permission check in R b/133791609
8358 final long identity = Binder.clearCallingIdentity();
8359 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008360 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8361 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8362 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8363 return carrierUAProfUrl;
8364 }
chen xud5ca2d52019-05-28 15:20:57 -07008365 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8366 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8367 } finally {
8368 Binder.restoreCallingIdentity(identity);
8369 }
8370 }
8371
8372 @Override
8373 public String getMmsUserAgent(int subId) {
8374 //TODO investigate if this API should require proper permission check in R b/133791609
8375 final long identity = Binder.clearCallingIdentity();
8376 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008377 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8378 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8379 if (!TextUtils.isEmpty(carrierUserAgent)) {
8380 return carrierUserAgent;
8381 }
chen xud5ca2d52019-05-28 15:20:57 -07008382 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8383 .getString(com.android.internal.R.string.config_mms_user_agent);
8384 } finally {
8385 Binder.restoreCallingIdentity(identity);
8386 }
8387 }
Jack Yub07d4972019-05-28 16:12:25 -07008388
8389 @Override
8390 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8391 enforceModifyPermission();
8392
8393 // Now that all security checks passes, perform the operation as ourselves.
8394 final long identity = Binder.clearCallingIdentity();
8395 try {
8396 Phone phone = getPhone(subId);
8397 if (phone == null) return false;
8398
8399 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 @Override
8406 public boolean isDataAllowedInVoiceCall(int subId) {
8407 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8408
8409 // Now that all security checks passes, perform the operation as ourselves.
8410 final long identity = Binder.clearCallingIdentity();
8411 try {
8412 Phone phone = getPhone(subId);
8413 if (phone == null) return false;
8414
8415 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8416 } finally {
8417 Binder.restoreCallingIdentity(identity);
8418 }
8419 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008420
changbetty97defcf2019-12-24 15:40:37 +08008421 @Override
8422 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8423 enforceModifyPermission();
8424
8425 // Now that all security checks passes, perform the operation as ourselves.
8426 final long identity = Binder.clearCallingIdentity();
8427 try {
8428 Phone phone = getPhone(subId);
8429 if (phone == null) return false;
8430
8431 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8432 } finally {
8433 Binder.restoreCallingIdentity(identity);
8434 }
8435 }
8436
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008437 /**
8438 * Updates whether conference event pacakge handling is enabled.
8439 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8440 * otherwise.
8441 */
8442 @Override
8443 public void setCepEnabled(boolean isCepEnabled) {
8444 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8445
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8449 for (Phone phone : PhoneFactory.getPhones()) {
8450 Phone defaultPhone = phone.getImsPhone();
8451 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8452 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8453 ImsPhoneCallTracker imsPhoneCallTracker =
8454 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8455 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8456 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8457 + imsPhone.getMsisdn());
8458 }
8459 }
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
8463 }
allenwtsu46dcc572020-01-08 18:24:03 +08008464
8465 /**
8466 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8467 *
8468 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8469 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8470 * before being read.
8471 */
8472 @Override
8473 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8474 isCompressed) {
8475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8476 mApp, subId, "notifyRcsAutoConfigurationReceived");
8477 try {
8478 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8479 if (configBinder == null) {
8480 Rlog.e(LOG_TAG, "null result for getImsConfig");
8481 } else {
8482 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8483 }
8484 } catch (RemoteException e) {
8485 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8486 }
8487 }
zoey chenf95ca592019-12-30 16:11:23 +08008488
8489 @Override
8490 public boolean isIccLockEnabled(int subId) {
8491 enforceReadPrivilegedPermission("isIccLockEnabled");
8492
8493 // Now that all security checks passes, perform the operation as ourselves.
8494 final long identity = Binder.clearCallingIdentity();
8495 try {
8496 Phone phone = getPhone(subId);
8497 if (phone != null && phone.getIccCard() != null) {
8498 return phone.getIccCard().getIccLockEnabled();
8499 } else {
8500 return false;
8501 }
8502 } finally {
8503 Binder.restoreCallingIdentity(identity);
8504 }
8505 }
8506
8507 /**
zoey chene02881a2019-12-30 16:11:23 +08008508 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008509 *
zoey chene02881a2019-12-30 16:11:23 +08008510 * @return an integer representing the status of IccLock enabled or disabled in the following
8511 * three cases:
8512 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8513 * successfully.
8514 * - Positive number and zero for remaining password attempts.
8515 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008516 *
8517 */
8518 @Override
8519 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8520 enforceModifyPermission();
8521
8522 Phone phone = getPhone(subId);
8523 if (phone == null) {
8524 return 0;
8525 }
8526 // Now that all security checks passes, perform the operation as ourselves.
8527 final long identity = Binder.clearCallingIdentity();
8528 try {
8529 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8530 new Pair<Boolean, String>(enabled, password), phone, null);
8531 return attemptsRemaining;
8532
8533 } catch (Exception e) {
8534 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8535 } finally {
8536 Binder.restoreCallingIdentity(identity);
8537 }
8538 return 0;
8539 }
8540
8541 /**
8542 * Change the ICC password used in ICC pin lock.
8543 *
zoey chene02881a2019-12-30 16:11:23 +08008544 * @return an integer representing the status of IccLock changed in the following three cases:
8545 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8546 * - Positive number and zero for remaining password attempts.
8547 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008548 *
8549 */
8550 @Override
8551 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8552 enforceModifyPermission();
8553
8554 Phone phone = getPhone(subId);
8555 if (phone == null) {
8556 return 0;
8557 }
8558 // Now that all security checks passes, perform the operation as ourselves.
8559 final long identity = Binder.clearCallingIdentity();
8560 try {
8561 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8562 new Pair<String, String>(oldPassword, newPassword), phone, null);
8563 return attemptsRemaining;
8564
8565 } catch (Exception e) {
8566 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8567 } finally {
8568 Binder.restoreCallingIdentity(identity);
8569 }
8570 return 0;
8571 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008572
Peter Wangdafb9ac2020-01-15 14:13:38 -08008573 /**
8574 * Request for receiving user activity notification
8575 */
8576 @Override
8577 public void requestUserActivityNotification() {
8578 if (!mNotifyUserActivity.get()
8579 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8580 mNotifyUserActivity.set(true);
8581 }
8582 }
8583
8584 /**
8585 * Called when userActivity is signalled in the power manager.
8586 * This is safe to call from any thread, with any window manager locks held or not.
8587 */
8588 @Override
8589 public void userActivity() {
8590 // ***************************************
8591 // * Inherited from PhoneWindowManager *
8592 // ***************************************
8593 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8594 // WITH ITS LOCKS HELD.
8595 //
8596 // This code must be VERY careful about the locks
8597 // it acquires.
8598 // In fact, the current code acquires way too many,
8599 // and probably has lurking deadlocks.
8600
8601 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8602 throw new SecurityException("Only the OS may call notifyUserActivity()");
8603 }
8604
8605 if (mNotifyUserActivity.getAndSet(false)) {
8606 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8607 USER_ACTIVITY_NOTIFICATION_DELAY);
8608 }
8609 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008610
Malcolm Chen884180b2020-04-13 11:59:40 -07008611 @Override
8612 public boolean canConnectTo5GInDsdsMode() {
8613 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8614 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008615}