blob: 7aef757271a76c1b0318d66374ffdc2362b377ce [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;
Hall Liua1548bd2019-12-24 14:14:12 -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;
Hall Liua1548bd2019-12-24 14:14:12 -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 Qiancd19c462020-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 Nallurid63128d2019-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 Kim14bb3d02018-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 Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -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 zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-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 Ebingera34a6c22019-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.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700316 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800766 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800767 if (ar.result == null) {
768 loge("getPreferredNetworkType: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("getPreferredNetworkType: CommandException: " +
771 ar.exception);
772 } else {
773 loge("getPreferredNetworkType: Unknown exception");
774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800777 break;
778
779 case CMD_SET_PREFERRED_NETWORK_TYPE:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
782 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700783 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800784 break;
785
786 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
787 handleNullReturnEvent(msg, "setPreferredNetworkType");
788 break;
789
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
791 request = (MainThreadRequest)msg.obj;
792 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000794 break;
795
796 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
797 ar = (AsyncResult)msg.obj;
798 request = (MainThreadRequest)ar.userObj;
799 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000801 break;
802
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800803 case CMD_SET_VOICEMAIL_NUMBER:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
806 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800807 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
808 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800809 break;
810
811 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
812 handleNullReturnEvent(msg, "setVoicemailNumber");
813 break;
814
Stuart Scott54788802015-03-30 13:18:01 -0700815 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
818 request);
819 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
823 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
824 break;
825
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 case CMD_PERFORM_NETWORK_SCAN:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
829 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
830 break;
831
Shuo Qian4a594052020-01-23 11:59:30 -0800832 case CMD_GET_CALL_FORWARDING:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
835 int callForwardingReason = (Integer) request.argument;
836 getPhoneFromRequest(request).getCallForwardingOption(
837 callForwardingReason, onCompleted);
838 break;
839
840 case EVENT_GET_CALL_FORWARDING_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 CallForwardingInfo callForwardingInfo = null;
844 if (ar.exception == null && ar.result != null) {
845 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
846 for (CallForwardInfo callForwardInfo : callForwardInfos) {
847 // Service Class is a bit mask per 3gpp 27.007. Search for
848 // any service for voice call.
849 if ((callForwardInfo.serviceClass
850 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
851 callForwardingInfo = new CallForwardingInfo(
852 callForwardInfo.serviceClass, callForwardInfo.reason,
853 callForwardInfo.number,
854 callForwardInfo.timeSeconds);
855 break;
856 }
857 }
858 // Didn't find a call forward info for voice call.
859 if (callForwardingInfo == null) {
860 callForwardingInfo = new CallForwardingInfo(
861 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
862 0 /* reason */, null /* number */, 0 /* timeout */);
863 }
864 } else {
865 if (ar.result == null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
867 }
868 if (ar.exception != null) {
869 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
870 }
871 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
872 if (ar.exception instanceof CommandException) {
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
876 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
879 }
880 }
881 callForwardingInfo = new CallForwardingInfo(
882 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
883 }
884 request.result = callForwardingInfo;
885 notifyRequester(request);
886 break;
887
888 case CMD_SET_CALL_FORWARDING:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
891 CallForwardingInfo callForwardingInfoToSet =
892 (CallForwardingInfo) request.argument;
893 getPhoneFromRequest(request).setCallForwardingOption(
894 callForwardingInfoToSet.getStatus(),
895 callForwardingInfoToSet.getReason(),
896 callForwardingInfoToSet.getNumber(),
897 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
898 break;
899
900 case EVENT_SET_CALL_FORWARDING_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null) {
904 request.result = true;
905 } else {
906 request.result = false;
907 loge("setCallForwarding exception: " + ar.exception);
908 }
909 notifyRequester(request);
910 break;
911
912 case CMD_GET_CALL_WAITING:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
915 getPhoneFromRequest(request).getCallWaiting(onCompleted);
916 break;
917
918 case EVENT_GET_CALL_WAITING_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
922 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800924 // Service Class is a bit mask per 3gpp 27.007.
925 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800926 if (callForwardResults.length > 1
927 && ((callForwardResults[1]
928 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
929 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800930 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
931 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
932 } else {
933 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
934 }
935 } else {
936 if (ar.result == null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
938 }
939 if (ar.exception != null) {
940 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
941 }
942 if (ar.exception instanceof CommandException) {
943 CommandException.Error error =
944 ((CommandException) (ar.exception)).getCommandError();
945 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
946 callForwardingStatus =
947 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
948 }
949 }
950 }
951 request.result = callForwardingStatus;
952 notifyRequester(request);
953 break;
954
955 case CMD_SET_CALL_WAITING:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
958 boolean isEnable = (Boolean) request.argument;
959 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
960 break;
961
962 case EVENT_SET_CALL_WAITING_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = true;
967 } else {
968 request.result = false;
969 loge("setCallWaiting exception: " + ar.exception);
970 }
971 notifyRequester(request);
972 break;
973
Shishir Agrawal302c8692015-06-19 13:49:39 -0700974 case EVENT_PERFORM_NETWORK_SCAN_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 CellNetworkScanResult cellScanResult;
978 if (ar.exception == null && ar.result != null) {
979 cellScanResult = new CellNetworkScanResult(
980 CellNetworkScanResult.STATUS_SUCCESS,
981 (List<OperatorInfo>) ar.result);
982 } else {
983 if (ar.result == null) {
984 loge("getCellNetworkScanResults: Empty response");
985 }
986 if (ar.exception != null) {
987 loge("getCellNetworkScanResults: Exception: " + ar.exception);
988 }
989 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.GENERIC_FAILURE) {
996 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
997 }
998 }
999 cellScanResult = new CellNetworkScanResult(errorCode, null);
1000 }
1001 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001002 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001003 break;
1004
1005 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1006 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001007 ManualNetworkSelectionArgument selArg =
1008 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001009 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1010 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001011 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1012 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001013 break;
1014
1015 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null) {
1019 request.result = true;
1020 } else {
1021 request.result = false;
1022 loge("setNetworkSelectionModeManual " + ar.exception);
1023 }
1024 notifyRequester(request);
1025 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001026 break;
1027
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001028 case CMD_GET_MODEM_ACTIVITY_INFO:
1029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001031 if (defaultPhone != null) {
1032 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001033 } else {
1034 ResultReceiver result = (ResultReceiver) request.argument;
1035 Bundle bundle = new Bundle();
1036 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1037 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1038 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001039 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001040 break;
1041
1042 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001045 ResultReceiver result = (ResultReceiver) request.argument;
1046
1047 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001048 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001049 // Update the last modem activity info and the result of the request.
1050 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1051 if (isModemActivityInfoValid(info)) {
1052 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1053 int[] txTimeMs = info.getTransmitTimeMillis();
1054 int[] lastModemTxTimeMs = mLastModemActivityInfo
1055 .getTransmitTimeMillis();
1056 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1057 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1058 }
1059 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1060 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1061 + mLastModemActivityInfo.getSleepTimeMillis());
1062 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1063 + mLastModemActivityInfo.getIdleTimeMillis());
1064 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1065 mLastModemActivityInfo.setReceiveTimeMillis(
1066 info.getReceiveTimeMillis()
1067 + mLastModemActivityInfo.getReceiveTimeMillis());
1068 }
1069 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1070 mLastModemActivityInfo.getSleepTimeMillis(),
1071 mLastModemActivityInfo.getIdleTimeMillis(),
1072 mLastModemActivityInfo.getTransmitTimeMillis(),
1073 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 } else {
1075 if (ar.result == null) {
1076 loge("queryModemActivityInfo: Empty response");
1077 } else if (ar.exception instanceof CommandException) {
1078 loge("queryModemActivityInfo: CommandException: " +
1079 ar.exception);
1080 } else {
1081 loge("queryModemActivityInfo: Unknown exception");
1082 }
1083 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001084 Bundle bundle = new Bundle();
1085 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1086 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001087 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001088 break;
1089
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 case CMD_SET_ALLOWED_CARRIERS:
1091 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001092 CarrierRestrictionRules argument =
1093 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001095 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001096 break;
1097
1098 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null && ar.result != null) {
1102 request.result = ar.result;
1103 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001104 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1105 if (ar.exception instanceof CommandException) {
1106 loge("setAllowedCarriers: CommandException: " + ar.exception);
1107 CommandException.Error error =
1108 ((CommandException) (ar.exception)).getCommandError();
1109 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1110 request.result =
1111 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1112 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001113 } else {
1114 loge("setAllowedCarriers: Unknown exception");
1115 }
1116 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001117 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001118 break;
1119
1120 case CMD_GET_ALLOWED_CARRIERS:
1121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001123 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001124 break;
1125
1126 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null && ar.result != null) {
1130 request.result = ar.result;
1131 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001132 request.result = new IllegalStateException(
1133 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001134 if (ar.result == null) {
1135 loge("getAllowedCarriers: Empty response");
1136 } else if (ar.exception instanceof CommandException) {
1137 loge("getAllowedCarriers: CommandException: " +
1138 ar.exception);
1139 } else {
1140 loge("getAllowedCarriers: Unknown exception");
1141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001144 break;
1145
Nathan Haroldb3014052017-01-25 15:57:32 -08001146 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 } else {
1152 request.result = new IllegalArgumentException(
1153 "Failed to retrieve Forbidden Plmns");
1154 if (ar.result == null) {
1155 loge("getForbiddenPlmns: Empty response");
1156 } else {
1157 loge("getForbiddenPlmns: Unknown exception");
1158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001161 break;
1162
1163 case CMD_GET_FORBIDDEN_PLMNS:
1164 request = (MainThreadRequest) msg.obj;
1165 uiccCard = getUiccCardFromRequest(request);
1166 if (uiccCard == null) {
1167 loge("getForbiddenPlmns() UiccCard is null");
1168 request.result = new IllegalArgumentException(
1169 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001171 break;
1172 }
1173 Integer appType = (Integer) request.argument;
1174 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1175 if (uiccApp == null) {
1176 loge("getForbiddenPlmns() no app with specified type -- "
1177 + appType);
1178 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001180 break;
1181 } else {
1182 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1183 + " specified type -- " + appType);
1184 }
1185 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1186 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1187 onCompleted);
1188 break;
1189
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001190 case CMD_SWITCH_SLOTS:
1191 request = (MainThreadRequest) msg.obj;
1192 int[] physicalSlots = (int[]) request.argument;
1193 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1194 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1195 break;
1196
1197 case EVENT_SWITCH_SLOTS_DONE:
1198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
1200 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
1202 break;
1203 case CMD_GET_NETWORK_SELECTION_MODE:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1206 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1207 break;
1208
1209 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
1212 if (ar.exception != null) {
1213 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1214 } else {
1215 int mode = ((int[]) ar.result)[0];
1216 if (mode == 0) {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1218 } else {
1219 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 notifyRequester(request);
1223 break;
1224 case CMD_GET_CDMA_ROAMING_MODE:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1227 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1228 break;
1229 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception != null) {
1233 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1234 } else {
1235 request.result = ((int[]) ar.result)[0];
1236 }
1237 notifyRequester(request);
1238 break;
1239 case CMD_SET_CDMA_ROAMING_MODE:
1240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1242 int mode = (int) request.argument;
1243 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1244 break;
1245 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1246 ar = (AsyncResult) msg.obj;
1247 request = (MainThreadRequest) ar.userObj;
1248 request.result = ar.exception == null;
1249 notifyRequester(request);
1250 break;
1251 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1254 int subscriptionMode = (int) request.argument;
1255 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1256 break;
1257 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
1260 request.result = ar.exception == null;
1261 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001262 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 case CMD_GET_ALL_CELL_INFO:
1264 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001266 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 case EVENT_GET_ALL_CELL_INFO_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001271 // If a timeout occurs, the response will be null
1272 request.result = (ar.exception == null && ar.result != null)
1273 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 synchronized (request) {
1275 request.notifyAll();
1276 }
1277 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001278 case CMD_REQUEST_CELL_INFO_UPDATE:
1279 request = (MainThreadRequest) msg.obj;
1280 request.phone.requestCellInfoUpdate(request.workSource,
1281 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1282 break;
1283 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1287 try {
1288 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001290 cb.onError(
1291 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1292 ar.exception.getClass().getName(),
1293 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001296 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 } else {
1298 // use the result as returned
1299 cb.onCellInfo((List<CellInfo>) ar.result);
1300 }
1301 } catch (RemoteException re) {
1302 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1303 }
1304 break;
1305 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001306 request = (MainThreadRequest) msg.obj;
1307 WorkSource ws = (WorkSource) request.argument;
1308 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001309 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001311 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null) {
1315 request.result = ar.result;
1316 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001317 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001319 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 }
1321
1322 synchronized (request) {
1323 request.notifyAll();
1324 }
1325 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001326 case CMD_MODEM_REBOOT:
1327 request = (MainThreadRequest) msg.obj;
1328 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001329 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001330 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001331 case EVENT_CMD_MODEM_REBOOT_DONE:
1332 handleNullReturnEvent(msg, "rebootModem");
1333 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001334 case CMD_REQUEST_ENABLE_MODEM:
1335 request = (MainThreadRequest) msg.obj;
1336 boolean enable = (boolean) request.argument;
1337 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001338 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001339 PhoneConfigurationManager.getInstance()
1340 .enablePhone(request.phone, enable, onCompleted);
1341 break;
1342 case EVENT_ENABLE_MODEM_DONE:
1343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
1345 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001347 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001348 if ((boolean) request.result) {
1349 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1350 updateModemStateMetrics();
1351 } else {
1352 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1353 + ar.exception);
1354 }
1355 notifyRequester(request);
1356 break;
1357 case CMD_GET_MODEM_STATUS:
1358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1360 PhoneConfigurationManager.getInstance()
1361 .getPhoneStatusFromModem(request.phone, onCompleted);
1362 break;
1363 case EVENT_GET_MODEM_STATUS_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 int id = request.phone.getPhoneId();
1367 if (ar.exception == null && ar.result != null) {
1368 request.result = ar.result;
1369 //update the cache as modem status has changed
1370 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1371 (boolean) request.result);
1372 } else {
1373 // Return true if modem status cannot be retrieved. For most cases,
1374 // modem status is on. And for older version modems, GET_MODEM_STATUS
1375 // and disable modem are not supported. Modem is always on.
1376 // TODO: this should be fixed in R to support a third
1377 // status UNKNOWN b/131631629
1378 request.result = true;
1379 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1380 + ar.exception);
1381 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001382 notifyRequester(request);
1383 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001384 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1385 request = (MainThreadRequest) msg.obj;
1386 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1388 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1389 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1390 break;
1391 }
1392 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1396 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1397 args.second.accept(ar.exception == null);
1398 notifyRequester(request);
1399 break;
1400 }
yincheng zhao2737e882019-09-06 17:06:54 -07001401 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception == null && ar.result != null) {
1405 request.result = ar.result;
1406 } else {
1407 request.result = -1;
1408 loge("Failed to set Forbidden Plmns");
1409 if (ar.result == null) {
1410 loge("setForbidenPlmns: Empty response");
1411 } else if (ar.exception != null) {
1412 loge("setForbiddenPlmns: Exception: " + ar.exception);
1413 request.result = -1;
1414 } else {
1415 loge("setForbiddenPlmns: Unknown exception");
1416 }
1417 }
1418 notifyRequester(request);
1419 break;
1420 case CMD_SET_FORBIDDEN_PLMNS:
1421 request = (MainThreadRequest) msg.obj;
1422 uiccCard = getUiccCardFromRequest(request);
1423 if (uiccCard == null) {
1424 loge("setForbiddenPlmns: UiccCard is null");
1425 request.result = -1;
1426 notifyRequester(request);
1427 break;
1428 }
1429 Pair<Integer, List<String>> setFplmnsArgs =
1430 (Pair<Integer, List<String>>) request.argument;
1431 appType = setFplmnsArgs.first;
1432 List<String> fplmns = setFplmnsArgs.second;
1433 uiccApp = uiccCard.getApplicationByType(appType);
1434 if (uiccApp == null) {
1435 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1436 request.result = -1;
1437 loge("Failed to get UICC App");
1438 notifyRequester(request);
1439 } else {
1440 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1441 ((SIMRecords) uiccApp.getIccRecords())
1442 .setForbiddenPlmns(onCompleted, fplmns);
1443 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001444 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001445 case CMD_ERASE_MODEM_CONFIG:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1448 defaultPhone.eraseModemConfig(onCompleted);
1449 break;
1450 case EVENT_ERASE_MODEM_CONFIG_DONE:
1451 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001452 break;
zoey chene02881a2019-12-30 16:11:23 +08001453
1454 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1457 Pair<String, String> changed = (Pair<String, String>) request.argument;
1458 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1459 changed.first, changed.second, onCompleted);
1460 break;
1461 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 if (ar.exception == null) {
1465 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1466 } else {
1467 request.result = msg.arg1;
1468 }
1469 notifyRequester(request);
1470 break;
1471
1472 case CMD_SET_ICC_LOCK_ENABLED:
1473 request = (MainThreadRequest) msg.obj;
1474 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1475 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1476 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1477 enabled.first, enabled.second, onCompleted);
1478 break;
1479 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null) {
1483 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1484 } else {
1485 request.result = msg.arg1;
1486 }
1487 notifyRequester(request);
1488 break;
1489
Peter Wangdafb9ac2020-01-15 14:13:38 -08001490 case MSG_NOTIFY_USER_ACTIVITY:
1491 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001492 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001493 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1494 getDefaultPhone().getContext().sendBroadcastAsUser(
1495 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1496 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 default:
1498 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1499 break;
1500 }
1501 }
Jake Hambye994d462014-02-03 13:10:13 -08001502
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 private void notifyRequester(MainThreadRequest request) {
1504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 }
1508
Jake Hambye994d462014-02-03 13:10:13 -08001509 private void handleNullReturnEvent(Message msg, String command) {
1510 AsyncResult ar = (AsyncResult) msg.obj;
1511 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception == null) {
1513 request.result = true;
1514 } else {
1515 request.result = false;
1516 if (ar.exception instanceof CommandException) {
1517 loge(command + ": CommandException: " + ar.exception);
1518 } else {
1519 loge(command + ": Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525
1526 /**
1527 * Posts the specified command to be executed on the main thread,
1528 * waits for the request to complete, and returns the result.
1529 * @see #sendRequestAsync
1530 */
1531 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001532 return sendRequest(
1533 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001534 }
1535
1536 /**
1537 * Posts the specified command to be executed on the main thread,
1538 * waits for the request to complete, and returns the result.
1539 * @see #sendRequestAsync
1540 */
1541 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1542 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001543 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
1546 /**
1547 * Posts the specified command to be executed on the main thread,
1548 * waits for the request to complete, and returns the result.
1549 * @see #sendRequestAsync
1550 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001551 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001552 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001553 }
1554
1555 /**
1556 * Posts the specified command to be executed on the main thread,
1557 * waits for the request to complete, and returns the result.
1558 * @see #sendRequestAsync
1559 */
Nathan Harold92bed182018-10-12 18:16:49 -07001560 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1561 return sendRequest(command, argument, subId, null, workSource);
1562 }
1563
1564 /**
1565 * Posts the specified command to be executed on the main thread,
1566 * waits for the request to complete, and returns the result.
1567 * @see #sendRequestAsync
1568 */
1569 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1570 return sendRequest(
1571 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1572 }
1573
1574 /**
1575 * Posts the specified command to be executed on the main thread,
1576 * waits for the request to complete, and returns the result.
1577 * @see #sendRequestAsync
1578 */
1579 private Object sendRequest(
1580 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1582 throw new RuntimeException("This method will deadlock if called from the main thread.");
1583 }
1584
Nathan Harold92bed182018-10-12 18:16:49 -07001585 MainThreadRequest request = null;
1586 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1587 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1588 } else if (phone != null) {
1589 request = new MainThreadRequest(argument, phone, workSource);
1590 } else {
1591 request = new MainThreadRequest(argument, subId, workSource);
1592 }
1593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 Message msg = mMainThreadHandler.obtainMessage(command, request);
1595 msg.sendToTarget();
1596
1597 // Wait for the request to complete
1598 synchronized (request) {
1599 while (request.result == null) {
1600 try {
1601 request.wait();
1602 } catch (InterruptedException e) {
1603 // Do nothing, go back and wait until the request is complete
1604 }
1605 }
1606 }
1607 return request.result;
1608 }
1609
1610 /**
1611 * Asynchronous ("fire and forget") version of sendRequest():
1612 * Posts the specified command to be executed on the main thread, and
1613 * returns immediately.
1614 * @see #sendRequest
1615 */
1616 private void sendRequestAsync(int command) {
1617 mMainThreadHandler.sendEmptyMessage(command);
1618 }
1619
1620 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001622 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001623 */
1624 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 sendRequestAsync(command, argument, null, null);
1626 }
1627
1628 /**
1629 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1630 * @see {@link #sendRequest(int,Object)}
1631 */
1632 private void sendRequestAsync(
1633 int command, Object argument, Phone phone, WorkSource workSource) {
1634 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001635 Message msg = mMainThreadHandler.obtainMessage(command, request);
1636 msg.sendToTarget();
1637 }
1638
1639 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 * Initialize the singleton PhoneInterfaceManager instance.
1641 * This is only done once, at startup, from PhoneApp.onCreate().
1642 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001643 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 synchronized (PhoneInterfaceManager.class) {
1645 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 } else {
1648 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1649 }
1650 return sInstance;
1651 }
1652 }
1653
1654 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001655 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001658 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001659 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1661 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001662 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001663 mTelephonySharedPreferences =
1664 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001665 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001666 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001667 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001668
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 publish();
1670 }
1671
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001672 private Phone getDefaultPhone() {
1673 Phone thePhone = getPhone(getDefaultSubscription());
1674 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1675 }
1676
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 private void publish() {
1678 if (DBG) log("publish: " + this);
1679
Peter Wangc035ce42020-01-08 21:00:22 -08001680 TelephonyFrameworkInitializer
1681 .getTelephonyServiceManager()
1682 .getTelephonyServiceRegisterer()
1683 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Stuart Scott584921c2015-01-15 17:10:34 -08001686 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001687 if (request.phone != null) {
1688 return request.phone;
1689 } else {
1690 return getPhoneFromSubId(request.subId);
1691 }
1692 }
1693
1694 private Phone getPhoneFromSubId(int subId) {
1695 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1696 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001697 }
1698
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001699 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1700 Phone phone = getPhoneFromRequest(request);
1701 return phone == null ? null :
1702 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1703 }
1704
Wink Saville36469e72014-06-11 15:17:00 -07001705 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001707 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709
Naina Nallurid63128d2019-09-17 14:10:30 -07001710 private void sendEraseModemConfig(Phone phone) {
1711 if (phone != null) {
1712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1713 mApp, phone.getSubId(), "eraseModemConfig");
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1717 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
1720 }
1721 }
1722 }
1723
Peter Wang44b186e2020-01-13 23:33:09 -08001724 private boolean isImsAvailableOnDevice() {
1725 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1726 if (pm == null) {
1727 // For some reason package manger is not available.. This will fail internally anyway,
1728 // so do not throw error and allow.
1729 return true;
1730 }
1731 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1732 }
1733
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001735 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001736 }
1737
Wink Savilleb564aae2014-10-23 10:18:09 -07001738 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 if (DBG) log("dial: " + number);
1740 // No permission check needed here: This is just a wrapper around the
1741 // ACTION_DIAL intent, which is available to any app since it puts up
1742 // the UI before it does anything.
1743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 String url = createTelUrl(number);
1747 if (url == null) {
1748 return;
1749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001751 // PENDING: should we just silently fail if phone is offhook or ringing?
1752 PhoneConstants.State state = mCM.getState(subId);
1753 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1754 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1755 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1756 mApp.startActivity(intent);
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761 }
1762
1763 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
Wink Savilleb564aae2014-10-23 10:18:09 -07001767 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 if (DBG) log("call: " + number);
1769
1770 // This is just a wrapper around the ACTION_CALL intent, but we still
1771 // need to do a permission check since we're calling startActivity()
1772 // from the context of the phone app.
1773 enforceCallPermission();
1774
Jordan Liu1617b712019-07-10 15:06:26 -07001775 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 != AppOpsManager.MODE_ALLOWED) {
1777 return;
1778 }
1779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 String url = createTelUrl(number);
1783 if (url == null) {
1784 return;
1785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787 boolean isValid = false;
1788 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1789 if (slist != null) {
1790 for (SubscriptionInfo subInfoRecord : slist) {
1791 if (subInfoRecord.getSubscriptionId() == subId) {
1792 isValid = true;
1793 break;
1794 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001795 }
Wink Saville08874612014-08-31 19:19:58 -07001796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 if (!isValid) {
1798 return;
1799 }
Wink Saville08874612014-08-31 19:19:58 -07001800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1802 intent.putExtra(SUBSCRIPTION_KEY, subId);
1803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1804 mApp.startActivity(intent);
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Wink Savilleb564aae2014-10-23 10:18:09 -07001810 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001811 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001812 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001816 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001817 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1818 }
1819
Wink Savilleb564aae2014-10-23 10:18:09 -07001820 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1826 checkSimPin.start();
1827 return checkSimPin.unlockSim(null, pin);
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
1830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Wink Savilleb564aae2014-10-23 10:18:09 -07001833 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1839 checkSimPuk.start();
1840 return checkSimPuk.unlockSim(puk, pin);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 }
1845
1846 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001847 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 * a synchronous one.
1849 */
1850 private static class UnlockSim extends Thread {
1851
1852 private final IccCard mSimCard;
1853
1854 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001855 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1856 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857
1858 // For replies from SimCard interface
1859 private Handler mHandler;
1860
1861 // For async handler to identify request type
1862 private static final int SUPPLY_PIN_COMPLETE = 100;
1863
1864 public UnlockSim(IccCard simCard) {
1865 mSimCard = simCard;
1866 }
1867
1868 @Override
1869 public void run() {
1870 Looper.prepare();
1871 synchronized (UnlockSim.this) {
1872 mHandler = new Handler() {
1873 @Override
1874 public void handleMessage(Message msg) {
1875 AsyncResult ar = (AsyncResult) msg.obj;
1876 switch (msg.what) {
1877 case SUPPLY_PIN_COMPLETE:
1878 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1879 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001880 mRetryCount = msg.arg1;
1881 if (ar.exception != null) {
1882 if (ar.exception instanceof CommandException &&
1883 ((CommandException)(ar.exception)).getCommandError()
1884 == CommandException.Error.PASSWORD_INCORRECT) {
1885 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001886 } //When UiccCardApp dispose,handle message and return exception
1887 else if (ar.exception instanceof CommandException &&
1888 ((CommandException) (ar.exception)).getCommandError()
1889 == CommandException.Error.ABORTED) {
1890 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001891 } else {
1892 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1893 }
1894 } else {
1895 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 mDone = true;
1898 UnlockSim.this.notifyAll();
1899 }
1900 break;
1901 }
1902 }
1903 };
1904 UnlockSim.this.notifyAll();
1905 }
1906 Looper.loop();
1907 }
1908
1909 /*
1910 * Use PIN or PUK to unlock SIM card
1911 *
1912 * If PUK is null, unlock SIM card with PIN
1913 *
1914 * If PUK is not null, unlock SIM card with PUK and set PIN code
1915 */
Wink Saville9de0f752013-10-22 19:04:03 -07001916 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917
1918 while (mHandler == null) {
1919 try {
1920 wait();
1921 } catch (InterruptedException e) {
1922 Thread.currentThread().interrupt();
1923 }
1924 }
1925 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1926
1927 if (puk == null) {
1928 mSimCard.supplyPin(pin, callback);
1929 } else {
1930 mSimCard.supplyPuk(puk, pin, callback);
1931 }
1932
1933 while (!mDone) {
1934 try {
1935 Log.d(LOG_TAG, "wait for done");
1936 wait();
1937 } catch (InterruptedException e) {
1938 // Restore the interrupted status
1939 Thread.currentThread().interrupt();
1940 }
1941 }
1942 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001943 int[] resultArray = new int[2];
1944 resultArray[0] = mResult;
1945 resultArray[1] = mRetryCount;
1946 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948 }
1949
1950 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001951 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952
1953 }
1954
Wink Savilleb564aae2014-10-23 10:18:09 -07001955 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 // No permission check needed here: this call is harmless, and it's
1957 // needed for the ServiceState.requestStateUpdate() call (which is
1958 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 phone.updateServiceLocation();
1964 }
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001970 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001971 @Override
1972 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001973 return isRadioOnWithFeature(callingPackage, null);
1974 }
1975
1976
1977 @Override
1978 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1979 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1980 callingFeatureId);
1981 }
1982
1983 @Deprecated
1984 @Override
1985 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1986 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001987 }
1988
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001990 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1991 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001993 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001994 return false;
1995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996
1997 final long identity = Binder.clearCallingIdentity();
1998 try {
1999 return isRadioOnForSubscriber(subId);
2000 } finally {
2001 Binder.restoreCallingIdentity(identity);
2002 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002003 }
2004
2005 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 final Phone phone = getPhone(subId);
2009 if (phone != null) {
2010 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2011 } else {
2012 return false;
2013 }
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
2019 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002020 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
Wink Saville36469e72014-06-11 15:17:00 -07002022
Wink Savilleb564aae2014-10-23 10:18:09 -07002023 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 final Phone phone = getPhone(subId);
2029 if (phone != null) {
2030 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2031 }
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002034 }
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
2037 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002038 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002039 }
2040
Wink Savilleb564aae2014-10-23 10:18:09 -07002041 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002043
2044 final long identity = Binder.clearCallingIdentity();
2045 try {
2046 final Phone phone = getPhone(subId);
2047 if (phone == null) {
2048 return false;
2049 }
2050 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2051 toggleRadioOnOffForSubscriber(subId);
2052 }
2053 return true;
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
Wink Saville36469e72014-06-11 15:17:00 -07002058
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002059 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002060 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002061 /*
2062 * If any of the Radios are available, it will need to be
2063 * shutdown. So return true if any Radio is available.
2064 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002065 final long identity = Binder.clearCallingIdentity();
2066 try {
2067 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2068 Phone phone = PhoneFactory.getPhone(i);
2069 if (phone != null && phone.isRadioAvailable()) return true;
2070 }
2071 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2072 return false;
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002076 }
2077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002079 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 enforceModifyPermission();
2081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2085 logv("Shutting down Phone " + i);
2086 shutdownRadioUsingPhoneId(i);
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002090 }
2091 }
2092
2093 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002094 Phone phone = PhoneFactory.getPhone(phoneId);
2095 if (phone != null && phone.isRadioAvailable()) {
2096 phone.shutdownRadio();
2097 }
2098 }
2099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2106 if (defaultPhone != null) {
2107 defaultPhone.setRadioPower(turnOn);
2108 return true;
2109 } else {
2110 loge("There's no default phone.");
2111 return false;
2112 }
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002115 }
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Wink Savilleb564aae2014-10-23 10:18:09 -07002118 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
2125 phone.setRadioPower(turnOn);
2126 return true;
2127 } else {
2128 return false;
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Wink Saville36469e72014-06-11 15:17:00 -07002135 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 public boolean enableDataConnectivity() {
2138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 int subId = mSubscriptionController.getDefaultDataSubId();
2143 final Phone phone = getPhone(subId);
2144 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002145 phone.getDataEnabledSettings().setDataEnabled(
2146 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 return true;
2148 } else {
2149 return false;
2150 }
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
Wink Saville36469e72014-06-11 15:17:00 -07002156 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002157 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 public boolean disableDataConnectivity() {
2159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 int subId = mSubscriptionController.getDefaultDataSubId();
2164 final Phone phone = getPhone(subId);
2165 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002166 phone.getDataEnabledSettings().setDataEnabled(
2167 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 return true;
2169 } else {
2170 return false;
2171 }
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 }
2176
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002178 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 final Phone phone = getPhone(subId);
2182 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002183 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184 } else {
2185 return false;
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
2192 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
pkanwarae03a6b2016-11-06 20:37:09 -08002196 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197 enforceCallPermission();
2198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2202 return;
2203 }
2204 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2205 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
2208 }
pkanwar32d516d2016-10-14 19:37:38 -07002209 };
2210
Wink Savilleb564aae2014-10-23 10:18:09 -07002211 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213
2214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2217 return false;
2218 }
2219 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002226 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002229 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 Phone phone = PhoneFactory.getPhone(slotIndex);
2233 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2234 PhoneConstantConversions.convertCallState(phone.getState());
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002241 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002242 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2243 }
2244
2245 @Override
2246 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 final long identity = Binder.clearCallingIdentity();
2248 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 if (phone != null) {
2251 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2252 } else {
2253 return PhoneConstantConversions.convertDataState(
2254 PhoneConstants.DataState.DISCONNECTED);
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002262 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002263 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2264 }
2265
2266 @Override
2267 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002270 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 if (phone != null) {
2272 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2273 } else {
2274 return TelephonyManager.DATA_ACTIVITY_NONE;
2275 }
2276 } finally {
2277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002282 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002283 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002284 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002285
2286 LocationAccessPolicy.LocationPermissionResult locationResult =
2287 LocationAccessPolicy.checkLocationPermission(mApp,
2288 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2289 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002290 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002291 .setCallingPid(Binder.getCallingPid())
2292 .setCallingUid(Binder.getCallingUid())
2293 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002294 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2296 .build());
2297 switch (locationResult) {
2298 case DENIED_HARD:
2299 throw new SecurityException("Not allowed to access cell location");
2300 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002301 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2302 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002309 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002310 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Svetoslav64fad262015-04-14 14:35:21 -07002314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002317 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2319 // registered cell info, so return a NULL country instead.
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002322 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2323 // Get default phone in this case.
2324 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2325 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002326 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002328 if (phone == null) return "";
2329 ServiceStateTracker sst = phone.getServiceStateTracker();
2330 if (sst == null) return "";
2331 LocaleTracker lt = sst.getLocaleTracker();
2332 if (lt == null) return "";
2333 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2334 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2335 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002339 }
2340
2341 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002343 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002344 }
2345
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002347 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 mApp.enforceCallingOrSelfPermission(
2349 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 final Phone phone = getPhone(subId);
2354 if (phone != null) {
2355 phone.enableLocationUpdates();
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 @Override
2363 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002368 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 mApp.enforceCallingOrSelfPermission(
2370 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 final Phone phone = getPhone(subId);
2375 if (phone != null) {
2376 phone.disableLocationUpdates();
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382
Nathan Harold31d7ff32018-10-15 20:20:30 -07002383 /**
2384 * Returns the target SDK version number for a given package name.
2385 *
Nathan Haroldec184742019-07-10 17:04:16 -07002386 * This call MUST be invoked before clearing the calling UID.
2387 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 * @return target SDK if the package is found or INT_MAX.
2389 */
2390 private int getTargetSdk(String packageName) {
2391 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002392 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002393 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002394 if (ai != null) return ai.targetSdkVersion;
2395 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002396 loge("Failed to get package info for pkg="
2397 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002398 }
2399 return Integer.MAX_VALUE;
2400 }
2401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 @Override
2403 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002404 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2405 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002406 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002407 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2408 throw new SecurityException(
2409 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2410 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002411
Jordan Liu1617b712019-07-10 15:06:26 -07002412 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2414 return null;
2415 }
Svetoslav64fad262015-04-14 14:35:21 -07002416
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002417 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002419 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002420 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421
Nathan Haroldf180aac2018-06-01 18:43:55 -07002422 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2423 for (CellInfo ci : info) {
2424 if (ci instanceof CellInfoGsm) {
2425 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2426 } else if (ci instanceof CellInfoWcdma) {
2427 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002430 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002433 private List<CellInfo> getCachedCellInfo() {
2434 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2435 for (Phone phone : PhoneFactory.getPhones()) {
2436 List<CellInfo> info = phone.getAllCellInfo();
2437 if (info != null) cellInfos.addAll(info);
2438 }
2439 return cellInfos;
2440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441
2442 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002443 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002445 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002446
2447 LocationAccessPolicy.LocationPermissionResult locationResult =
2448 LocationAccessPolicy.checkLocationPermission(mApp,
2449 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2450 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002451 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002452 .setCallingPid(Binder.getCallingPid())
2453 .setCallingUid(Binder.getCallingUid())
2454 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002455 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002456 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2457 .build());
2458 switch (locationResult) {
2459 case DENIED_HARD:
2460 throw new SecurityException("Not allowed to access cell info");
2461 case DENIED_SOFT:
2462 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 final int targetSdk = getTargetSdk(callingPackage);
2466 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2467 return getCachedCellInfo();
2468 }
2469
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002470 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2475 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002476 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002477 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 if (info != null) cellInfos.addAll(info);
2479 }
2480 return cellInfos;
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484 }
2485
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002486 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002487 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2488 String callingFeatureId) {
2489 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2490 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 }
2492
2493 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002494 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2495 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002496 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002497 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002498 }
2499
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2501 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002502 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002503 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002504
2505 LocationAccessPolicy.LocationPermissionResult locationResult =
2506 LocationAccessPolicy.checkLocationPermission(mApp,
2507 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2508 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002509 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002510 .setCallingPid(Binder.getCallingPid())
2511 .setCallingUid(Binder.getCallingUid())
2512 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002513 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2514 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002515 .build());
2516 switch (locationResult) {
2517 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002518 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2519 // Safetynet logging for b/154934934
2520 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2521 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002522 throw new SecurityException("Not allowed to access cell info");
2523 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002524 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2525 // Safetynet logging for b/154934934
2526 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2527 }
Nathan Harold5320c422019-05-09 10:26:08 -07002528 try {
2529 cb.onCellInfo(new ArrayList<CellInfo>());
2530 } catch (RemoteException re) {
2531 // Drop without consequences
2532 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002533 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002534 }
2535
Nathan Harolda939a962019-05-09 10:13:47 -07002536
2537 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002538 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2539
2540 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2541 }
2542
2543 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002545 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002550 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
Shishir Agrawala9f32182016-04-12 12:00:16 -07002556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002557 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002558 Phone phone = PhoneFactory.getPhone(slotIndex);
2559 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002560 return null;
2561 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002563 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002564 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002565 return null;
2566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 return phone.getImei();
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
2573 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002574 }
2575
2576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002577 public String getTypeAllocationCodeForSlot(int slotIndex) {
2578 Phone phone = PhoneFactory.getPhone(slotIndex);
2579 String tac = null;
2580 if (phone != null) {
2581 String imei = phone.getImei();
2582 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2583 }
2584 return tac;
2585 }
2586
2587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002588 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 Phone phone = PhoneFactory.getPhone(slotIndex);
2590 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002591 return null;
2592 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002593
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002595 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002597 return null;
2598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 return phone.getMeid();
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
2605 }
Jack Yu2af8d712017-03-15 17:14:14 -07002606 }
2607
2608 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002609 public String getManufacturerCodeForSlot(int slotIndex) {
2610 Phone phone = PhoneFactory.getPhone(slotIndex);
2611 String manufacturerCode = null;
2612 if (phone != null) {
2613 String meid = phone.getMeid();
2614 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2615 }
2616 return manufacturerCode;
2617 }
2618
2619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002620 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2621 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002622 Phone phone = PhoneFactory.getPhone(slotIndex);
2623 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 return null;
2625 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002626 int subId = phone.getSubId();
2627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 mApp, subId, callingPackage, callingFeatureId,
2629 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002630 return null;
2631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return phone.getDeviceSvn();
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002639 }
2640
fionaxu43304da2017-11-27 22:51:16 -08002641 @Override
2642 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
fionaxu43304da2017-11-27 22:51:16 -08002650 }
2651
2652 @Override
2653 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 return phone == null ? null : phone.getCarrierName();
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
fionaxu43304da2017-11-27 22:51:16 -08002661 }
2662
calvinpanffe225e2018-11-01 19:43:06 +08002663 @Override
chen xu0026ca62019-03-06 15:28:50 -08002664 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002669 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
2675 @Override
chen xu0026ca62019-03-06 15:28:50 -08002676 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002680 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
2684 }
2685
chen xu651eec72018-11-11 19:03:44 -08002686 @Override
chen xu864e11c2018-12-06 22:10:03 -08002687 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2688 if (!isSubscriptionMccMnc) {
2689 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2690 }
chen xu651eec72018-11-11 19:03:44 -08002691 final Phone phone = PhoneFactory.getPhone(slotIndex);
2692 if (phone == null) {
2693 return TelephonyManager.UNKNOWN_CARRIER_ID;
2694 }
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
2701 }
2702
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 //
2704 // Internal helper methods.
2705 //
2706
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002707 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2709 *
2710 * @throws SecurityException if the caller does not have the required permission
2711 */
2712 private void enforceModifyPermission() {
2713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2714 }
2715
Shuo Qiancd19c462020-01-16 20:51:11 -08002716 /**
2717 * Make sure the caller is system.
2718 *
2719 * @throws SecurityException if the caller is not system.
2720 */
2721 private void enforceSystemCaller() {
2722 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2723 throw new SecurityException("Caller must be system");
2724 }
2725 }
2726
Shuo Qian3b6ee772019-11-13 17:43:31 -08002727 private void enforceActiveEmergencySessionPermission() {
2728 mApp.enforceCallingOrSelfPermission(
2729 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2730 }
2731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 /**
2733 * Make sure the caller has the CALL_PHONE permission.
2734 *
2735 * @throws SecurityException if the caller does not have the required permission
2736 */
2737 private void enforceCallPermission() {
2738 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2739 }
2740
paulhu5a773602019-08-23 19:17:33 +08002741 private void enforceSettingsPermission() {
2742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002743 }
2744
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 private String createTelUrl(String number) {
2746 if (TextUtils.isEmpty(number)) {
2747 return null;
2748 }
2749
Jake Hambye994d462014-02-03 13:10:13 -08002750 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
Ihab Awadf9e92732013-12-05 18:02:52 -08002753 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2755 }
2756
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002757 private static void logv(String msg) {
2758 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2759 }
2760
Ihab Awadf9e92732013-12-05 18:02:52 -08002761 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2763 }
2764
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002765 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002767 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002768 }
2769
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002771 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 final Phone phone = PhoneFactory.getPhone(slotIndex);
2775 if (phone == null) {
2776 return PhoneConstants.PHONE_TYPE_NONE;
2777 } else {
2778 return phone.getPhoneType();
2779 }
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
2785 /**
2786 * Returns the CDMA ERI icon index to display
2787 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002789 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2790 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2791 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002792 }
2793
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2796 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002798 mApp, subId, callingPackage, callingFeatureId,
2799 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002800 return -1;
2801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 return phone.getCdmaEriIconIndex();
2808 } else {
2809 return -1;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
2816 /**
2817 * Returns the CDMA ERI icon mode,
2818 * 0 - ON
2819 * 1 - FLASHING
2820 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2823 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2824 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002825 }
2826
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2829 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 mApp, subId, callingPackage, callingFeatureId,
2832 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 return -1;
2834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
2840 return phone.getCdmaEriIconMode();
2841 } else {
2842 return -1;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 /**
2850 * Returns the CDMA ERI text,
2851 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2854 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2855 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002862 mApp, subId, callingPackage, callingFeatureId,
2863 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 return null;
2865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
2871 return phone.getCdmaEriText();
2872 } else {
2873 return null;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
2880 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002881 * Returns the CDMA MDN.
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002884 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2886 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return phone.getLine1Number();
2893 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 return null;
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002899 }
2900 }
2901
2902 /**
2903 * Returns the CDMA MIN.
2904 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002906 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2908 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2914 return phone.getCdmaMin();
2915 } else {
2916 return null;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002920 }
2921 }
2922
Hall Liud892bec2018-11-30 14:51:45 -08002923 @Override
2924 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2925 INumberVerificationCallback callback, String callingPackage) {
2926 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2927 != PERMISSION_GRANTED) {
2928 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2929 }
2930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2931
2932 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2933 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2934 throw new SecurityException("Calling package must be configured in the device config");
2935 }
2936
2937 if (range == null) {
2938 throw new NullPointerException("Range must be non-null");
2939 }
2940
2941 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002942 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002943
2944 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2945 }
2946
Junda Liuca05d5d2014-08-14 22:36:34 -07002947 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 * Returns true if CDMA provisioning needs to run.
2949 */
2950 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
2959 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002960 * Sets the voice mail number of a given subId.
2961 */
2962 @Override
2963 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2965 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2970 new Pair<String, String>(alphaTag, number), new Integer(subId));
2971 return success;
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002975 }
2976
Ta-wei Yen87c49842016-05-13 21:19:52 -07002977 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002978 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002980 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2981 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002982 if (!TextUtils.equals(callingPackage, systemDialer)) {
2983 throw new SecurityException("caller must be system dialer");
2984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2989 if (phoneAccountHandle == null) {
2990 return null;
2991 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002995 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002996 }
2997
2998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002999 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3000 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003003 mApp, subId, callingPackage, callingFeatureId,
3004 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003005 return null;
3006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003008 final long identity = Binder.clearCallingIdentity();
3009 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003014 }
3015
3016 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003017 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3018 VisualVoicemailSmsFilterSettings settings) {
3019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003028 }
3029
3030 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003031 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003041 }
3042
3043 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003044 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3045 String callingPackage, int subId) {
3046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003051 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003055 }
3056
3057 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003058 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003064 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003068 }
3069
3070 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003071 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3072 String callingAttributionTag, int subId, String number, int port, String text,
3073 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003075 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003076 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003077 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003078 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3079 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003080 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003081
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003082 /**
fionaxu0152e512016-11-14 13:36:14 -08003083 * Sets the voice activation state of a given subId.
3084 */
3085 @Override
3086 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final Phone phone = getPhone(subId);
3093 if (phone != null) {
3094 phone.setVoiceActivationState(activationState);
3095 } else {
3096 loge("setVoiceActivationState fails with invalid subId: " + subId);
3097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003100 }
3101 }
3102
3103 /**
3104 * Sets the data activation state of a given subId.
3105 */
3106 @Override
3107 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3109 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
3115 phone.setDataActivationState(activationState);
3116 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003117 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003121 }
3122 }
3123
3124 /**
3125 * Returns the voice activation state of a given subId.
3126 */
3127 @Override
3128 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
fionaxu0152e512016-11-14 13:36:14 -08003131 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 if (phone != null) {
3135 return phone.getVoiceActivationState();
3136 } else {
3137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3138 }
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003141 }
3142 }
3143
3144 /**
3145 * Returns the data activation state of a given subId.
3146 */
3147 @Override
3148 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150
fionaxu0152e512016-11-14 13:36:14 -08003151 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 if (phone != null) {
3155 return phone.getDataActivationState();
3156 } else {
3157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003161 }
3162 }
3163
3164 /**
Wink Saville36469e72014-06-11 15:17:00 -07003165 * Returns the unread count of voicemails for a subId
3166 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003168 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3169 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003171 mApp, subId, callingPackage, callingFeatureId,
3172 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003173 return 0;
3174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 if (phone != null) {
3179 return phone.getVoiceMessageCount();
3180 } else {
3181 return 0;
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
3188 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003189 * returns true, if the device is in a state where both voice and data
3190 * are supported simultaneously. This can change based on location or network condition.
3191 */
3192 @Override
3193 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
3197 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003201 }
3202
3203 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003204 * Send the dialer code if called from the current default dialer or the caller has
3205 * carrier privilege.
3206 * @param inputCode The dialer code to send
3207 */
3208 @Override
3209 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003210 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003212 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3213 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003214 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003215 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
3219 final long identity = Binder.clearCallingIdentity();
3220 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
fionaxu235cc5e2017-03-06 22:25:57 -08003225 }
3226
Pengquan Menga1bb6272018-09-06 09:59:22 -07003227 @Override
3228 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003229 TelephonyPermissions
3230 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3231 mApp, subId, "getNetworkSelectionMode");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 if (!isActiveSubscription(subId)) {
3235 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3236 }
3237 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003241 }
3242
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003244 public boolean isInEmergencySmsMode() {
3245 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 for (Phone phone : PhoneFactory.getPhones()) {
3249 if (phone.isInEmergencySmsMode()) {
3250 return true;
3251 }
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 return false;
3257 }
3258
shilu366312e2019-12-17 09:28:10 -08003259 /**
3260 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3261 * @param subId The subscription to use to check the configuration.
3262 * @param c The callback that will be used to send the result.
3263 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003264 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003265 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3266 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003267 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3268 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003269
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003270 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3271 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3272 "IMS not available on device.");
3273 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 final long token = Binder.clearCallingIdentity();
3275 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003279 } catch (ImsException e) {
3280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 } finally {
3282 Binder.restoreCallingIdentity(token);
3283 }
3284 }
3285
shilu366312e2019-12-17 09:28:10 -08003286 /**
3287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3288 * @param subId The subscription to use to check the configuration.
3289 * @param c The callback that will be used to send the result.
3290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003292 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003293 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3294 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3296 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3297 }
Meng Wangafbc5852019-09-19 17:37:13 -07003298 final long token = Binder.clearCallingIdentity();
3299 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003300 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003301 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3302 .removeRegistrationCallbackForSubscription(c, subId);
3303 } catch (ImsException e) {
3304 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3305 + "is inactive, ignoring unregister.");
3306 // If the subscription is no longer active, just return, since the callback
3307 // will already have been removed internally.
3308 } finally {
3309 Binder.restoreCallingIdentity(token);
3310 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 }
3312
Brad Ebingera34a6c22019-10-22 17:36:18 -07003313 /**
3314 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3315 */
3316 @Override
3317 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3318 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3321 "IMS not available on device.");
3322 }
3323 final long token = Binder.clearCallingIdentity();
3324 try {
3325 Phone phone = getPhone(subId);
3326 if (phone == null) {
3327 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3328 + subId + "'");
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3330 }
3331 phone.getImsRegistrationState(regState -> {
3332 try {
3333 consumer.accept((regState == null)
3334 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3335 } catch (RemoteException e) {
3336 // Ignore if the remote process is no longer available to call back.
3337 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3338 }
3339 });
3340 } finally {
3341 Binder.restoreCallingIdentity(token);
3342 }
3343 }
3344
3345 /**
3346 * Get the transport type for the IMS service registration state.
3347 */
3348 @Override
3349 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003350 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3351 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003352 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3353 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3354 "IMS not available on device.");
3355 }
3356 final long token = Binder.clearCallingIdentity();
3357 try {
3358 Phone phone = getPhone(subId);
3359 if (phone == null) {
3360 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3361 + subId + "'");
3362 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3363 }
3364 phone.getImsRegistrationTech(regTech -> {
3365 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3366 int regTechConverted = (regTech == null)
3367 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3368 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3369 regTechConverted);
3370 try {
3371 consumer.accept(regTechConverted);
3372 } catch (RemoteException e) {
3373 // Ignore if the remote process is no longer available to call back.
3374 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3375 }
3376 });
3377 } finally {
3378 Binder.restoreCallingIdentity(token);
3379 }
3380 }
3381
shilu366312e2019-12-17 09:28:10 -08003382 /**
3383 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3384 * @param subId The subscription to use to check the configuration.
3385 * @param c The callback that will be used to send the result.
3386 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003388 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3389 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003390 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3391 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003392 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3393 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3394 "IMS not available on device.");
3395 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3397 final long token = Binder.clearCallingIdentity();
3398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003401 } catch (ImsException e) {
3402 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 } finally {
3404 Binder.restoreCallingIdentity(token);
3405 }
3406 }
3407
shilu366312e2019-12-17 09:28:10 -08003408 /**
3409 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3410 * @param subId The subscription to use to check the configuration.
3411 * @param c The callback that will be used to send the result.
3412 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003414 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003415 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3416 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3418 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3419 }
Meng Wangafbc5852019-09-19 17:37:13 -07003420
3421 final long token = Binder.clearCallingIdentity();
3422 try {
Meng Wang8ea57e32020-06-25 11:03:56 -07003423 // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly.
Meng Wangafbc5852019-09-19 17:37:13 -07003424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003426 } catch (ImsException e) {
3427 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3428 + "is inactive, ignoring unregister.");
3429 // If the subscription is no longer active, just return, since the callback
3430 // will already have been removed internally.
3431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 }
3435
3436 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003437 public boolean isCapable(int subId, int capability, int regTech) {
3438 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3440 final long token = Binder.clearCallingIdentity();
3441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3446 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003447 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003448 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3449 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 } finally {
3451 Binder.restoreCallingIdentity(token);
3452 }
3453 }
3454
3455 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003456 public boolean isAvailable(int subId, int capability, int regTech) {
3457 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 final long token = Binder.clearCallingIdentity();
3459 try {
3460 Phone phone = getPhone(subId);
3461 if (phone == null) return false;
3462 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003463 } catch (com.android.ims.ImsException e) {
3464 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3465 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003466 } finally {
3467 Binder.restoreCallingIdentity(token);
3468 }
3469 }
3470
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003471 /**
3472 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3473 * subscription.
3474 * @param subId The subscription to use to check the configuration.
3475 * @param callback The callback that will be used to send the result.
3476 * @param capability The MmTelFeature capability that will be used to send the result.
3477 * @param transportType The transport type of the MmTelFeature capability.
3478 */
3479 @Override
3480 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3481 int transportType) {
3482 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3483 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3484 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3485 "IMS not available on device.");
3486 }
3487 final long token = Binder.clearCallingIdentity();
3488 try {
3489 int slotId = getSlotIndex(subId);
3490 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3491 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3492 + subId + "'");
3493 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3494 }
3495 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3496 transportType, aBoolean -> {
3497 try {
3498 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3499 } catch (RemoteException e) {
3500 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3501 + "running. Ignore");
3502 }
3503 });
3504 } finally {
3505 Binder.restoreCallingIdentity(token);
3506 }
3507 }
3508
shilu366312e2019-12-17 09:28:10 -08003509 /**
3510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3511 * @param subId The subscription to use to check the configuration.
3512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 @Override
3514 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003515 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3516 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003517
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3519 final long token = Binder.clearCallingIdentity();
3520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003523 } catch (ImsException e) {
3524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 } finally {
3526 Binder.restoreCallingIdentity(token);
3527 }
3528 }
3529
3530 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003531 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003533 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003539 } catch (ImsException e) {
3540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
3545
shilu366312e2019-12-17 09:28:10 -08003546 /**
3547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3548 * @param subId The subscription to use to check the configuration.
3549 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003551 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003552 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3553 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003566 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003568 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
shilu366312e2019-12-17 09:28:10 -08003580 /**
3581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3582 * @param subId The subscription to use to check the configuration.
3583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 @Override
3585 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003586 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3587 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
3600 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003601 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003603 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (ImsException e) {
3609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
3613 }
3614
shilu366312e2019-12-17 09:28:10 -08003615 /**
3616 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3617 * @param subId The subscription to use to check the configuration.
3618 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 @Override
3620 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003621 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3622 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
3629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634
3635 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003636 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003638 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003644 } catch (ImsException e) {
3645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
3649 }
3650
3651 @Override
3652 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3654 "setVoWiFiNonPersistent");
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003659 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003660 } catch (ImsException e) {
3661 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
3665 }
3666
shilu366312e2019-12-17 09:28:10 -08003667 /**
3668 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3669 * @param subId The subscription to use to check the configuration.
3670 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 @Override
3672 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003673 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3674 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003680 } catch (ImsException e) {
3681 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
3685 }
3686
3687 @Override
3688 public void setVoWiFiModeSetting(int subId, int mode) {
3689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3690 "setVoWiFiModeSetting");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003694 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003696 } catch (ImsException e) {
3697 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
3703 @Override
3704 public int getVoWiFiRoamingModeSetting(int subId) {
3705 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003711 } catch (ImsException e) {
3712 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
3716 }
3717
3718 @Override
3719 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3721 "setVoWiFiRoamingModeSetting");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 } catch (ImsException e) {
3728 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
3732 }
3733
3734 @Override
3735 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3737 "setRttCapabilityEnabled");
3738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
shilu366312e2019-12-17 09:28:10 -08003749 /**
3750 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3751 * @param subId The subscription to use to check the configuration.
3752 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 @Override
3754 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003755 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3756 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 }
3768
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003769 @Override
3770 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3771 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003774 if (!isImsAvailableOnDevice()) {
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3776 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003780 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003781 } catch (ImsException e) {
3782 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
3786 }
3787
3788 @Override
3789 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3790 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3791 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3793 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3794 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003795 try {
3796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003798 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003799 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003800 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3801 + "is inactive, ignoring unregister.");
3802 // If the subscription is no longer active, just return, since the callback will already
3803 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
allenwtsu99c623b2020-01-03 18:24:23 +08003809
3810 private void checkModifyPhoneStatePermission(int subId, String message) {
3811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3812 message);
3813 }
3814
3815 private boolean isImsProvisioningRequired(int subId, int capability,
3816 boolean isMmtelCapability) {
3817 Phone phone = getPhone(subId);
3818 if (phone == null) {
3819 loge("phone instance null for subid " + subId);
3820 return false;
3821 }
3822 if (isMmtelCapability) {
3823 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3824 return false;
3825 }
3826 } else {
3827 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3828 return false;
3829 }
3830 }
3831 return true;
3832 }
3833
3834 @Override
3835 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3836 boolean isProvisioned) {
3837 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3838
3839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3842 if (!isImsProvisioningRequired(subId, capability, false)) {
3843 return;
3844 }
3845
3846 // this capability requires provisioning, route to the correct API.
3847 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3848 switch (capability) {
3849 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3850 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3851 ims.setEabProvisioned(isProvisioned);
3852 break;
3853 default: {
3854 throw new IllegalArgumentException("Tried to set provisioning for "
3855 + "rcs capability '" + capability + "', which does not require "
3856 + "provisioning.");
3857 }
3858 }
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862
3863 }
3864
3865
3866 @Override
3867 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3868 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3872 if (!isImsProvisioningRequired(subId, capability, false)) {
3873 return true;
3874 }
3875
3876 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3877 switch (capability) {
3878 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3879 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3880 return ims.isEabProvisionedOnDevice();
3881
3882 default: {
3883 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3884 + "capability '" + capability + "', which does not require "
3885 + "provisioning.");
3886 }
3887 }
3888
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
3892 }
3893
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003894 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003895 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3896 boolean isProvisioned) {
3897 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3898 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3899 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3900 }
allenwtsu99c623b2020-01-03 18:24:23 +08003901 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003905 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003906 return;
3907 }
3908
3909 // this capability requires provisioning, route to the correct API.
3910 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3913 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3914 ims.setVolteProvisioned(isProvisioned);
3915 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3916 ims.setWfcProvisioned(isProvisioned);
3917 }
3918 break;
3919 }
3920 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3921 // There is currently no difference in VT provisioning type.
3922 ims.setVtProvisioned(isProvisioned);
3923 break;
3924 }
3925 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3926 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3927 // change the capability of the feature instead if needed.
3928 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3929 == isProvisioned) {
3930 // No change in provisioning.
3931 return;
3932 }
3933 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3934 try {
3935 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003936 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3938 + ", Exception" + e.getMessage());
3939 }
3940 break;
3941 }
3942 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003943 throw new IllegalArgumentException("Tried to set provisioning for "
3944 + "MmTel capability '" + capability + "', which does not require "
3945 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003946 }
3947 }
3948
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 }
3953
3954 @Override
3955 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3956 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3957 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3958 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3959 }
3960 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003964 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003965 return true;
3966 }
3967
3968 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3969 switch (capability) {
3970 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3971 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 return ims.isVolteProvisionedOnDevice();
3973 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3974 return ims.isWfcProvisionedOnDevice();
3975 }
3976 // This should never happen, since we are checking tech above to make sure it
3977 // is either LTE or IWLAN.
3978 throw new IllegalArgumentException("Invalid radio technology for voice "
3979 + "capability.");
3980 }
3981 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3982 // There is currently no difference in VT provisioning type.
3983 return ims.isVtProvisionedOnDevice();
3984 }
3985 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3986 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3987 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3988 }
3989 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003990 throw new IllegalArgumentException(
3991 "Tried to get provisioning for MmTel capability '" + capability
3992 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003993 }
3994 }
3995
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
4001 @Override
4002 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4003 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4004 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4005 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4006 }
4007 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4008 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4009 return (provisionedBits & capability) > 0;
4010 }
4011
4012 @Override
4013 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4014 boolean isProvisioned) {
4015 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4016 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4017 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4018 }
4019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4020 "setProvisioningStatusForCapability");
4021 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4022 // If the current provisioning status for capability already matches isProvisioned,
4023 // do nothing.
4024 if (((provisionedBits & capability) > 0) == isProvisioned) {
4025 return;
4026 }
4027 if (isProvisioned) {
4028 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4029 } else {
4030 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4031 }
4032 }
4033
4034 /**
4035 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4036 * technology. The bitfield should mirror the bitfield defined by
4037 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4038 */
4039 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4040 String key = getMmTelProvisioningKey(subId, tech);
4041 // Default is no capabilities are provisioned.
4042 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4043 }
4044
4045 /**
4046 * Sets the MmTel capability provisioning bitfield (defined by
4047 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4048 * technology specified.
4049 *
4050 * Note: This is a synchronous command and should not be called on UI thread.
4051 */
4052 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4053 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4054 String key = getMmTelProvisioningKey(subId, tech);
4055 editor.putInt(key, newField);
4056 editor.commit();
4057 }
4058
4059 private static String getMmTelProvisioningKey(int subId, int tech) {
4060 // resulting key is provision_ims_mmtel_{subId}_{tech}
4061 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4062 }
4063
4064 /**
4065 * Query CarrierConfig to see if the specified capability requires provisioning for the
4066 * carrier associated with the subscription id.
4067 */
4068 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4069 int capability) {
4070 CarrierConfigManager configManager = new CarrierConfigManager(context);
4071 PersistableBundle c = configManager.getConfigForSubId(subId);
4072 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004073 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004074 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4075 false);
4076 boolean requireVoiceVtProvisioning = c.getBoolean(
4077 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4078
4079 // First check to make sure that the capability requires provisioning.
4080 switch (capability) {
4081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4082 // intentional fallthrough
4083 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4084 if (requireVoiceVtProvisioning) {
4085 // Voice and Video requires provisioning
4086 return true;
4087 }
4088 break;
4089 }
4090 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4091 if (requireUtProvisioning) {
4092 // UT requires provisioning
4093 return true;
4094 }
4095 break;
4096 }
4097 }
4098 return false;
4099 }
4100
allenwtsu99c623b2020-01-03 18:24:23 +08004101 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4102 int capability) {
4103 CarrierConfigManager configManager = new CarrierConfigManager(context);
4104 PersistableBundle c = configManager.getConfigForSubId(subId);
4105
4106 boolean requireRcsProvisioning = c.getBoolean(
4107 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4108
4109 // First check to make sure that the capability requires provisioning.
4110 switch (capability) {
4111 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4112 // intentional fallthrough
4113 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4114 if (requireRcsProvisioning) {
4115 // OPTION or PRESENCE requires provisioning
4116 return true;
4117 }
4118 break;
4119 }
4120 }
4121 return false;
4122 }
4123
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4127 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4128 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004129 enforceReadPrivilegedPermission("getImsProvisioningInt");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004133 int slotId = getSlotIndex(subId);
4134 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4135 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4136 + subId + "' for key:" + key);
4137 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4138 }
4139 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004141 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4142 + subId + "' for key:" + key);
4143 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4152 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4153 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004154 enforceReadPrivilegedPermission("getImsProvisioningString");
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004158 int slotId = getSlotIndex(subId);
4159 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4160 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4161 + subId + "' for key:" + key);
4162 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4163 }
4164 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004166 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4167 + subId + "' for key:" + key);
4168 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4177 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4178 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4180 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 int slotId = getSlotIndex(subId);
4185 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4186 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4187 + subId + "' for key:" + key);
4188 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4189 }
4190 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004191 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004192 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4193 + "' for key:" + key);
4194 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
4198 }
4199
4200 @Override
4201 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004202 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4203 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4204 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4206 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004210 int slotId = getSlotIndex(subId);
4211 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4212 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4213 + subId + "' for key:" + key);
4214 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4215 }
4216 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4219 + "' for key:" + key);
4220 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224 }
4225
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 int slotId = SubscriptionManager.getSlotIndex(subId);
4228 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4230 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 }
4232 return slotId;
4233 }
4234
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004235 private int getSlotIndex(int subId) {
4236 int slotId = SubscriptionManager.getSlotIndex(subId);
4237 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4238 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4239 }
4240 return slotId;
4241 }
4242
Wink Saville36469e72014-06-11 15:17:00 -07004243 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004244 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004245 */
4246 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004247 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4248 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004249 final int targetSdk = getTargetSdk(callingPackage);
4250 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004251 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004252 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004253 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004254 mApp, subId, callingPackage, callingFeatureId,
4255 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4257 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 final long identity = Binder.clearCallingIdentity();
4260 try {
4261 final Phone phone = getPhone(subId);
4262 if (phone != null) {
4263 return phone.getServiceState().getDataNetworkType();
4264 } else {
4265 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4266 }
4267 } finally {
4268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004270 }
4271
4272 /**
4273 * Returns the data network type
4274 */
4275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4277 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4278 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004279 }
4280
4281 /**
4282 * Returns the data network type for a subId
4283 */
4284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004285 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4286 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004288 mApp, subId, callingPackage, callingFeatureId,
4289 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004290 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4291 }
4292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 final Phone phone = getPhone(subId);
4296 if (phone != null) {
4297 return phone.getServiceState().getDataNetworkType();
4298 } else {
4299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4300 }
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004304 }
4305
4306 /**
Wink Saville36469e72014-06-11 15:17:00 -07004307 * Returns the Voice network type for a subId
4308 */
4309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004310 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4311 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004313 mApp, subId, callingPackage, callingFeatureId,
4314 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004315 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4316 }
4317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 final Phone phone = getPhone(subId);
4321 if (phone != null) {
4322 return phone.getServiceState().getVoiceNetworkType();
4323 } else {
4324 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4325 }
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004329 }
4330
4331 /**
4332 * @return true if a ICC card is present
4333 */
4334 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004335 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004336 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4337 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004338 }
4339
4340 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004341 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004343 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004344 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 final Phone phone = PhoneFactory.getPhone(slotIndex);
4348 if (phone != null) {
4349 return phone.getIccCard().hasIccCard();
4350 } else {
4351 return false;
4352 }
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004356 }
4357
4358 /**
4359 * Return if the current radio is LTE on CDMA. This
4360 * is a tri-state return value as for a period of time
4361 * the mode may be unknown.
4362 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004363 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004364 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004365 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4369 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4370 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004371 }
4372
Sanket Padawe356d7632015-06-22 14:03:32 -07004373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004374 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4375 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004376 try {
4377 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4378 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004379 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4380 }
4381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 final Phone phone = getPhone(subId);
4385 if (phone == null) {
4386 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4387 } else {
4388 return phone.getLteOnCdmaMode();
4389 }
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004392 }
Wink Saville36469e72014-06-11 15:17:00 -07004393 }
4394
Wink Saville36469e72014-06-11 15:17:00 -07004395 /**
4396 * {@hide}
4397 * Returns Default subId, 0 in the case of single standby.
4398 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004399 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004400 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004401 }
4402
Shishir Agrawala9f32182016-04-12 12:00:16 -07004403 private int getSlotForDefaultSubscription() {
4404 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4405 }
4406
Wink Savilleb564aae2014-10-23 10:18:09 -07004407 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004408 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004409 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004410
Pengquan Menge92a50d2018-09-21 15:54:48 -07004411 private boolean isActiveSubscription(int subId) {
4412 return mSubscriptionController.isActiveSubId(subId);
4413 }
4414
Ihab Awadf2177b72013-11-25 13:33:23 -08004415 /**
4416 * @see android.telephony.TelephonyManager.WifiCallingChoices
4417 */
4418 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004421 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4423 getWhenToMakeWifiCallsDefaultPreference());
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004427 }
4428
4429 /**
4430 * @see android.telephony.TelephonyManager.WifiCallingChoices
4431 */
4432 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004441 }
4442
Sailesh Nepald1e68152013-12-12 19:08:02 -08004443 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004444 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004445 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004446 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004447
Jordan Liu4c733742019-02-28 12:03:40 -08004448 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4449 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4450 if (phoneId == -1) {
4451 throw new IllegalArgumentException("Given slot index: " + slotIndex
4452 + " does not correspond to an active phone");
4453 }
4454 return PhoneFactory.getPhone(phoneId);
4455 }
4456
Shishir Agrawal566b7612013-10-28 14:41:00 -07004457 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004458 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4459 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4461 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004463 if (DBG) {
4464 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4465 }
4466 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4467 p2);
4468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004469
Jordan Liu4c733742019-02-28 12:03:40 -08004470
4471 @Override
4472 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4473 int slotIndex, String callingPackage, String aid, int p2) {
4474 enforceModifyPermission();
4475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4476 if (DBG) {
4477 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4478 }
4479 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4480 callingPackage, aid, p2);
4481 }
4482
4483 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4484 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 if (TextUtils.equals(ISDR_AID, aid)) {
4488 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004489 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4490 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 if (bestComponent == null
4492 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4493 loge("The calling package is not allowed to access ISD-R.");
4494 throw new SecurityException(
4495 "The calling package is not allowed to access ISD-R.");
4496 }
Derek Tan740e1672017-06-27 14:56:27 -07004497 }
Derek Tan740e1672017-06-27 14:56:27 -07004498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004500 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4501 null /* workSource */);
4502 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 return response;
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004507 }
4508
4509 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004510 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004513 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4514 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004516
Jordan Liu4c733742019-02-28 12:03:40 -08004517 @Override
4518 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4519 enforceModifyPermission();
4520 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4521 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4522 channel);
4523 }
4524
4525 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 if (channel < 0) {
4529 return false;
4530 }
Jordan Liu4c733742019-02-28 12:03:40 -08004531 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4532 null /* workSource */);
4533 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 return success;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004538 }
4539
4540 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004541 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004542 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4544 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004545 if (DBG) {
4546 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4547 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4548 + p3 + " data=" + data);
4549 }
4550 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4551 command, p1, p2, p3, data);
4552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004553
Jordan Liu4c733742019-02-28 12:03:40 -08004554 @Override
4555 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4556 int command, int p1, int p2, int p3, String data) {
4557 enforceModifyPermission();
4558 if (DBG) {
4559 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4560 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4561 + p3 + " data=" + data);
4562 }
4563 return iccTransmitApduLogicalChannelWithPermission(
4564 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4565 data);
4566 }
4567
4568 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4569 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004572 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 return "";
4574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004577 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4578 null /* workSource */);
4579 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 // Append the returned status code to the end of the response payload.
4582 String s = Integer.toHexString(
4583 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4584 if (response.payload != null) {
4585 s = IccUtils.bytesToHexString(response.payload) + s;
4586 }
4587 return s;
4588 } finally {
4589 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004591 }
Jake Hambye994d462014-02-03 13:10:13 -08004592
Evan Charltonc66da362014-05-16 14:06:40 -07004593 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004594 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4595 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004599 if (DBG) {
4600 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4601 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4602 }
4603 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4604 cla, command, p1, p2, p3, data);
4605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004606
Jordan Liu4c733742019-02-28 12:03:40 -08004607 @Override
4608 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4609 int command, int p1, int p2, int p3, String data) {
4610 enforceModifyPermission();
4611 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4612 if (DBG) {
4613 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4614 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4615 + " data=" + data);
4616 }
4617
4618 return iccTransmitApduBasicChannelWithPermission(
4619 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4620 p2, p3, data);
4621 }
4622
4623 // open APDU basic channel assuming the caller has sufficient permissions
4624 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4625 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4629 && TextUtils.equals(ISDR_AID, data)) {
4630 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004631 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4632 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 if (bestComponent == null
4634 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4635 loge("The calling package is not allowed to select ISD-R.");
4636 throw new SecurityException(
4637 "The calling package is not allowed to select ISD-R.");
4638 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004639 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004642 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4643 null /* workSource */);
4644 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 // Append the returned status code to the end of the response payload.
4647 String s = Integer.toHexString(
4648 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4649 if (response.payload != null) {
4650 s = IccUtils.bytesToHexString(response.payload) + s;
4651 }
4652 return s;
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004656 }
4657
4658 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004659 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4662 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 if (DBG) {
4667 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4668 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4669 }
4670
4671 IccIoResult response =
4672 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4673 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4674 subId);
4675
4676 if (DBG) {
4677 log("Exchange SIM_IO [R]" + response);
4678 }
4679
4680 byte[] result = null;
4681 int length = 2;
4682 if (response.payload != null) {
4683 length = 2 + response.payload.length;
4684 result = new byte[length];
4685 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4686 } else {
4687 result = new byte[length];
4688 }
4689
4690 result[length - 1] = (byte) response.sw2;
4691 result[length - 2] = (byte) response.sw1;
4692 return result;
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004695 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004696 }
4697
Nathan Haroldb3014052017-01-25 15:57:32 -08004698 /**
4699 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4700 * on a particular subscription
4701 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004702 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4703 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004705 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004706 return null;
4707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 if (appType != TelephonyManager.APPTYPE_USIM
4712 && appType != TelephonyManager.APPTYPE_SIM) {
4713 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4714 return null;
4715 }
4716 Object response = sendRequest(
4717 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4718 if (response instanceof String[]) {
4719 return (String[]) response;
4720 }
yincheng zhao2737e882019-09-06 17:06:54 -07004721 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004723 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004726 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004727 }
4728
yincheng zhao2737e882019-09-06 17:06:54 -07004729 /**
4730 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4731 * subscription.
4732 *
4733 * @param subId the id of the subscription.
4734 * @param appType the uicc app type, must be USIM or SIM.
4735 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4736 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004737 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004738 * @return number of fplmns that is successfully written to the SIM.
4739 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004740 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4741 String callingFeatureId) {
4742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4743 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004744 if (DBG) logv("no permissions for setForbiddenplmns");
4745 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4746 }
4747 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4748 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4749 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4750 }
4751 if (fplmns == null) {
4752 throw new IllegalArgumentException("Fplmn List provided is null");
4753 }
4754 for (String fplmn : fplmns) {
4755 if (!CellIdentity.isValidPlmn(fplmn)) {
4756 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4757 }
4758 }
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 Object response = sendRequest(
4762 CMD_SET_FORBIDDEN_PLMNS,
4763 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4764 subId);
4765 return (int) response;
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004771 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004772 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4779 if (response.payload == null) {
4780 return "";
4781 }
Evan Charltonc66da362014-05-16 14:06:40 -07004782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 // Append the returned status code to the end of the response payload.
4784 String s = Integer.toHexString(
4785 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4786 s = IccUtils.bytesToHexString(response.payload) + s;
4787 return s;
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Evan Charltonc66da362014-05-16 14:06:40 -07004791 }
4792
Jake Hambye994d462014-02-03 13:10:13 -08004793 /**
4794 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4795 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4796 *
4797 * @param itemID the ID of the item to read
4798 * @return the NV item as a String, or null on error.
4799 */
4800 @Override
4801 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4804 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004809 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4811 return value;
4812 } finally {
4813 Binder.restoreCallingIdentity(identity);
4814 }
Jake Hambye994d462014-02-03 13:10:13 -08004815 }
4816
4817 /**
4818 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4819 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4820 *
4821 * @param itemID the ID of the item to read
4822 * @param itemValue the value to write, as a String
4823 * @return true on success; false on any failure
4824 */
4825 @Override
4826 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4829 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830
4831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4834 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004835 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4837 return success;
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Jake Hambye994d462014-02-03 13:10:13 -08004841 }
4842
4843 /**
4844 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4845 * Used for device configuration by some CDMA operators.
4846 *
4847 * @param preferredRoamingList byte array containing the new PRL
4848 * @return true on success; false on any failure
4849 */
4850 @Override
4851 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4853 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4858 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4859 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4860 return success;
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Jake Hambye994d462014-02-03 13:10:13 -08004864 }
4865
4866 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004867 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004868 * Used for device configuration by some CDMA operators.
4869 *
chen xu6dac5ab2018-10-26 17:39:23 -07004870 * @param slotIndex - device slot.
4871 *
Jake Hambye994d462014-02-03 13:10:13 -08004872 * @return true on success; false on any failure
4873 */
4874 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004875 public boolean resetModemConfig(int slotIndex) {
4876 Phone phone = PhoneFactory.getPhone(slotIndex);
4877 if (phone != null) {
4878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4879 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880
chen xu6dac5ab2018-10-26 17:39:23 -07004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4884 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4885 return success;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 }
chen xu6dac5ab2018-10-26 17:39:23 -07004890 return false;
4891 }
4892
4893 /**
4894 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4895 *
4896 * @param slotIndex - device slot.
4897 *
4898 * @return true on success; false on any failure
4899 */
4900 @Override
4901 public boolean rebootModem(int slotIndex) {
4902 Phone phone = PhoneFactory.getPhone(slotIndex);
4903 if (phone != null) {
4904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, phone.getSubId(), "rebootModem");
4906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4910 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4911 return success;
4912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
4915 }
4916 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004917 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004918
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 public String[] getPcscfAddress(String apnType, String callingPackage,
4920 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004921 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4923 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004924 return new String[0];
4925 }
4926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
Wink Saville36469e72014-06-11 15:17:00 -07004933 }
4934
Brad Ebinger51f743a2017-01-23 13:50:20 -08004935 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004936 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4937 * {@link #disableIms(int)}.
4938 * @param slotIndex device slot.
4939 */
4940 public void resetIms(int slotIndex) {
4941 enforceModifyPermission();
4942
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 if (mImsResolver == null) {
4946 // may happen if the does not support IMS.
4947 return;
4948 }
4949 mImsResolver.disableIms(slotIndex);
4950 mImsResolver.enableIms(slotIndex);
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4958 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004959 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004965 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004966 // may happen if the device does not support IMS.
4967 return;
4968 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004969 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004973 }
4974
4975 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004976 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4977 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004978 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004979 public void disableIms(int slotId) {
4980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981
4982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004984 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004985 // may happen if the device does not support IMS.
4986 return;
4987 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004992 }
4993
4994 /**
4995 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4996 * feature or {@link null} if the service is not available. If the feature is available, the
4997 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4998 */
4999 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005000 IImsServiceFeatureCallback callback) {
5001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002
5003 final long identity = Binder.clearCallingIdentity();
5004 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005005 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005006 // may happen if the device does not support IMS.
5007 return null;
5008 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005009 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005013 }
5014
5015 /**
5016 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5017 * feature during emergency calling or {@link null} if the service is not available. If the
5018 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5019 * listener for feature updates.
5020 */
5021 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005026 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 // may happen if the device does not support IMS.
5028 return null;
5029 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005030 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005034 }
5035
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005037 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5038 */
5039 public void unregisterImsFeatureCallback(int slotId, int featureType,
5040 IImsServiceFeatureCallback callback) {
5041 enforceModifyPermission();
5042
5043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 if (mImsResolver == null) return;
5046 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
5050 }
5051
5052 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005053 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005054 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005055 */
5056 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 // may happen if the device does not support IMS.
5063 return null;
5064 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005065 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005069 }
5070
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005071 /**
5072 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005073 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005074 */
5075 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005081 // may happen if the device does not support IMS.
5082 return null;
5083 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005088 }
5089
Brad Ebinger884c07b2018-02-15 16:17:40 -08005090 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 * Sets the ImsService Package Name that Telephony will bind to.
5092 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005093 * @param slotIndex the slot ID that the ImsService should bind for.
5094 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005095 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005096 * @param featureTypes An integer array of feature types associated with a packageName.
5097 * @param packageName The name of the package that the current configuration will be replaced
5098 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005099 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005100 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005101 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5102 int[] featureTypes, String packageName) {
5103 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5106 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005107 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005111 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005112 // may happen if the device does not support IMS.
5113 return false;
5114 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005115 Map<Integer, String> featureConfig = new HashMap<>();
5116 for (int featureType : featureTypes) {
5117 featureConfig.put(featureType, packageName);
5118 }
5119 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5120 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005124 }
5125
5126 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005127 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005128 *
5129 * @param slotId The slot that the ImsService is associated with.
5130 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5131 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005132 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005133 * @return the package name of the ImsService configuration.
5134 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005135 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5136 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005137 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005138 TelephonyPermissions
5139 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5140 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5141 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005145 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005146 // may happen if the device does not support IMS.
5147 return "";
5148 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005149 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005150 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5151 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005155 }
5156
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005157 /**
5158 * Get the MmTelFeature state associated with the requested subscription id.
5159 * @param subId The subscription that the MmTelFeature is associated with.
5160 * @param callback A callback with an integer containing the
5161 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5162 */
5163 @Override
5164 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5165 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5166 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5167 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5168 "IMS not available on device.");
5169 }
5170 final long token = Binder.clearCallingIdentity();
5171 try {
5172 int slotId = getSlotIndex(subId);
5173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5174 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5175 + subId + "'");
5176 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5177 }
5178 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5179 try {
5180 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5181 } catch (RemoteException e) {
5182 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5183 + "Ignore");
5184 }
5185 });
5186 } finally {
5187 Binder.restoreCallingIdentity(token);
5188 }
5189 }
5190
Wink Saville36469e72014-06-11 15:17:00 -07005191 public void setImsRegistrationState(boolean registered) {
5192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Wink Saville36469e72014-06-11 15:17:00 -07005200 }
5201
5202 /**
Stuart Scott54788802015-03-30 13:18:01 -07005203 * Set the network selection mode to automatic.
5204 *
5205 */
5206 @Override
5207 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
shilufc958392020-01-20 11:36:01 -08005213 if (!isActiveSubscription(subId)) {
5214 return;
5215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5217 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Stuart Scott54788802015-03-30 13:18:01 -07005221 }
5222
Pengquan Mengea84e042018-09-20 14:57:26 -07005223 /**
5224 * Ask the radio to connect to the input network and change selection mode to manual.
5225 *
5226 * @param subId the id of the subscription.
5227 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5228 * the operator to attach to.
5229 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5230 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5231 * normal network selection next time.
5232 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005233 */
5234 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005235 public boolean setNetworkSelectionModeManual(
5236 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5238 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005239
5240 if (!isActiveSubscription(subId)) {
5241 return false;
5242 }
5243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005246 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005248 if (DBG) {
5249 log("setNetworkSelectionModeManual: subId: " + subId
5250 + " operator: " + operatorInfo);
5251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005256 }
shilu84f6e8b2019-12-19 13:58:01 -08005257 /**
5258 * Get the manual network selection
5259 *
5260 * @param subId the id of the subscription.
5261 *
5262 * @return the previously saved user selected PLMN
5263 */
5264 @Override
5265 public String getManualNetworkSelectionPlmn(int subId) {
5266 TelephonyPermissions
5267 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5268 mApp, subId, "getManualNetworkSelectionPlmn");
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005273 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005274 }
5275
5276 final Phone phone = getPhone(subId);
5277 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005278 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005279 }
5280 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5281 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5282 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005287
5288 /**
5289 * Scans for available networks.
5290 */
5291 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005292 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5293 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005296 LocationAccessPolicy.LocationPermissionResult locationResult =
5297 LocationAccessPolicy.checkLocationPermission(mApp,
5298 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5299 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005300 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005301 .setCallingPid(Binder.getCallingPid())
5302 .setCallingUid(Binder.getCallingUid())
5303 .setMethod("getCellNetworkScanResults")
5304 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005305 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5306 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005307 .build());
5308 switch (locationResult) {
5309 case DENIED_HARD:
5310 throw new SecurityException("Not allowed to access scan results -- location");
5311 case DENIED_SOFT:
5312 return null;
5313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314
Pengquan Menga1bb6272018-09-06 09:59:22 -07005315 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 try {
5317 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005318 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005323 }
5324
5325 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005326 * Get the call forwarding info, given the call forwarding reason.
5327 */
5328 @Override
5329 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5330 enforceReadPrivilegedPermission("getCallForwarding");
5331 long identity = Binder.clearCallingIdentity();
5332 try {
5333 if (DBG) {
5334 log("getCallForwarding: subId " + subId
5335 + " callForwardingReason" + callForwardingReason);
5336 }
5337 return (CallForwardingInfo) sendRequest(
5338 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
5345 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5346 * reason, the number to forward, and the timeout before the forwarding is attempted.
5347 */
5348 @Override
5349 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5350 enforceModifyPermission();
5351 long identity = Binder.clearCallingIdentity();
5352 try {
5353 if (DBG) {
5354 log("setCallForwarding: subId " + subId
5355 + " callForwardingInfo" + callForwardingInfo);
5356 }
5357 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
5361 }
5362
5363 /**
5364 * Get the call forwarding info, given the call forwarding reason.
5365 */
5366 @Override
5367 public int getCallWaitingStatus(int subId) {
5368 enforceReadPrivilegedPermission("getCallForwarding");
5369 long identity = Binder.clearCallingIdentity();
5370 try {
5371 if (DBG) log("getCallWaitingStatus: subId " + subId);
5372 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
5376 }
5377
5378 /**
5379 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5380 * reason, the number to forward, and the timeout before the forwarding is attempted.
5381 */
5382 @Override
5383 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5384 enforceModifyPermission();
5385 long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5388 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
5392 }
5393
5394 /**
yinxub1bed742017-04-17 11:45:04 -07005395 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005396 *
yinxub1bed742017-04-17 11:45:04 -07005397 * @param subId id of the subscription
5398 * @param request contains the radio access networks with bands/channels to scan
5399 * @param messenger callback messenger for scan results or errors
5400 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005401 * @return the id of the requested scan which can be used to stop the scan.
5402 */
5403 @Override
5404 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005405 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5407 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005408 LocationAccessPolicy.LocationPermissionResult locationResult =
5409 LocationAccessPolicy.checkLocationPermission(mApp,
5410 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5411 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005412 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005413 .setCallingPid(Binder.getCallingPid())
5414 .setCallingUid(Binder.getCallingUid())
5415 .setMethod("requestNetworkScan")
5416 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
James.cf Lin1d4d7392020-07-03 18:22:53 +08005417 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5418 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005419 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005421 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005422 if (e != null) {
5423 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5424 throw e;
5425 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005426 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005427 return TelephonyScanManager.INVALID_SCAN_ID;
5428 }
5429 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005430 }
Hall Liu912dfd32019-04-25 14:02:26 -07005431 int callingUid = Binder.getCallingUid();
5432 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005433 final long identity = Binder.clearCallingIdentity();
5434 try {
5435 return mNetworkScanRequestTracker.startNetworkScan(
5436 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005437 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005438 } finally {
5439 Binder.restoreCallingIdentity(identity);
5440 }
yinxu504e1392017-04-12 16:03:22 -07005441 }
5442
Hall Liub2ac8ef2019-02-28 15:56:23 -08005443 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005444 NetworkScanRequest request, int subId) {
5445 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5446 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5447 boolean hasNetworkScanPermission =
5448 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5449 == PERMISSION_GRANTED;
5450
5451 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5452 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5453 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005454 }
5455
5456 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5457 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005458 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5459 return new SecurityException("Specific channels must not be"
5460 + " scanned without location access.");
5461 }
5462 }
5463 }
5464
Hall Liub2ac8ef2019-02-28 15:56:23 -08005465 return null;
5466 }
5467
yinxu504e1392017-04-12 16:03:22 -07005468 /**
5469 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005470 *
5471 * @param subId id of the subscription
5472 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005473 */
5474 @Override
5475 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005476 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5477 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478
Hall Liu912dfd32019-04-25 14:02:26 -07005479 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005480 final long identity = Binder.clearCallingIdentity();
5481 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005482 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005483 } finally {
5484 Binder.restoreCallingIdentity(identity);
5485 }
yinxu504e1392017-04-12 16:03:22 -07005486 }
5487
5488 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005489 * Get the calculated preferred network type.
5490 * Used for debugging incorrect network type.
5491 *
5492 * @return the preferred network type, defined in RILConstants.java.
5493 */
5494 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005495 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 final Phone defaultPhone = getDefaultPhone();
5497 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005498 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005499 return RILConstants.PREFERRED_NETWORK_MODE;
5500 }
5501
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005502 final long identity = Binder.clearCallingIdentity();
5503 try {
5504 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005505 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005506 } finally {
5507 Binder.restoreCallingIdentity(identity);
5508 }
Junda Liu84d15a22014-07-02 11:21:04 -07005509 }
5510
5511 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005512 * Get the preferred network type.
5513 * Used for device configuration by some CDMA operators.
5514 *
5515 * @return the preferred network type, defined in RILConstants.java.
5516 */
5517 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005518 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005519 TelephonyPermissions
5520 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5521 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005522
5523 final long identity = Binder.clearCallingIdentity();
5524 try {
5525 if (DBG) log("getPreferredNetworkType");
5526 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5527 int networkType = (result != null ? result[0] : -1);
5528 if (DBG) log("getPreferredNetworkType: " + networkType);
5529 return networkType;
5530 } finally {
5531 Binder.restoreCallingIdentity(identity);
5532 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005533 }
5534
5535 /**
5536 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005537 *
5538 * @param networkType the preferred network type, defined in RILConstants.java.
5539 * @return true on success; false on any failure.
5540 */
5541 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005542 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5544 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005545
5546 final long identity = Binder.clearCallingIdentity();
5547 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005548 Settings.Global.putInt(mApp.getContentResolver(),
5549 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005550
5551 Boolean success = (Boolean) sendRequest(
5552 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5553 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5554 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005555 } finally {
5556 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005557 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005558 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005559
5560 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005561 * Get the allowed network types that store in the telephony provider.
5562 *
5563 * @param subId the id of the subscription.
5564 * @return allowedNetworkTypes the allowed network types.
5565 */
5566 @Override
5567 public long getAllowedNetworkTypes(int subId) {
5568 TelephonyPermissions
5569 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5570 mApp, subId, "getAllowedNetworkTypes");
5571
5572 final long identity = Binder.clearCallingIdentity();
5573 try {
5574 return SubscriptionManager.getLongSubscriptionProperty(
5575 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5576 } finally {
5577 Binder.restoreCallingIdentity(identity);
5578 }
5579 }
5580
5581 /**
5582 * Set the allowed network types.
5583 *
5584 * @param subId the id of the subscription.
5585 * @param allowedNetworkTypes the allowed network types.
5586 * @return true on success; false on any failure.
5587 */
5588 @Override
5589 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5591 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005592
calvinpan8ed33732020-03-12 14:17:55 +08005593 SubscriptionManager.setSubscriptionProperty(subId,
5594 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5595 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005596
calvinpan8ed33732020-03-12 14:17:55 +08005597 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5598 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5599 RILConstants.PREFERRED_NETWORK_MODE);
5600 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005601 }
5602
5603 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005604 * Get the allowed network types for certain reason.
5605 *
5606 * @param subId the id of the subscription.
5607 * @param reason the reason the allowed network type change is taking place
5608 * @return the allowed network types.
5609 */
5610 @Override
5611 public long getAllowedNetworkTypesForReason(int subId,
5612 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5613 TelephonyPermissions
5614 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5615 mApp, subId, "getAllowedNetworkTypesForReason");
5616 final long identity = Binder.clearCallingIdentity();
5617 try {
5618 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5619 } finally {
5620 Binder.restoreCallingIdentity(identity);
5621 }
5622 }
5623
5624 /**
5625 * Get the effective allowed network types on the device.
5626 * This API will return an intersection of allowed network types for all reasons,
5627 * including the configuration done through setAllowedNetworkTypes
5628 *
5629 * @param subId the id of the subscription.
5630 * @return the allowed network types
5631 */
5632 @Override
5633 public long getEffectiveAllowedNetworkTypes(int subId) {
5634 TelephonyPermissions
5635 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5636 mApp, subId, "getEffectiveAllowedNetworkTypes");
5637 final long identity = Binder.clearCallingIdentity();
5638 try {
5639 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5640 } finally {
5641 Binder.restoreCallingIdentity(identity);
5642 }
5643 }
5644
5645 /**
5646 * Set the allowed network types of the device and
5647 * provide the reason triggering the allowed network change.
5648 *
5649 * @param subId the id of the subscription.
5650 * @param reason the reason the allowed network type change is taking place
5651 * @param allowedNetworkTypes the allowed network types.
5652 * @return true on success; false on any failure.
5653 */
5654 @Override
5655 public boolean setAllowedNetworkTypesForReason(int subId,
5656 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5657 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5658 mApp, subId, "setAllowedNetworkTypesForReason");
5659 final long identity = Binder.clearCallingIdentity();
5660 try {
5661 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5662 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5663 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5664 RILConstants.PREFERRED_NETWORK_MODE);
5665 return setPreferredNetworkType(subId, preferredNetworkMode);
5666 } finally {
5667 Binder.restoreCallingIdentity(identity);
5668 }
5669 }
5670
5671 /**
Miaoa84611c2019-03-15 09:21:10 +08005672 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005673 *
Miaoa84611c2019-03-15 09:21:10 +08005674 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005675 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005676 * @hide
5677 */
5678 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005679 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005680 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005682 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005683 try {
Miaoa84611c2019-03-15 09:21:10 +08005684 if (phone != null) {
5685 return phone.hasMatchedTetherApnSetting();
5686 } else {
5687 return false;
5688 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005689 } finally {
5690 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005691 }
Junda Liu475951f2014-11-07 16:45:03 -08005692 }
5693
5694 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005695 * Enable or disable always reporting signal strength changes from radio.
5696 *
5697 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5698 */
5699 @Override
5700 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5701 enforceModifyPermission();
5702 enforceSystemCaller();
5703
5704 final long identity = Binder.clearCallingIdentity();
5705 final Phone phone = getPhone(subId);
5706 try {
5707 if (phone != null) {
5708 if (DBG) {
5709 log("setAlwaysReportSignalStrength: subId=" + subId
5710 + " isEnable=" + isEnable);
5711 }
5712 phone.setAlwaysReportSignalStrength(isEnable);
5713 } else {
5714 loge("setAlwaysReportSignalStrength: no phone found for subId="
5715 + subId);
5716 }
5717 } finally {
5718 Binder.restoreCallingIdentity(identity);
5719 }
5720 }
5721
5722 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005723 * Get the user enabled state of Mobile Data.
5724 *
5725 * TODO: remove and use isUserDataEnabled.
5726 * This can't be removed now because some vendor codes
5727 * calls through ITelephony directly while they should
5728 * use TelephonyManager.
5729 *
5730 * @return true on enabled
5731 */
5732 @Override
5733 public boolean getDataEnabled(int subId) {
5734 return isUserDataEnabled(subId);
5735 }
5736
5737 /**
5738 * Get whether mobile data is enabled per user setting.
5739 *
5740 * There are other factors deciding whether mobile data is actually enabled, but they are
5741 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005742 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005743 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005744 *
5745 * @return {@code true} if data is enabled else {@code false}
5746 */
5747 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005748 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005749 try {
5750 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5751 null);
5752 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005753 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5754 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005755 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005756
5757 final long identity = Binder.clearCallingIdentity();
5758 try {
5759 int phoneId = mSubscriptionController.getPhoneId(subId);
5760 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5761 Phone phone = PhoneFactory.getPhone(phoneId);
5762 if (phone != null) {
5763 boolean retVal = phone.isUserDataEnabled();
5764 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5765 return retVal;
5766 } else {
5767 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5768 return false;
5769 }
5770 } finally {
5771 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005772 }
5773 }
5774
5775 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005776 * Checks if the device is capable of mobile data by considering whether whether the
5777 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5778 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005779 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005780 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005781 */
5782 @Override
5783 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005784 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005785
5786 final long identity = Binder.clearCallingIdentity();
5787 try {
5788 int phoneId = mSubscriptionController.getPhoneId(subId);
5789 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5790 Phone phone = PhoneFactory.getPhone(phoneId);
5791 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005792 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005793 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5794 return retVal;
5795 } else {
5796 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5797 return false;
5798 }
5799 } finally {
5800 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005801 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005802 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005803
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005804 /**
5805 * Check if data is enabled for a specific reason
5806 * @param subId Subscription index
5807 * @param reason the reason the data enable change is taking place
5808 * @return {@code true} if the overall data is enabled; {@code false} if not.
5809 */
5810 @Override
5811 public boolean isDataEnabledWithReason(int subId,
5812 @TelephonyManager.DataEnabledReason int reason) {
5813 try {
5814 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5815 null);
5816 } catch (Exception e) {
5817 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5818 "isDataEnabledWithReason");
5819 }
5820
5821
5822 final long identity = Binder.clearCallingIdentity();
5823 try {
5824 int phoneId = mSubscriptionController.getPhoneId(subId);
5825 if (DBG) {
5826 log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
5827 + " reason=" + reason);
5828 }
5829 Phone phone = PhoneFactory.getPhone(phoneId);
5830 if (phone != null) {
5831 boolean retVal;
5832 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5833 retVal = phone.isUserDataEnabled();
5834 } else {
5835 retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
5836 }
5837 if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
5838 return retVal;
5839 } else {
5840 if (DBG) {
5841 loge("isDataEnabledWithReason: no phone subId="
5842 + subId + " retVal=false");
5843 }
5844 return false;
5845 }
5846 } finally {
5847 Binder.restoreCallingIdentity(identity);
5848 }
5849 }
5850
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005851 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005852 Phone phone) {
5853 //load access rules from carrier configs, and check those as well: b/139133814
5854 SubscriptionController subController = SubscriptionController.getInstance();
5855 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5856 || subController == null) return privilegeFromSim;
5857
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005858 PackageManager pkgMgr = phone.getContext().getPackageManager();
5859 String[] packages = pkgMgr.getPackagesForUid(uid);
5860
5861 final long identity = Binder.clearCallingIdentity();
5862 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005863 int subId = phone.getSubId();
5864 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5865 // A test override is in place for the privileges for this subId, so don't try to
5866 // read the subscription privileges.
5867 return privilegeFromSim;
5868 }
5869 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005870 SubscriptionManager subManager = (SubscriptionManager)
5871 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5872 for (String pkg : packages) {
5873 if (subManager.canManageSubscription(subInfo, pkg)) {
5874 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5875 }
5876 }
5877 return privilegeFromSim;
5878 } finally {
5879 Binder.restoreCallingIdentity(identity);
5880 }
5881 }
5882
5883 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5884 String pkgName) {
5885 //load access rules from carrier configs, and check those as well: b/139133814
5886 SubscriptionController subController = SubscriptionController.getInstance();
5887 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5888 || subController == null) return privilegeFromSim;
5889
5890 final long identity = Binder.clearCallingIdentity();
5891 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005892 int subId = phone.getSubId();
5893 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5894 // A test override is in place for the privileges for this subId, so don't try to
5895 // read the subscription privileges.
5896 return privilegeFromSim;
5897 }
5898 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005899 SubscriptionManager subManager = (SubscriptionManager)
5900 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5901 return subManager.canManageSubscription(subInfo, pkgName)
5902 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5903 } finally {
5904 Binder.restoreCallingIdentity(identity);
5905 }
5906 }
5907
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005908 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005909 public int getCarrierPrivilegeStatus(int subId) {
5910 final Phone phone = getPhone(subId);
5911 if (phone == null) {
5912 loge("getCarrierPrivilegeStatus: Invalid subId");
5913 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5914 }
5915 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005916 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005917 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005918 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5919 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005920
5921 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5922 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005923 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005924 }
Junda Liu29340342014-07-10 15:23:27 -07005925
5926 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005928 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005929 final Phone phone = getPhone(subId);
5930 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005931 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5933 }
5934 UiccProfile profile =
5935 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5936 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005937 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005938 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5939 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005940 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005941 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005942 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005943 }
5944
5945 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005946 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5947 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005948 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005949 }
5950
5951 int phoneId = SubscriptionManager.getPhoneId(subId);
5952 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005953 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005954 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005955 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5956 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005957 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5958 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5959 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005960 }
5961
5962 @Override
5963 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005964 if (TextUtils.isEmpty(pkgName))
5965 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005966 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5967 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5968 UiccCard card = UiccController.getInstance().getUiccCard(i);
5969 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005970 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005971 continue;
5972 }
5973
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005974 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5975 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5976 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005977 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5978 break;
5979 }
5980 }
5981
5982 return result;
Junda Liu29340342014-07-10 15:23:27 -07005983 }
Derek Tan89e89d42014-07-08 17:00:10 -07005984
5985 @Override
Junda Liue64de782015-04-16 17:19:16 -07005986 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5987 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5988 loge("phoneId " + phoneId + " is not valid.");
5989 return null;
5990 }
5991 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005992 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005993 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005994 return null ;
5995 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005996 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005997 }
5998
Amith Yamasani6e118872016-02-19 12:53:51 -08005999 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07006000 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006001 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006002 List<String> privilegedPackages = new ArrayList<>();
6003 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006004 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6005 // has UICC in that slot.
6006 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006007 if (card.hasCarrierPrivilegeRules()) {
6008 if (packages == null) {
6009 // Only check packages in user 0 for now
6010 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006011 PackageManager.MATCH_DISABLED_COMPONENTS
6012 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006013 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006014 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006015 }
6016 for (int p = packages.size() - 1; p >= 0; p--) {
6017 PackageInfo pkgInfo = packages.get(p);
6018 if (pkgInfo != null && pkgInfo.packageName != null
6019 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006020 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006021 privilegedPackages.add(pkgInfo.packageName);
6022 }
6023 }
6024 }
6025 }
6026 return privilegedPackages;
6027 }
6028
chen xuf7e9fe82019-05-09 19:31:02 -07006029 @Override
6030 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006031 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6032
6033 final long identity = Binder.clearCallingIdentity();
6034
chen xuf7e9fe82019-05-09 19:31:02 -07006035 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006036 try {
6037 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6038 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6039 }
6040 } finally {
6041 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006042 }
6043 return privilegedPackages;
6044 }
6045
Wink Savilleb564aae2014-10-23 10:18:09 -07006046 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006047 final Phone phone = getPhone(subId);
6048 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006049 if (card == null) {
6050 loge("getIccId: No UICC");
6051 return null;
6052 }
6053 String iccId = card.getIccId();
6054 if (TextUtils.isEmpty(iccId)) {
6055 loge("getIccId: ICC ID is null or empty.");
6056 return null;
6057 }
6058 return iccId;
6059 }
6060
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006061 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006062 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6063 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006064 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006065 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006066
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006067 final long identity = Binder.clearCallingIdentity();
6068 try {
6069 final String iccId = getIccId(subId);
6070 final Phone phone = getPhone(subId);
6071 if (phone == null) {
6072 return false;
6073 }
6074 final String subscriberId = phone.getSubscriberId();
6075
6076 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006077 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006078 + subscriberId + " to " + number);
6079 }
6080
6081 if (TextUtils.isEmpty(iccId)) {
6082 return false;
6083 }
6084
6085 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6086
6087 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6088 if (alphaTag == null) {
6089 editor.remove(alphaTagPrefKey);
6090 } else {
6091 editor.putString(alphaTagPrefKey, alphaTag);
6092 }
6093
6094 // Record both the line number and IMSI for this ICCID, since we need to
6095 // track all merged IMSIs based on line number
6096 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6097 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6098 if (number == null) {
6099 editor.remove(numberPrefKey);
6100 editor.remove(subscriberPrefKey);
6101 } else {
6102 editor.putString(numberPrefKey, number);
6103 editor.putString(subscriberPrefKey, subscriberId);
6104 }
6105
6106 editor.commit();
6107 return true;
6108 } finally {
6109 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006110 }
Derek Tan7226c842014-07-02 17:42:23 -07006111 }
6112
6113 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006114 public String getLine1NumberForDisplay(int subId, String callingPackage,
6115 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006116 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006117 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006118 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006119 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006120 return null;
6121 }
Derek Tan97ebb422014-09-05 16:55:38 -07006122
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006123 final long identity = Binder.clearCallingIdentity();
6124 try {
6125 String iccId = getIccId(subId);
6126 if (iccId != null) {
6127 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6128 if (DBG_MERGE) {
6129 log("getLine1NumberForDisplay returning "
6130 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6131 }
6132 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006133 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6135 return null;
6136 } finally {
6137 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006138 }
Derek Tan7226c842014-07-02 17:42:23 -07006139 }
6140
6141 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006142 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6143 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006144 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006145 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006146 return null;
6147 }
Derek Tan97ebb422014-09-05 16:55:38 -07006148
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006149 final long identity = Binder.clearCallingIdentity();
6150 try {
6151 String iccId = getIccId(subId);
6152 if (iccId != null) {
6153 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6154 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6155 }
6156 return null;
6157 } finally {
6158 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006159 }
Derek Tan7226c842014-07-02 17:42:23 -07006160 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006161
6162 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006163 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6164 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006165 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6166 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006167 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006168 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006169 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006170 return null;
6171 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006172
Jordan Liub49b04b2019-05-06 14:45:15 -07006173 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6174 // the process, where TelephonyManager was instantiated.
6175 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006176 final long identity = Binder.clearCallingIdentity();
6177 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006178 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006179 final TelephonyManager tele = TelephonyManager.from(context);
6180 final SubscriptionManager sub = SubscriptionManager.from(context);
6181
6182 // Figure out what subscribers are currently active
6183 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006184
Jordan Liub49b04b2019-05-06 14:45:15 -07006185 // Only consider subs which match the current subId
6186 // This logic can be simplified. See b/131189269 for progress.
6187 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006188 activeSubscriberIds.add(tele.getSubscriberId(subId));
6189 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006190
6191 // First pass, find a number override for an active subscriber
6192 String mergeNumber = null;
6193 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6194 for (String key : prefs.keySet()) {
6195 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6196 final String subscriberId = (String) prefs.get(key);
6197 if (activeSubscriberIds.contains(subscriberId)) {
6198 final String iccId = key.substring(
6199 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6200 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6201 mergeNumber = (String) prefs.get(numberKey);
6202 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006203 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 + " for active subscriber " + subscriberId);
6205 }
6206 if (!TextUtils.isEmpty(mergeNumber)) {
6207 break;
6208 }
6209 }
6210 }
6211 }
6212
6213 // Shortcut when no active merged subscribers
6214 if (TextUtils.isEmpty(mergeNumber)) {
6215 return null;
6216 }
6217
6218 // Second pass, find all subscribers under that line override
6219 final ArraySet<String> result = new ArraySet<>();
6220 for (String key : prefs.keySet()) {
6221 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6222 final String number = (String) prefs.get(key);
6223 if (mergeNumber.equals(number)) {
6224 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6225 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6226 final String subscriberId = (String) prefs.get(subscriberKey);
6227 if (!TextUtils.isEmpty(subscriberId)) {
6228 result.add(subscriberId);
6229 }
6230 }
6231 }
6232 }
6233
6234 final String[] resultArray = result.toArray(new String[result.size()]);
6235 Arrays.sort(resultArray);
6236 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006237 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006238 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6239 }
6240 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006241 } finally {
6242 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006243 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006244 }
6245
6246 @Override
zoey chen38003472019-12-13 17:16:31 +08006247 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6248 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006249
6250 final long identity = Binder.clearCallingIdentity();
6251 try {
6252 final TelephonyManager telephonyManager = mApp.getSystemService(
6253 TelephonyManager.class);
6254 String subscriberId = telephonyManager.getSubscriberId(subId);
6255 if (subscriberId == null) {
6256 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006257 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006258 + subId);
6259 }
6260 return null;
6261 }
6262
6263 final SubscriptionInfo info = SubscriptionController.getInstance()
6264 .getSubscriptionInfo(subId);
6265 final ParcelUuid groupUuid = info.getGroupUuid();
6266 // If it doesn't belong to any group, return just subscriberId of itself.
6267 if (groupUuid == null) {
6268 return new String[]{subscriberId};
6269 }
6270
6271 // Get all subscriberIds from the group.
6272 final List<String> mergedSubscriberIds = new ArrayList<>();
6273 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006274 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006275 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006276 for (SubscriptionInfo subInfo : groupInfos) {
6277 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6278 if (subscriberId != null) {
6279 mergedSubscriberIds.add(subscriberId);
6280 }
6281 }
6282
6283 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6284 } finally {
6285 Binder.restoreCallingIdentity(identity);
6286
6287 }
6288 }
6289
6290 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006291 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006292 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006293 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 final Phone phone = getPhone(subId);
6298 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6299 } finally {
6300 Binder.restoreCallingIdentity(identity);
6301 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006302 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006303
6304 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006305 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006306 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6307 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006308 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6309 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006310
6311 final long identity = Binder.clearCallingIdentity();
6312 try {
6313 final Phone phone = getPhone(subId);
6314 if (phone == null) {
6315 return false;
6316 }
6317 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6318 cdmaNonRoamingList);
6319 } finally {
6320 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006321 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006322 }
6323
6324 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006325 @Deprecated
6326 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6327 enforceModifyPermission();
6328
6329 int returnValue = 0;
6330 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006331 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006332 if(result.exception == null) {
6333 if (result.result != null) {
6334 byte[] responseData = (byte[])(result.result);
6335 if(responseData.length > oemResp.length) {
6336 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6337 responseData.length + "bytes. Buffer Size is " +
6338 oemResp.length + "bytes.");
6339 }
6340 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6341 returnValue = responseData.length;
6342 }
6343 } else {
6344 CommandException ex = (CommandException) result.exception;
6345 returnValue = ex.getCommandError().ordinal();
6346 if(returnValue > 0) returnValue *= -1;
6347 }
6348 } catch (RuntimeException e) {
6349 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6350 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6351 if(returnValue > 0) returnValue *= -1;
6352 }
6353
6354 return returnValue;
6355 }
6356
6357 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006358 public void setRadioCapability(RadioAccessFamily[] rafs) {
6359 try {
6360 ProxyController.getInstance().setRadioCapability(rafs);
6361 } catch (RuntimeException e) {
6362 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6363 }
6364 }
6365
6366 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006367 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006368 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006369 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006370 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006371 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006372 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373 final long identity = Binder.clearCallingIdentity();
6374 try {
chen xub97461a2018-10-26 14:17:57 -07006375 TelephonyPermissions
6376 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6377 mApp, phone.getSubId(), "getRadioAccessFamily");
6378 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006379 } finally {
6380 Binder.restoreCallingIdentity(identity);
6381 }
chen xub97461a2018-10-26 14:17:57 -07006382 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006383 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006384
6385 @Override
6386 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006387 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006388 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389
6390 final long identity = Binder.clearCallingIdentity();
6391 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006392 ImsManager.getInstance(defaultPhone.getContext(),
6393 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006394 } finally {
6395 Binder.restoreCallingIdentity(identity);
6396 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006397 }
6398
6399 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006400 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006401 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006402 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6403 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006404 return false;
6405 }
Svet Ganovb320e182015-04-16 12:30:10 -07006406
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006407 final long identity = Binder.clearCallingIdentity();
6408 try {
6409 // Check the user preference and the system-level IMS setting. Even if the user has
6410 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6411 // In the long run, we may instead need to check if there exists a connection service
6412 // which can support video calling.
6413 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006414 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 return imsManager.isVtEnabledByPlatform()
6416 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6417 && imsManager.isVtEnabledByUser();
6418 } finally {
6419 Binder.restoreCallingIdentity(identity);
6420 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006421 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006422
Andrew Leea1239f22015-03-02 17:44:07 -08006423 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006424 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6425 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006427 mApp, subId, callingPackage, callingFeatureId,
6428 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 return false;
6430 }
6431
6432 final long identity = Binder.clearCallingIdentity();
6433 try {
6434 CarrierConfigManager configManager =
6435 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006436 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006437 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6438 } finally {
6439 Binder.restoreCallingIdentity(identity);
6440 }
Andrew Leea1239f22015-03-02 17:44:07 -08006441 }
6442
6443 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006444 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006446 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006447 return false;
6448 }
6449
6450 final long identity = Binder.clearCallingIdentity();
6451 try {
6452 CarrierConfigManager configManager =
6453 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006454 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006455 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Andrew Leea1239f22015-03-02 17:44:07 -08006459 }
6460
Andrew Lee9431b832015-03-09 18:46:45 -07006461 @Override
6462 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006463 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006464 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006465 }
6466
6467 @Override
6468 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 final long identity = Binder.clearCallingIdentity();
6470 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006471 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006472 } finally {
6473 Binder.restoreCallingIdentity(identity);
6474 }
Andrew Lee9431b832015-03-09 18:46:45 -07006475 }
6476
Hall Liuf6668912018-10-31 17:05:23 -07006477 /**
6478 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6479 * support for the feature and device firmware support.
6480 *
6481 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6482 */
6483 @Override
6484 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006485 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006486 final Phone phone = getPhone(subscriptionId);
6487 if (phone == null) {
6488 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6489 return false;
6490 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006492 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006493 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6494 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006495 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006496 return isCarrierSupported && isDeviceSupported;
6497 } finally {
6498 Binder.restoreCallingIdentity(identity);
6499 }
Hall Liu98187582018-01-22 19:15:32 -08006500 }
6501
Hall Liuf6668912018-10-31 17:05:23 -07006502 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006503 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6504 * RTT setting, will return true if the device and carrier both support RTT.
6505 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006506 */
6507 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006508 final long identity = Binder.clearCallingIdentity();
6509 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006510 boolean isRttSupported = isRttSupported(subscriptionId);
6511 boolean isUserRttSettingOn = Settings.Secure.getInt(
6512 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6513 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6514 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6515 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006516 } finally {
6517 Binder.restoreCallingIdentity(identity);
6518 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006519 }
6520
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006521 @Deprecated
6522 @Override
6523 public String getDeviceId(String callingPackage) {
6524 return getDeviceIdWithFeature(callingPackage, null);
6525 }
6526
Sanket Padawe7310cc72015-01-14 09:53:20 -08006527 /**
6528 * Returns the unique device ID of phone, for example, the IMEI for
6529 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6530 *
6531 * <p>Requires Permission:
6532 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6533 */
6534 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006535 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006536 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006537 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006538 return null;
6539 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006540 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006541 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006542 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006543 return null;
6544 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545
6546 final long identity = Binder.clearCallingIdentity();
6547 try {
6548 return phone.getDeviceId();
6549 } finally {
6550 Binder.restoreCallingIdentity(identity);
6551 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006552 }
6553
Ping Sunc67b7c22016-03-02 19:16:45 +08006554 /**
6555 * {@hide}
6556 * Returns the IMS Registration Status on a particular subid
6557 *
6558 * @param subId
6559 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006560 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006561 Phone phone = getPhone(subId);
6562 if (phone != null) {
6563 return phone.isImsRegistered();
6564 } else {
6565 return false;
6566 }
6567 }
6568
Santos Cordon7a1885b2015-02-03 11:15:19 -08006569 @Override
6570 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006571 final long identity = Binder.clearCallingIdentity();
6572 try {
6573 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6574 } finally {
6575 Binder.restoreCallingIdentity(identity);
6576 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006577 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006578
Tyler Gunnf70ed162019-04-03 15:28:53 -07006579 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006580 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006581 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006582 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006583 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006584 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6585 }
6586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 }
6593
6594 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006595 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6596 final long identity = Binder.clearCallingIdentity();
6597 try {
6598 Phone phone = getPhone(subscriptionId);
6599 if (phone == null) {
6600 return null;
6601 }
6602 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6603 } finally {
6604 Binder.restoreCallingIdentity(identity);
6605 }
6606 }
6607
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006608 /**
6609 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006610 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006611 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006612 final long identity = Binder.clearCallingIdentity();
6613 try {
6614 Phone phone = getPhone(subId);
6615 if (phone != null) {
6616 return phone.isWifiCallingEnabled();
6617 } else {
6618 return false;
6619 }
6620 } finally {
6621 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006622 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006623 }
6624
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006625 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006626 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006627 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006628 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006629 final long identity = Binder.clearCallingIdentity();
6630 try {
6631 Phone phone = getPhone(subId);
6632 if (phone != null) {
6633 return phone.isVideoEnabled();
6634 } else {
6635 return false;
6636 }
6637 } finally {
6638 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006639 }
6640 }
6641
6642 /**
6643 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6644 * defined in {@link ImsRegistrationImplBase}.
6645 */
6646 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006647 final long identity = Binder.clearCallingIdentity();
6648 try {
6649 Phone phone = getPhone(subId);
6650 if (phone != null) {
6651 return phone.getImsRegistrationTech();
6652 } else {
6653 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6654 }
6655 } finally {
6656 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006657 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006658 }
6659
Stuart Scott8eef64f2015-04-08 15:13:54 -07006660 @Override
6661 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006662 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006663 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6664 return;
6665 }
6666
Svet Ganovcc087f82015-05-12 20:35:54 -07006667 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006668
Svet Ganovcc087f82015-05-12 20:35:54 -07006669 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006670 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6671 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006672 setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
6673 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006674 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006675 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006676 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6677 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006678 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006679 // There has been issues when Sms raw table somehow stores orphan
6680 // fragments. They lead to garbled message when new fragments come
6681 // in and combined with those stale ones. In case this happens again,
6682 // user can reset all network settings which will clean up this table.
6683 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006684 // Clean up IMS settings as well here.
6685 int slotId = getSlotIndex(subId);
6686 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6687 ImsManager.getInstance(mApp, slotId).factoryReset();
6688 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006689
6690 // Erase modem config if erase modem on network setting is enabled.
6691 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6692 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6693 if (configValue != null && Boolean.parseBoolean(configValue)) {
6694 sendEraseModemConfig(getDefaultPhone());
6695 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006696 } finally {
6697 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006698 }
6699 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006700
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006701 private void cleanUpSmsRawTable(Context context) {
6702 ContentResolver resolver = context.getContentResolver();
6703 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6704 resolver.delete(uri, null, null);
6705 }
6706
Narayan Kamath1c496c22015-04-16 14:40:19 +01006707 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006708 public String getSimLocaleForSubscriber(int subId) {
6709 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6710 final Phone phone = getPhone(subId);
6711 if (phone == null) {
6712 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006713 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006714 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006715 final long identity = Binder.clearCallingIdentity();
6716 try {
chen xu5d3637b2019-01-21 23:31:38 -08006717 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006718 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006719 if (info == null) {
6720 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6721 return null;
6722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 // Try and fetch the locale from the carrier properties or from the SIM language
6724 // preferences (EF-PL and EF-LI)...
6725 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006726 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006727 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6728 if (localeFromDefaultSim != null) {
6729 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6730 if (DBG) log("Using locale from subId: " + subId + " locale: "
6731 + localeFromDefaultSim);
6732 return localeFromDefaultSim.toLanguageTag();
6733 } else {
6734 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006735 }
6736 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006737
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006738 // The SIM language preferences only store a language (e.g. fr = French), not an
6739 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6740 // the SIM and carrier preferences does not include a country we add the country
6741 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006742 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006744 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 return mccLocale.toLanguageTag();
6746 }
6747
6748 if (DBG) log("No locale found - returning null");
6749 return null;
6750 } finally {
6751 Binder.restoreCallingIdentity(identity);
6752 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006753 }
6754
6755 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006756 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006757 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006758 }
6759
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 /**
6761 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6762 */
6763 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006764 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006765 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006766 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006767
Chenjie Yu1ba97252018-01-11 18:16:20 -08006768 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006769 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006770
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006771 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006772 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6773 * representing the state of the modem.
6774 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006775 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6776 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006777 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006778 */
6779 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006780 public void requestModemActivityInfo(ResultReceiver result) {
6781 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006782 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006783
6784 final long identity = Binder.clearCallingIdentity();
6785 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006786 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 } finally {
6788 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006789 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006790 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006791
Siddharth Rayb8114062018-06-17 15:02:38 -07006792 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6793 // less than total activity duration.
6794 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6795 if (info == null) {
6796 return false;
6797 }
6798 int activityDurationMs =
6799 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6800 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006801 int[] txTimeMs = info.getTransmitTimeMillis();
6802 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6803 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006804 }
6805 return (info.isValid()
6806 && (info.getSleepTimeMillis() <= activityDurationMs)
6807 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006808 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006809 && (totalTxTimeMs <= activityDurationMs));
6810 }
6811
Jack Yu85bd38a2015-11-09 11:34:32 -08006812 /**
6813 * {@hide}
6814 * Returns the service state information on specified subscription.
6815 */
6816 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006817 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6818 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006819 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006820 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006821 return null;
6822 }
6823
Hall Liuf19c44f2018-11-27 14:38:17 -08006824 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6825 LocationAccessPolicy.checkLocationPermission(mApp,
6826 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6827 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006828 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006829 .setCallingPid(Binder.getCallingPid())
6830 .setCallingUid(Binder.getCallingUid())
6831 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006832 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006833 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006834 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6835 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006836 .build());
6837
6838 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6839 LocationAccessPolicy.checkLocationPermission(mApp,
6840 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6841 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006842 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006843 .setCallingPid(Binder.getCallingPid())
6844 .setCallingUid(Binder.getCallingUid())
6845 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006846 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006847 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006848 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6849 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006850 .build());
6851 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6852 boolean hasFinePermission =
6853 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6854 boolean hasCoarsePermission =
6855 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6856
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 final long identity = Binder.clearCallingIdentity();
6858 try {
6859 final Phone phone = getPhone(subId);
6860 if (phone == null) {
6861 return null;
6862 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006863
Hall Liuf19c44f2018-11-27 14:38:17 -08006864 ServiceState ss = phone.getServiceState();
6865
6866 // Scrub out the location info in ServiceState depending on what level of access
6867 // the caller has.
6868 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006869 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6870 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006871 } finally {
6872 Binder.restoreCallingIdentity(identity);
6873 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006874 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006875
6876 /**
6877 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6878 *
6879 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6880 * voicemail ringtone.
6881 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6882 * PhoneAccount.
6883 */
6884 @Override
6885 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006886 final long identity = Binder.clearCallingIdentity();
6887 try {
6888 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6889 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006890 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006892
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006893 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6894 } finally {
6895 Binder.restoreCallingIdentity(identity);
6896 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006897 }
6898
6899 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006900 * Sets the per-account voicemail ringtone.
6901 *
6902 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6903 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6904 *
6905 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6906 * voicemail ringtone.
6907 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6908 * PhoneAccount.
6909 */
6910 @Override
6911 public void setVoicemailRingtoneUri(String callingPackage,
6912 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006913 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006914 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006915 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6916 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006917 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6918 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6919 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006920 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006921
6922 final long identity = Binder.clearCallingIdentity();
6923 try {
6924 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6925 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006926 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006927 }
6928 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6929 } finally {
6930 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006931 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006932 }
6933
6934 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006935 * Returns whether vibration is set for voicemail notification in Phone settings.
6936 *
6937 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6938 * voicemail vibration setting.
6939 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6940 */
6941 @Override
6942 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006943 final long identity = Binder.clearCallingIdentity();
6944 try {
6945 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6946 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006947 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006949
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006950 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6951 } finally {
6952 Binder.restoreCallingIdentity(identity);
6953 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006954 }
6955
Youhan Wange64578a2016-05-02 15:32:42 -07006956 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006957 * Sets the per-account voicemail vibration.
6958 *
6959 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6960 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6961 *
6962 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6963 * voicemail vibration setting.
6964 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6965 * specific PhoneAccount.
6966 */
6967 @Override
6968 public void setVoicemailVibrationEnabled(String callingPackage,
6969 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006970 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006971 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006972 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6973 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006974 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6975 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6976 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006977 }
6978
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 final long identity = Binder.clearCallingIdentity();
6980 try {
6981 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6982 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006983 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006984 }
6985 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6986 } finally {
6987 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006988 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006989 }
6990
6991 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006992 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6993 *
6994 * @throws SecurityException if the caller does not have the required permission
6995 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006996 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006997 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006998 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006999 }
7000
7001 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007002 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7003 * permission.
7004 *
7005 * @throws SecurityException if the caller does not have the required permission
7006 */
7007 private void enforceSendSmsPermission() {
7008 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7009 }
7010
7011 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007012 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007013 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007014 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007015 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007016 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007017 final long identity = Binder.clearCallingIdentity();
7018 try {
7019 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007020 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007021 if (componentName == null) {
7022 throw new SecurityException(
7023 "Caller not current active visual voicemail package[null]");
7024 }
7025 String vvmPackage = componentName.getPackageName();
7026 if (!callingPackage.equals(vvmPackage)) {
7027 throw new SecurityException("Caller not current active visual voicemail package["
7028 + vvmPackage + "]");
7029 }
7030 } finally {
7031 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007032 }
7033 }
7034
7035 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007036 * Return the application ID for the app type.
7037 *
7038 * @param subId the subscription ID that this request applies to.
7039 * @param appType the uicc app type.
7040 * @return Application ID for specificied app type, or null if no uicc.
7041 */
7042 @Override
7043 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007044 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007045 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007046
7047 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007048 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007049 if (phone == null) {
7050 return null;
7051 }
7052 String aid = null;
7053 try {
7054 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7055 .getApplicationByType(appType).getAid();
7056 } catch (Exception e) {
7057 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7058 }
7059 return aid;
7060 } finally {
7061 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007062 }
Youhan Wange64578a2016-05-02 15:32:42 -07007063 }
7064
Youhan Wang4001d252016-05-11 10:29:41 -07007065 /**
7066 * Return the Electronic Serial Number.
7067 *
7068 * @param subId the subscription ID that this request applies to.
7069 * @return ESN or null if error.
7070 */
7071 @Override
7072 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007073 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007074 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007075
7076 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007077 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007078 if (phone == null) {
7079 return null;
7080 }
7081 String esn = null;
7082 try {
7083 esn = phone.getEsn();
7084 } catch (Exception e) {
7085 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7086 }
7087 return esn;
7088 } finally {
7089 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007090 }
Youhan Wang4001d252016-05-11 10:29:41 -07007091 }
7092
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007093 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007094 * Return the Preferred Roaming List Version.
7095 *
7096 * @param subId the subscription ID that this request applies to.
7097 * @return PRLVersion or null if error.
7098 */
7099 @Override
7100 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007101 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007102 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007103
7104 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007105 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106 if (phone == null) {
7107 return null;
7108 }
7109 String cdmaPrlVersion = null;
7110 try {
7111 cdmaPrlVersion = phone.getCdmaPrlVersion();
7112 } catch (Exception e) {
7113 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7114 }
7115 return cdmaPrlVersion;
7116 } finally {
7117 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007118 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007119 }
7120
7121 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007122 * Get snapshot of Telephony histograms
7123 * @return List of Telephony histograms
7124 * @hide
7125 */
7126 @Override
7127 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007128 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7129 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007130
7131 final long identity = Binder.clearCallingIdentity();
7132 try {
7133 return RIL.getTelephonyRILTimingHistograms();
7134 } finally {
7135 Binder.restoreCallingIdentity(identity);
7136 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007137 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007138
7139 /**
7140 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007141 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7142 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007143 * Require system privileges. In the future we may add this to carrier APIs.
7144 *
Michele Berionne482f8202018-11-27 18:57:59 -08007145 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007146 */
7147 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007148 @TelephonyManager.SetCarrierRestrictionResult
7149 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007150 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007151 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007152
Michele Berionne482f8202018-11-27 18:57:59 -08007153 if (carrierRestrictionRules == null) {
7154 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007155 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007156
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007157 final long identity = Binder.clearCallingIdentity();
7158 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007159 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007160 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007161 } finally {
7162 Binder.restoreCallingIdentity(identity);
7163 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007164 }
7165
7166 /**
7167 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007168 * Get the allowed carrier list and the excluded carrier list, including the priority between
7169 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007170 * Require system privileges. In the future we may add this to carrier APIs.
7171 *
Michele Berionne482f8202018-11-27 18:57:59 -08007172 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007173 */
7174 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007175 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007176 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007177 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007178
7179 final long identity = Binder.clearCallingIdentity();
7180 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007181 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7182 if (response instanceof CarrierRestrictionRules) {
7183 return (CarrierRestrictionRules) response;
7184 }
7185 // Response is an Exception of some kind,
7186 // which is signalled to the user as a NULL retval
7187 return null;
7188 } catch (Exception e) {
7189 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7190 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007191 } finally {
7192 Binder.restoreCallingIdentity(identity);
7193 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007194 }
7195
fionaxu59545b42016-05-25 15:53:37 -07007196 /**
fionaxu59545b42016-05-25 15:53:37 -07007197 * Action set from carrier signalling broadcast receivers to enable/disable radio
7198 * @param subId the subscription ID that this action applies to.
7199 * @param enabled control enable or disable radio.
7200 * {@hide}
7201 */
7202 @Override
7203 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7204 enforceModifyPermission();
7205 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007206
7207 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007208 if (phone == null) {
7209 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7210 return;
7211 }
7212 try {
7213 phone.carrierActionSetRadioEnabled(enabled);
7214 } catch (Exception e) {
7215 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007216 } finally {
7217 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007218 }
7219 }
7220
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007221 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007222 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7223 * network status based on which carrier apps could apply actions accordingly,
7224 * enable/disable default url handler for example.
7225 *
7226 * @param subId the subscription ID that this action applies to.
7227 * @param report control start/stop reporting the default network status.
7228 * {@hide}
7229 */
7230 @Override
7231 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7232 enforceModifyPermission();
7233 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007234
7235 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007236 if (phone == null) {
7237 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7238 return;
7239 }
7240 try {
7241 phone.carrierActionReportDefaultNetworkStatus(report);
7242 } catch (Exception e) {
7243 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007244 } finally {
7245 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007246 }
7247 }
7248
7249 /**
fionaxud9622282017-07-17 17:51:30 -07007250 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7251 * @param subId the subscription ID that this action applies to.
7252 * {@hide}
7253 */
7254 @Override
7255 public void carrierActionResetAll(int subId) {
7256 enforceModifyPermission();
7257 final Phone phone = getPhone(subId);
7258 if (phone == null) {
7259 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7260 return;
7261 }
7262 try {
7263 phone.carrierActionResetAll();
7264 } catch (Exception e) {
7265 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7266 }
7267 }
7268
7269 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007270 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7271 * bug report is being generated.
7272 */
7273 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007274 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007275 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7276 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007277 writer.println("Permission Denial: can't dump Phone from pid="
7278 + Binder.getCallingPid()
7279 + ", uid=" + Binder.getCallingUid()
7280 + "without permission "
7281 + android.Manifest.permission.DUMP);
7282 return;
7283 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007284 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007285 }
Jack Yueb89b242016-06-22 13:27:47 -07007286
Brad Ebingerdac2f002018-04-03 15:17:52 -07007287 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007288 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7289 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7290 @NonNull String[] args) {
7291 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7292 this, in.getFileDescriptor(), out.getFileDescriptor(),
7293 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007294 }
7295
Jack Yueb89b242016-06-22 13:27:47 -07007296 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007297 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007298 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007299 * @param reason the reason the data enable change is taking place
7300 * @param enabled True if enabling the data, otherwise disabling.
7301 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007302 */
7303 @Override
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007304 public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
7305 boolean enabled) {
7306 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7307 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7308 try {
7309 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7310 mApp, subId, "setDataEnabledWithReason");
7311 } catch (SecurityException se) {
7312 enforceModifyPermission();
7313 }
7314 } else {
7315 enforceModifyPermission();
7316 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317
7318 final long identity = Binder.clearCallingIdentity();
7319 try {
7320 Phone phone = getPhone(subId);
7321 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007322 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7323 phone.carrierActionSetMeteredApnsEnabled(enabled);
7324 } else {
7325 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007327 }
7328 } finally {
7329 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007330 }
7331 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007332
7333 /**
7334 * Get Client request stats
7335 * @return List of Client Request Stats
7336 * @hide
7337 */
7338 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007339 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7340 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007341 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007342 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007343 return null;
7344 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007345 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007346
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007347 final long identity = Binder.clearCallingIdentity();
7348 try {
7349 if (phone != null) {
7350 return phone.getClientRequestStats();
7351 }
7352
7353 return null;
7354 } finally {
7355 Binder.restoreCallingIdentity(identity);
7356 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007357 }
7358
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007359 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007360 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007361 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007362 }
Jack Yueb4124c2017-02-16 15:32:43 -08007363
7364 /**
Grace Chen70990072017-03-24 17:21:30 -07007365 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007366 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007367 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007368 * @param state State of SIM (power down, power up, pass through)
7369 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7370 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7371 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007372 *
7373 **/
7374 @Override
Grace Chen70990072017-03-24 17:21:30 -07007375 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007376 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007377 Phone phone = PhoneFactory.getPhone(slotIndex);
7378
vagdeviaf9a5b92018-08-15 16:01:53 -07007379 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007381 final long identity = Binder.clearCallingIdentity();
7382 try {
7383 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007384 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007385 }
7386 } finally {
7387 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007388 }
7389 }
Shuo Qiandd210312017-04-12 22:11:33 +00007390
Tyler Gunn65d45c22017-06-05 11:22:26 -07007391 private boolean isUssdApiAllowed(int subId) {
7392 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007393 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007394 if (configManager == null) {
7395 return false;
7396 }
7397 PersistableBundle pb = configManager.getConfigForSubId(subId);
7398 if (pb == null) {
7399 return false;
7400 }
7401 return pb.getBoolean(
7402 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7403 }
7404
Shuo Qiandd210312017-04-12 22:11:33 +00007405 /**
7406 * Check if phone is in emergency callback mode
7407 * @return true if phone is in emergency callback mode
7408 * @param subId sub id
7409 */
goneil9c5f4872017-12-05 14:07:56 -08007410 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007411 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007412 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007413 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007414
7415 final long identity = Binder.clearCallingIdentity();
7416 try {
7417 if (phone != null) {
7418 return phone.isInEcm();
7419 } else {
7420 return false;
7421 }
7422 } finally {
7423 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007424 }
7425 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007426
7427 /**
7428 * Get the current signal strength information for the given subscription.
7429 * Because this information is not updated when the device is in a low power state
7430 * it should not be relied-upon to be current.
7431 * @param subId Subscription index
7432 * @return the most recent cached signal strength info from the modem
7433 */
7434 @Override
7435 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007436 final long identity = Binder.clearCallingIdentity();
7437 try {
7438 Phone p = getPhone(subId);
7439 if (p == null) {
7440 return null;
7441 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007442
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007443 return p.getSignalStrength();
7444 } finally {
7445 Binder.restoreCallingIdentity(identity);
7446 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007447 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007448
Pengquan Meng77b7f132018-08-22 14:49:57 -07007449 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007450 * Get the current modem radio state for the given slot.
7451 * @param slotIndex slot index.
7452 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007453 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007454 * @return the current radio power state from the modem
7455 */
7456 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007457 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007458 Phone phone = PhoneFactory.getPhone(slotIndex);
7459 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007460 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7461 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007462 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7463 }
7464
7465 final long identity = Binder.clearCallingIdentity();
7466 try {
7467 return phone.getRadioPowerState();
7468 } finally {
7469 Binder.restoreCallingIdentity(identity);
7470 }
7471 }
7472 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7473 }
7474
7475 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007476 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7477 *
7478 * <p>Requires one of the following permissions:
7479 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7480 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7481 * privileges.
7482 *
7483 * @param subId subscription id
7484 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7485 * {@code false}.
7486 */
7487 @Override
7488 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007489 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7490 null /* message */);
7491
Pengquan Menga1bb6272018-09-06 09:59:22 -07007492 boolean isEnabled = false;
7493 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007494 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007495 Phone phone = getPhone(subId);
7496 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007497 } catch (Exception e) {
7498 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7499 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007500 } finally {
7501 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007502 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007503 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007504 }
7505
7506
7507 /**
7508 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7509 *
7510 * <p> Requires permission:
7511 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7512 * privileges.
7513 *
7514 * @param subId subscription id
7515 * @param isEnabled {@code true} means enable, {@code false} means disable.
7516 */
7517 @Override
7518 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007519 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7520 mApp, subId, "setDataRoamingEnabled");
7521
Pengquan Menga1bb6272018-09-06 09:59:22 -07007522 final long identity = Binder.clearCallingIdentity();
7523 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007524 Phone phone = getPhone(subId);
7525 if (phone != null) {
7526 phone.setDataRoamingEnabled(isEnabled);
7527 }
7528 } finally {
7529 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007530 }
7531 }
7532
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007533 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007534 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007535 TelephonyPermissions
7536 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007537 mApp, subId, "isManualNetworkSelectionAllowed");
7538
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007539 boolean isAllowed = true;
7540 final long identity = Binder.clearCallingIdentity();
7541 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007542 Phone phone = getPhone(subId);
7543 if (phone != null) {
7544 isAllowed = phone.isCspPlmnEnabled();
7545 }
7546 } finally {
7547 Binder.restoreCallingIdentity(identity);
7548 }
7549 return isAllowed;
7550 }
7551
7552 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007553 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007554 // Verify that tha callingPackage belongs to the calling UID
7555 mApp.getSystemService(AppOpsManager.class)
7556 .checkPackage(Binder.getCallingUid(), callingPackage);
7557
Jordan Liu1e142fc2019-04-22 15:10:43 -07007558 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007559 try {
7560 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007561 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007562 } catch (SecurityException e) {
7563 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7564 // has carrier privileges on an active UICC
7565 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7566 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007567 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007568 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007569 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007570
7571 final long identity = Binder.clearCallingIdentity();
7572 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007573 UiccController uiccController = UiccController.getInstance();
7574 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007575 if (hasReadPermission) {
7576 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007577 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007578
7579 // Remove private info if the caller doesn't have access
7580 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7581 for (UiccCardInfo cardInfo : cardInfos) {
7582 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7583 // is available
7584 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7585 if (card == null || card.getUiccProfile() == null) {
7586 // assume no access if the card or profile is unavailable
7587 filteredInfos.add(cardInfo.getUnprivileged());
7588 continue;
7589 }
7590 UiccProfile profile = card.getUiccProfile();
7591 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7592 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7593 filteredInfos.add(cardInfo);
7594 } else {
7595 filteredInfos.add(cardInfo.getUnprivileged());
7596 }
7597 }
7598 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007599 } finally {
7600 Binder.restoreCallingIdentity(identity);
7601 }
7602 }
7603
7604 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007605 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007606 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007607
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7611 if (slots == null) {
7612 Rlog.i(LOG_TAG, "slots is null.");
7613 return null;
7614 }
7615
7616 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7617 for (int i = 0; i < slots.length; i++) {
7618 UiccSlot slot = slots[i];
7619 if (slot == null) {
7620 continue;
7621 }
7622
Jordan Liu7be7e652019-05-06 18:55:02 +00007623 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 UiccCard card = slot.getUiccCard();
7625 if (card != null) {
7626 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007627 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007628 cardId = slot.getEid();
7629 if (TextUtils.isEmpty(cardId)) {
7630 cardId = slot.getIccId();
7631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 }
7633
Jordan Liu857451f2019-05-09 16:35:35 -07007634 if (cardId != null) {
7635 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7636 // if cardId is an EID, it's all digits so this is fine
7637 cardId = IccUtils.stripTrailingFs(cardId);
7638 }
7639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007640 int cardState = 0;
7641 switch (slot.getCardState()) {
7642 case CARDSTATE_ABSENT:
7643 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7644 break;
7645 case CARDSTATE_PRESENT:
7646 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7647 break;
7648 case CARDSTATE_ERROR:
7649 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7650 break;
7651 case CARDSTATE_RESTRICTED:
7652 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7653 break;
7654 default:
7655 break;
7656
7657 }
7658
7659 infos[i] = new UiccSlotInfo(
7660 slot.isActive(),
7661 slot.isEuicc(),
7662 cardId,
7663 cardState,
7664 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007665 slot.isExtendedApduSupported(),
7666 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007667 }
7668 return infos;
7669 } finally {
7670 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007671 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007672 }
7673
7674 @Override
7675 public boolean switchSlots(int[] physicalSlots) {
7676 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007677
7678 final long identity = Binder.clearCallingIdentity();
7679 try {
7680 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7681 } finally {
7682 Binder.restoreCallingIdentity(identity);
7683 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007684 }
Jack Yu4c988042018-02-27 15:30:01 -08007685
7686 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007687 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007688 final long identity = Binder.clearCallingIdentity();
7689 try {
7690 return UiccController.getInstance().getCardIdForDefaultEuicc();
7691 } finally {
7692 Binder.restoreCallingIdentity(identity);
7693 }
7694 }
7695
Pengquan Meng85728fb2018-03-12 16:31:21 -07007696 /**
goneil47ffb6e2018-04-06 15:40:58 -07007697 * A test API to reload the UICC profile.
7698 *
7699 * <p>Requires that the calling app has permission
7700 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7701 * @hide
7702 */
7703 @Override
7704 public void refreshUiccProfile(int subId) {
7705 enforceModifyPermission();
7706
7707 final long identity = Binder.clearCallingIdentity();
7708 try {
7709 Phone phone = getPhone(subId);
7710 if (phone == null) {
7711 return;
7712 }
7713 UiccCard uiccCard = phone.getUiccCard();
7714 if (uiccCard == null) {
7715 return;
7716 }
7717 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7718 if (uiccProfile == null) {
7719 return;
7720 }
7721 uiccProfile.refresh();
7722 } finally {
7723 Binder.restoreCallingIdentity(identity);
7724 }
7725 }
7726
7727 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007728 * Returns false if the mobile data is disabled by default, otherwise return true.
7729 */
7730 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007731 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007732 }
7733
7734 /**
7735 * Returns true if the data roaming is enabled by default, i.e the system property
7736 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7737 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7738 */
7739 private boolean getDefaultDataRoamingEnabled(int subId) {
7740 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007741 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007742 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007743 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7744 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7745 return isDataRoamingEnabled;
7746 }
7747
7748 /**
7749 * Returns the default network type for the given {@code subId}, if the default network type is
7750 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7751 */
7752 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007753 List<Integer> list = TelephonyProperties.default_network();
7754 int phoneId = mSubscriptionController.getPhoneId(subId);
7755 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7756 return list.get(phoneId);
7757 }
7758 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007759 }
fionaxua13278b2018-03-21 00:08:13 -07007760
7761 @Override
7762 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007763 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007764 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007765
7766 final long identity = Binder.clearCallingIdentity();
7767 try {
7768 final Phone phone = getPhone(subId);
7769 if (phone == null) {
7770 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7771 return;
7772 }
chen xueaba88a2019-03-15 13:15:10 -07007773 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7774 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007775 if (carrierPrivilegeRules == null) {
7776 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7777 } else {
7778 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7779 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007780 } finally {
7781 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007782 }
fionaxua13278b2018-03-21 00:08:13 -07007783 }
7784
7785 @Override
7786 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007787 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007788
7789 final long identity = Binder.clearCallingIdentity();
7790 try {
7791 final Phone phone = getPhone(subId);
7792 if (phone == null) {
7793 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7794 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7795 }
7796 return phone.getCarrierIdListVersion();
7797 } finally {
7798 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007799 }
fionaxua13278b2018-03-21 00:08:13 -07007800 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007801
7802 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007803 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7804 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007805 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007806 mApp, subId, callingPackage, callingFeatureId,
7807 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007808 return -1;
7809 }
7810
7811 final long identity = Binder.clearCallingIdentity();
7812 try {
7813 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7814 } finally {
7815 Binder.restoreCallingIdentity(identity);
7816 }
7817 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007818
7819 @Override
7820 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007821 TelephonyPermissions
7822 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007823 mApp, subId, "getCdmaRoamingMode");
7824
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
7830 }
7831 }
7832
7833 @Override
7834 public boolean setCdmaRoamingMode(int subId, int mode) {
7835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7836 mApp, subId, "setCdmaRoamingMode");
7837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
7845
7846 @Override
7847 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7848 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7849 mApp, subId, "setCdmaSubscriptionMode");
7850
7851 final long identity = Binder.clearCallingIdentity();
7852 try {
7853 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7854 } finally {
7855 Binder.restoreCallingIdentity(identity);
7856 }
7857 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007858
sqianc5eccab2018-10-19 18:46:41 -07007859 @Override
sqian8c685422019-02-22 15:55:18 -08007860 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007862 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007863 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7864 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007865 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7866 }
7867 final long identity = Binder.clearCallingIdentity();
7868 try {
sqian854d44b2018-12-12 16:48:18 -08007869 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7870 for (Phone phone: PhoneFactory.getPhones()) {
7871 if (phone.getEmergencyNumberTracker() != null
7872 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7873 emergencyNumberListInternal.put(
7874 phone.getSubId(),
7875 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7876 }
sqian11b7a0e2018-12-05 18:48:28 -08007877 }
sqian854d44b2018-12-12 16:48:18 -08007878 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007879 } finally {
7880 Binder.restoreCallingIdentity(identity);
7881 }
sqianc5eccab2018-10-19 18:46:41 -07007882 }
7883
7884 @Override
sqian8c685422019-02-22 15:55:18 -08007885 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007886 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007887 if (!exactMatch) {
7888 TelephonyPermissions
7889 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007890 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007891 }
7892 final long identity = Binder.clearCallingIdentity();
7893 try {
sqian854d44b2018-12-12 16:48:18 -08007894 for (Phone phone: PhoneFactory.getPhones()) {
7895 if (phone.getEmergencyNumberTracker() != null
7896 && phone.getEmergencyNumberTracker() != null) {
7897 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7898 number, exactMatch)) {
7899 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007900 }
7901 }
sqian11b7a0e2018-12-05 18:48:28 -08007902 }
7903 return false;
7904 } finally {
7905 Binder.restoreCallingIdentity(identity);
7906 }
7907 }
7908
sqianf4ca7ed2019-01-15 18:32:07 -08007909 /**
7910 * Update emergency number list for test mode.
7911 */
7912 @Override
7913 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7914 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7915 "updateEmergencyNumberListTestMode");
7916
7917 final long identity = Binder.clearCallingIdentity();
7918 try {
7919 for (Phone phone: PhoneFactory.getPhones()) {
7920 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7921 if (tracker != null) {
7922 tracker.executeEmergencyNumberTestModeCommand(action, num);
7923 }
7924 }
7925 } finally {
7926 Binder.restoreCallingIdentity(identity);
7927 }
7928 }
7929
7930 /**
7931 * Get the full emergency number list for test mode.
7932 */
7933 @Override
7934 public List<String> getEmergencyNumberListTestMode() {
7935 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7936 "getEmergencyNumberListTestMode");
7937
7938 final long identity = Binder.clearCallingIdentity();
7939 try {
7940 Set<String> emergencyNumbers = new HashSet<>();
7941 for (Phone phone: PhoneFactory.getPhones()) {
7942 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7943 if (tracker != null) {
7944 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7945 emergencyNumbers.add(num.getNumber());
7946 }
7947 }
7948 }
7949 return new ArrayList<>(emergencyNumbers);
7950 } finally {
7951 Binder.restoreCallingIdentity(identity);
7952 }
7953 }
7954
chen xud6b45bd2018-10-30 22:27:10 -07007955 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007956 public int getEmergencyNumberDbVersion(int subId) {
7957 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7958
7959 final long identity = Binder.clearCallingIdentity();
7960 try {
7961 final Phone phone = getPhone(subId);
7962 if (phone == null) {
7963 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7964 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7965 }
7966 return phone.getEmergencyNumberDbVersion();
7967 } finally {
7968 Binder.restoreCallingIdentity(identity);
7969 }
7970 }
7971
7972 @Override
7973 public void notifyOtaEmergencyNumberDbInstalled() {
7974 enforceModifyPermission();
7975
7976 final long identity = Binder.clearCallingIdentity();
7977 try {
7978 for (Phone phone: PhoneFactory.getPhones()) {
7979 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7980 if (tracker != null) {
7981 tracker.updateOtaEmergencyNumberDatabase();
7982 }
7983 }
7984 } finally {
7985 Binder.restoreCallingIdentity(identity);
7986 }
7987 }
7988
7989 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007990 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007991 enforceActiveEmergencySessionPermission();
7992
7993 final long identity = Binder.clearCallingIdentity();
7994 try {
7995 for (Phone phone: PhoneFactory.getPhones()) {
7996 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7997 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007998 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7999 }
8000 }
8001 } finally {
8002 Binder.restoreCallingIdentity(identity);
8003 }
8004 }
8005
8006 @Override
8007 public void resetOtaEmergencyNumberDbFilePath() {
8008 enforceActiveEmergencySessionPermission();
8009
8010 final long identity = Binder.clearCallingIdentity();
8011 try {
8012 for (Phone phone: PhoneFactory.getPhones()) {
8013 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8014 if (tracker != null) {
8015 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008016 }
8017 }
8018 } finally {
8019 Binder.restoreCallingIdentity(identity);
8020 }
8021 }
8022
8023 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008024 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8025 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8026 Phone phone = getPhone(subId);
8027 if (phone == null) {
8028 return null;
8029 }
8030 final long identity = Binder.clearCallingIdentity();
8031 try {
8032 UiccProfile profile = UiccController.getInstance()
8033 .getUiccProfileForPhone(phone.getPhoneId());
8034 if (profile != null) {
8035 return profile.getCertsFromCarrierPrivilegeAccessRules();
8036 }
8037 } finally {
8038 Binder.restoreCallingIdentity(identity);
8039 }
8040 return null;
8041 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008042
8043 /**
8044 * Enable or disable a modem stack.
8045 */
8046 @Override
8047 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8048 enforceModifyPermission();
8049
8050 final long identity = Binder.clearCallingIdentity();
8051 try {
8052 Phone phone = PhoneFactory.getPhone(slotIndex);
8053 if (phone == null) {
8054 return false;
8055 } else {
8056 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8057 }
8058 } finally {
8059 Binder.restoreCallingIdentity(identity);
8060 }
8061 }
Michelecea4cf22018-12-21 15:00:11 -08008062
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008063 /**
8064 * Whether a modem stack is enabled or not.
8065 */
8066 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008067 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8068 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008069 Phone phone = PhoneFactory.getPhone(slotIndex);
8070 if (phone == null) return false;
8071
8072 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008073 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8074 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008075 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8076 }
8077
8078 final long identity = Binder.clearCallingIdentity();
8079 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008080 try {
8081 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8082 } catch (NoSuchElementException ex) {
8083 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8084 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008085 } finally {
8086 Binder.restoreCallingIdentity(identity);
8087 }
8088 }
8089
Michelecea4cf22018-12-21 15:00:11 -08008090 @Override
Michele0ea7d782019-03-19 14:58:42 -07008091 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008092 enforceModifyPermission();
8093
8094 final long identity = Binder.clearCallingIdentity();
8095 try {
8096 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008097 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008098 .commit();
8099 } finally {
8100 Binder.restoreCallingIdentity(identity);
8101 }
8102 }
8103
8104 @Override
Michele0ea7d782019-03-19 14:58:42 -07008105 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008106 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008107 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008108 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8109 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008110 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008111 }
Michelecea4cf22018-12-21 15:00:11 -08008112
8113 final long identity = Binder.clearCallingIdentity();
8114 try {
Michele0ea7d782019-03-19 14:58:42 -07008115 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008116 } finally {
8117 Binder.restoreCallingIdentity(identity);
8118 }
8119 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008120
Michele0ea7d782019-03-19 14:58:42 -07008121 @TelephonyManager.IsMultiSimSupportedResult
8122 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008123 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8124 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8125 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008126 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8127 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008128 }
8129 // Check if the hardware supports multisim functionality. If usage of multisim is not
8130 // supported by the modem, indicate that it is restricted.
8131 PhoneCapability staticCapability =
8132 mPhoneConfigurationManager.getStaticPhoneCapability();
8133 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008134 loge("isMultiSimSupportedInternal: no static configuration available");
8135 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008136 }
Sarah Chin7caee492020-02-18 20:49:02 +00008137 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008138 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8139 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008140 }
8141 // Check if support of multiple SIMs is restricted by carrier
8142 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008143 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008144 }
8145
Michele0ea7d782019-03-19 14:58:42 -07008146 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008147 }
8148
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008149 /**
8150 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008151 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8152 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8153 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008154 * @param numOfSims number of active sims we want to switch to
8155 */
8156 @Override
8157 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008158 if (numOfSims == 1) {
8159 enforceModifyPermission();
8160 } else {
8161 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8162 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8163 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008164 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008165
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008166 try {
Michele30b57b22019-03-01 12:01:14 -08008167 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008168 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008169 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8170 return;
8171 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008172 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8173 } finally {
8174 Binder.restoreCallingIdentity(identity);
8175 }
8176 }
8177
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008178 @Override
8179 public boolean isApplicationOnUicc(int subId, int appType) {
8180 enforceReadPrivilegedPermission("isApplicationOnUicc");
8181 Phone phone = getPhone(subId);
8182 if (phone == null) {
8183 return false;
8184 }
8185 final long identity = Binder.clearCallingIdentity();
8186 try {
8187 UiccCard uiccCard = phone.getUiccCard();
8188 if (uiccCard == null) {
8189 return false;
8190 }
8191 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8192 if (uiccProfile == null) {
8193 return false;
8194 }
8195 if (TelephonyManager.APPTYPE_SIM <= appType
8196 && appType <= TelephonyManager.APPTYPE_ISIM) {
8197 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8198 }
8199 return false;
8200 } finally {
8201 Binder.restoreCallingIdentity(identity);
8202 }
8203 }
8204
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008205 /**
chen xub4baa772019-04-03 10:23:41 -07008206 * Get whether making changes to modem configurations will trigger reboot.
8207 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008208 */
8209 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008210 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8211 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008212 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008213 mApp, subId, callingPackage, callingFeatureId,
8214 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008215 return false;
8216 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008217 final long identity = Binder.clearCallingIdentity();
8218 try {
8219 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8220 } finally {
8221 Binder.restoreCallingIdentity(identity);
8222 }
8223 }
8224
Nathan Harold29f5f052019-02-15 13:41:57 -08008225 private void updateModemStateMetrics() {
8226 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8227 // TODO: check the state for each modem if the api is ready.
8228 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8229 }
8230
Pengquan Meng3889a572019-01-23 11:16:29 -08008231 @Override
8232 public int[] getSlotsMapping() {
8233 enforceReadPrivilegedPermission("getSlotsMapping");
8234
8235 final long identity = Binder.clearCallingIdentity();
8236 try {
8237 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8238 // All logical slots should have a mapping to a physical slot.
8239 int[] logicalSlotsMapping = new int[phoneCount];
8240 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8241 for (int i = 0; i < slotInfos.length; i++) {
8242 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8243 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8244 }
8245 }
8246 return logicalSlotsMapping;
8247 } finally {
8248 Binder.restoreCallingIdentity(identity);
8249 }
8250 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008251
8252 /**
8253 * Get the IRadio HAL Version
8254 */
8255 @Override
8256 public int getRadioHalVersion() {
8257 Phone phone = getDefaultPhone();
8258 if (phone == null) return -1;
8259 HalVersion hv = phone.getHalVersion();
8260 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8261 return hv.major * 100 + hv.minor;
8262 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008263
8264 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008265 * Get the current calling package name.
8266 * @return the current calling package name
8267 */
8268 @Override
8269 public String getCurrentPackageName() {
8270 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8271 }
8272
8273 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008274 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8275 * corresponding network requests on a subId.
8276 *
8277 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008278 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008279 * 2) APN is un-metered for this subscription, or
8280 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008281 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008282 *
8283 * @return whether data is allowed for a apn type.
8284 *
8285 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008286 */
8287 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008288 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008289 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8290 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008291
8292 // Now that all security checks passes, perform the operation as ourselves.
8293 final long identity = Binder.clearCallingIdentity();
8294 try {
8295 Phone phone = getPhone(subId);
8296 if (phone == null) return false;
8297
Jack Yu41407ee2019-05-13 16:54:09 -07008298 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008299 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8300 } finally {
8301 Binder.restoreCallingIdentity(identity);
8302 }
8303 }
8304
8305 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008306 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008307 enforceReadPrivilegedPermission("isApnMetered");
8308
8309 // Now that all security checks passes, perform the operation as ourselves.
8310 final long identity = Binder.clearCallingIdentity();
8311 try {
8312 Phone phone = getPhone(subId);
8313 if (phone == null) return true; // By default return true.
8314
Jack Yu41407ee2019-05-13 16:54:09 -07008315 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008316 } finally {
8317 Binder.restoreCallingIdentity(identity);
8318 }
8319 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008320
8321 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008322 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8323 int subscriptionId, IBooleanConsumer resultCallback) {
8324 enforceModifyPermission();
8325 long token = Binder.clearCallingIdentity();
8326 try {
8327 Phone phone = getPhone(subscriptionId);
8328 if (phone == null) {
8329 try {
8330 if (resultCallback != null) {
8331 resultCallback.accept(false);
8332 }
8333 } catch (RemoteException e) {
8334 // ignore
8335 }
8336 return;
8337 }
8338 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8339 Pair.create(specifiers, (x) -> {
8340 try {
8341 if (resultCallback != null) {
8342 resultCallback.accept(x);
8343 }
8344 } catch (RemoteException e) {
8345 // ignore
8346 }
8347 });
8348 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8349 } finally {
8350 Binder.restoreCallingIdentity(token);
8351 }
8352 }
8353
8354 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008355 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008356 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008357 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8358 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8359 if (iccRecords == null) {
8360 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8361 return false;
8362 }
8363 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8364 }
8365
8366 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008367 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8368 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008369 if (callingPackage == null) {
8370 callingPackage = getCurrentPackageName();
8371 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008372 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8373 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008374 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8375 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008376 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8377 }
8378 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8379 Intent intent = new Intent();
8380 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8381 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8382 // Bring up choose default SMS subscription dialog right now
8383 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8384 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8385 mApp.startActivity(intent);
8386 }
chen xud5ca2d52019-05-28 15:20:57 -07008387
8388 @Override
8389 public String getMmsUAProfUrl(int subId) {
8390 //TODO investigate if this API should require proper permission check in R b/133791609
8391 final long identity = Binder.clearCallingIdentity();
8392 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008393 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8394 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008395 } finally {
8396 Binder.restoreCallingIdentity(identity);
8397 }
8398 }
8399
8400 @Override
8401 public String getMmsUserAgent(int subId) {
8402 //TODO investigate if this API should require proper permission check in R b/133791609
8403 final long identity = Binder.clearCallingIdentity();
8404 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008405 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8406 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008407 } finally {
8408 Binder.restoreCallingIdentity(identity);
8409 }
8410 }
Jack Yub07d4972019-05-28 16:12:25 -07008411
8412 @Override
8413 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8414 enforceModifyPermission();
8415
8416 // Now that all security checks passes, perform the operation as ourselves.
8417 final long identity = Binder.clearCallingIdentity();
8418 try {
8419 Phone phone = getPhone(subId);
8420 if (phone == null) return false;
8421
8422 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8423 } finally {
8424 Binder.restoreCallingIdentity(identity);
8425 }
8426 }
8427
8428 @Override
8429 public boolean isDataAllowedInVoiceCall(int subId) {
8430 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8431
8432 // Now that all security checks passes, perform the operation as ourselves.
8433 final long identity = Binder.clearCallingIdentity();
8434 try {
8435 Phone phone = getPhone(subId);
8436 if (phone == null) return false;
8437
8438 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8439 } finally {
8440 Binder.restoreCallingIdentity(identity);
8441 }
8442 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008443
changbettyd5c246e2019-12-24 15:40:37 +08008444 @Override
8445 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8446 enforceModifyPermission();
8447
8448 // Now that all security checks passes, perform the operation as ourselves.
8449 final long identity = Binder.clearCallingIdentity();
8450 try {
8451 Phone phone = getPhone(subId);
8452 if (phone == null) return false;
8453
8454 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008460 /**
8461 * Updates whether conference event pacakge handling is enabled.
8462 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8463 * otherwise.
8464 */
8465 @Override
8466 public void setCepEnabled(boolean isCepEnabled) {
8467 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8468
8469 final long identity = Binder.clearCallingIdentity();
8470 try {
8471 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8472 for (Phone phone : PhoneFactory.getPhones()) {
8473 Phone defaultPhone = phone.getImsPhone();
8474 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8475 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8476 ImsPhoneCallTracker imsPhoneCallTracker =
8477 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8478 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8479 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8480 + imsPhone.getMsisdn());
8481 }
8482 }
8483 } finally {
8484 Binder.restoreCallingIdentity(identity);
8485 }
8486 }
allenwtsu46dcc572020-01-08 18:24:03 +08008487
8488 /**
8489 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8490 *
8491 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8492 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8493 * before being read.
8494 */
8495 @Override
8496 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8497 isCompressed) {
8498 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8499 mApp, subId, "notifyRcsAutoConfigurationReceived");
8500 try {
8501 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8502 if (configBinder == null) {
8503 Rlog.e(LOG_TAG, "null result for getImsConfig");
8504 } else {
8505 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8506 }
8507 } catch (RemoteException e) {
8508 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8509 }
8510 }
zoey chene02881a2019-12-30 16:11:23 +08008511
8512 @Override
8513 public boolean isIccLockEnabled(int subId) {
8514 enforceReadPrivilegedPermission("isIccLockEnabled");
8515
8516 // Now that all security checks passes, perform the operation as ourselves.
8517 final long identity = Binder.clearCallingIdentity();
8518 try {
8519 Phone phone = getPhone(subId);
8520 if (phone != null && phone.getIccCard() != null) {
8521 return phone.getIccCard().getIccLockEnabled();
8522 } else {
8523 return false;
8524 }
8525 } finally {
8526 Binder.restoreCallingIdentity(identity);
8527 }
8528 }
8529
8530 /**
8531 * Set the ICC pin lock enabled or disabled.
8532 *
8533 * @return an integer representing the status of IccLock enabled or disabled in the following
8534 * three cases:
8535 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8536 * successfully.
8537 * - Positive number and zero for remaining password attempts.
8538 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8539 *
8540 */
8541 @Override
8542 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8543 enforceModifyPermission();
8544
8545 Phone phone = getPhone(subId);
8546 if (phone == null) {
8547 return 0;
8548 }
8549 // Now that all security checks passes, perform the operation as ourselves.
8550 final long identity = Binder.clearCallingIdentity();
8551 try {
8552 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8553 new Pair<Boolean, String>(enabled, password), phone, null);
8554 return attemptsRemaining;
8555
8556 } catch (Exception e) {
8557 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8558 } finally {
8559 Binder.restoreCallingIdentity(identity);
8560 }
8561 return 0;
8562 }
8563
8564 /**
8565 * Change the ICC password used in ICC pin lock.
8566 *
8567 * @return an integer representing the status of IccLock changed in the following three cases:
8568 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8569 * - Positive number and zero for remaining password attempts.
8570 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8571 *
8572 */
8573 @Override
8574 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8575 enforceModifyPermission();
8576
8577 Phone phone = getPhone(subId);
8578 if (phone == null) {
8579 return 0;
8580 }
8581 // Now that all security checks passes, perform the operation as ourselves.
8582 final long identity = Binder.clearCallingIdentity();
8583 try {
8584 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8585 new Pair<String, String>(oldPassword, newPassword), phone, null);
8586 return attemptsRemaining;
8587
8588 } catch (Exception e) {
8589 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8590 } finally {
8591 Binder.restoreCallingIdentity(identity);
8592 }
8593 return 0;
8594 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008595
8596 /**
8597 * Request for receiving user activity notification
8598 */
8599 @Override
8600 public void requestUserActivityNotification() {
8601 if (!mNotifyUserActivity.get()
8602 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8603 mNotifyUserActivity.set(true);
8604 }
8605 }
8606
8607 /**
8608 * Called when userActivity is signalled in the power manager.
8609 * This is safe to call from any thread, with any window manager locks held or not.
8610 */
8611 @Override
8612 public void userActivity() {
8613 // ***************************************
8614 // * Inherited from PhoneWindowManager *
8615 // ***************************************
8616 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8617 // WITH ITS LOCKS HELD.
8618 //
8619 // This code must be VERY careful about the locks
8620 // it acquires.
8621 // In fact, the current code acquires way too many,
8622 // and probably has lurking deadlocks.
8623
8624 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8625 throw new SecurityException("Only the OS may call notifyUserActivity()");
8626 }
8627
8628 if (mNotifyUserActivity.getAndSet(false)) {
8629 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8630 USER_ACTIVITY_NOTIFICATION_DELAY);
8631 }
8632 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008633
8634 @Override
8635 public boolean canConnectTo5GInDsdsMode() {
8636 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8637 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008638}