blob: 8d26c5a5fdf39fc0de83682917eafec97258e041 [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)
5417 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005419 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 if (e != null) {
5421 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5422 throw e;
5423 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005424 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005425 return TelephonyScanManager.INVALID_SCAN_ID;
5426 }
5427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 }
Hall Liu912dfd32019-04-25 14:02:26 -07005429 int callingUid = Binder.getCallingUid();
5430 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 return mNetworkScanRequestTracker.startNetworkScan(
5434 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005435 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
yinxu504e1392017-04-12 16:03:22 -07005439 }
5440
Hall Liub2ac8ef2019-02-28 15:56:23 -08005441 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005442 NetworkScanRequest request, int subId) {
5443 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5444 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5445 boolean hasNetworkScanPermission =
5446 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5447 == PERMISSION_GRANTED;
5448
5449 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5450 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5451 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005452 }
5453
5454 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5455 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005456 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5457 return new SecurityException("Specific channels must not be"
5458 + " scanned without location access.");
5459 }
5460 }
5461 }
5462
Hall Liub2ac8ef2019-02-28 15:56:23 -08005463 return null;
5464 }
5465
yinxu504e1392017-04-12 16:03:22 -07005466 /**
5467 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005468 *
5469 * @param subId id of the subscription
5470 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005471 */
5472 @Override
5473 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476
Hall Liu912dfd32019-04-25 14:02:26 -07005477 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005480 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
yinxu504e1392017-04-12 16:03:22 -07005484 }
5485
5486 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005487 * Get the calculated preferred network type.
5488 * Used for debugging incorrect network type.
5489 *
5490 * @return the preferred network type, defined in RILConstants.java.
5491 */
5492 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 final Phone defaultPhone = getDefaultPhone();
5495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005496 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005497 return RILConstants.PREFERRED_NETWORK_MODE;
5498 }
5499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005503 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Junda Liu84d15a22014-07-02 11:21:04 -07005507 }
5508
5509 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005510 * Get the preferred network type.
5511 * Used for device configuration by some CDMA operators.
5512 *
5513 * @return the preferred network type, defined in RILConstants.java.
5514 */
5515 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005516 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005517 TelephonyPermissions
5518 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5519 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 if (DBG) log("getPreferredNetworkType");
5524 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5525 int networkType = (result != null ? result[0] : -1);
5526 if (DBG) log("getPreferredNetworkType: " + networkType);
5527 return networkType;
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005531 }
5532
5533 /**
5534 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005535 *
5536 * @param networkType the preferred network type, defined in RILConstants.java.
5537 * @return true on success; false on any failure.
5538 */
5539 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005540 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5542 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005546 Settings.Global.putInt(mApp.getContentResolver(),
5547 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005548
5549 Boolean success = (Boolean) sendRequest(
5550 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5551 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5552 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005555 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005556 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005557
5558 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005559 * Get the allowed network types that store in the telephony provider.
5560 *
5561 * @param subId the id of the subscription.
5562 * @return allowedNetworkTypes the allowed network types.
5563 */
5564 @Override
5565 public long getAllowedNetworkTypes(int subId) {
5566 TelephonyPermissions
5567 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5568 mApp, subId, "getAllowedNetworkTypes");
5569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 return SubscriptionManager.getLongSubscriptionProperty(
5573 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
5577 }
5578
5579 /**
5580 * Set the allowed network types.
5581 *
5582 * @param subId the id of the subscription.
5583 * @param allowedNetworkTypes the allowed network types.
5584 * @return true on success; false on any failure.
5585 */
5586 @Override
5587 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005590
calvinpan8ed33732020-03-12 14:17:55 +08005591 SubscriptionManager.setSubscriptionProperty(subId,
5592 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5593 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005594
calvinpan8ed33732020-03-12 14:17:55 +08005595 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5596 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5597 RILConstants.PREFERRED_NETWORK_MODE);
5598 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005599 }
5600
5601 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005602 * Get the allowed network types for certain reason.
5603 *
5604 * @param subId the id of the subscription.
5605 * @param reason the reason the allowed network type change is taking place
5606 * @return the allowed network types.
5607 */
5608 @Override
5609 public long getAllowedNetworkTypesForReason(int subId,
5610 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5611 TelephonyPermissions
5612 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5613 mApp, subId, "getAllowedNetworkTypesForReason");
5614 final long identity = Binder.clearCallingIdentity();
5615 try {
5616 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5617 } finally {
5618 Binder.restoreCallingIdentity(identity);
5619 }
5620 }
5621
5622 /**
5623 * Get the effective allowed network types on the device.
5624 * This API will return an intersection of allowed network types for all reasons,
5625 * including the configuration done through setAllowedNetworkTypes
5626 *
5627 * @param subId the id of the subscription.
5628 * @return the allowed network types
5629 */
5630 @Override
5631 public long getEffectiveAllowedNetworkTypes(int subId) {
5632 TelephonyPermissions
5633 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5634 mApp, subId, "getEffectiveAllowedNetworkTypes");
5635 final long identity = Binder.clearCallingIdentity();
5636 try {
5637 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5638 } finally {
5639 Binder.restoreCallingIdentity(identity);
5640 }
5641 }
5642
5643 /**
5644 * Set the allowed network types of the device and
5645 * provide the reason triggering the allowed network change.
5646 *
5647 * @param subId the id of the subscription.
5648 * @param reason the reason the allowed network type change is taking place
5649 * @param allowedNetworkTypes the allowed network types.
5650 * @return true on success; false on any failure.
5651 */
5652 @Override
5653 public boolean setAllowedNetworkTypesForReason(int subId,
5654 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5656 mApp, subId, "setAllowedNetworkTypesForReason");
5657 final long identity = Binder.clearCallingIdentity();
5658 try {
5659 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5660 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5661 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5662 RILConstants.PREFERRED_NETWORK_MODE);
5663 return setPreferredNetworkType(subId, preferredNetworkMode);
5664 } finally {
5665 Binder.restoreCallingIdentity(identity);
5666 }
5667 }
5668
5669 /**
Miaoa84611c2019-03-15 09:21:10 +08005670 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005671 *
Miaoa84611c2019-03-15 09:21:10 +08005672 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005673 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005674 * @hide
5675 */
5676 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005677 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005678 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005679 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005680 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005681 try {
Miaoa84611c2019-03-15 09:21:10 +08005682 if (phone != null) {
5683 return phone.hasMatchedTetherApnSetting();
5684 } else {
5685 return false;
5686 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005687 } finally {
5688 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005689 }
Junda Liu475951f2014-11-07 16:45:03 -08005690 }
5691
5692 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005693 * Enable or disable always reporting signal strength changes from radio.
5694 *
5695 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5696 */
5697 @Override
5698 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5699 enforceModifyPermission();
5700 enforceSystemCaller();
5701
5702 final long identity = Binder.clearCallingIdentity();
5703 final Phone phone = getPhone(subId);
5704 try {
5705 if (phone != null) {
5706 if (DBG) {
5707 log("setAlwaysReportSignalStrength: subId=" + subId
5708 + " isEnable=" + isEnable);
5709 }
5710 phone.setAlwaysReportSignalStrength(isEnable);
5711 } else {
5712 loge("setAlwaysReportSignalStrength: no phone found for subId="
5713 + subId);
5714 }
5715 } finally {
5716 Binder.restoreCallingIdentity(identity);
5717 }
5718 }
5719
5720 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005721 * Get the user enabled state of Mobile Data.
5722 *
5723 * TODO: remove and use isUserDataEnabled.
5724 * This can't be removed now because some vendor codes
5725 * calls through ITelephony directly while they should
5726 * use TelephonyManager.
5727 *
5728 * @return true on enabled
5729 */
5730 @Override
5731 public boolean getDataEnabled(int subId) {
5732 return isUserDataEnabled(subId);
5733 }
5734
5735 /**
5736 * Get whether mobile data is enabled per user setting.
5737 *
5738 * There are other factors deciding whether mobile data is actually enabled, but they are
5739 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005740 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005741 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005742 *
5743 * @return {@code true} if data is enabled else {@code false}
5744 */
5745 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005746 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005747 try {
5748 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5749 null);
5750 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005751 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5752 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005753 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005754
5755 final long identity = Binder.clearCallingIdentity();
5756 try {
5757 int phoneId = mSubscriptionController.getPhoneId(subId);
5758 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5759 Phone phone = PhoneFactory.getPhone(phoneId);
5760 if (phone != null) {
5761 boolean retVal = phone.isUserDataEnabled();
5762 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5763 return retVal;
5764 } else {
5765 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5766 return false;
5767 }
5768 } finally {
5769 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005770 }
5771 }
5772
5773 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005774 * Checks if the device is capable of mobile data by considering whether whether the
5775 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5776 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005777 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005778 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005779 */
5780 @Override
5781 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005782 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005783
5784 final long identity = Binder.clearCallingIdentity();
5785 try {
5786 int phoneId = mSubscriptionController.getPhoneId(subId);
5787 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5788 Phone phone = PhoneFactory.getPhone(phoneId);
5789 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005790 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005791 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5792 return retVal;
5793 } else {
5794 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5795 return false;
5796 }
5797 } finally {
5798 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005799 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005800 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005801
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005802 /**
5803 * Check if data is enabled for a specific reason
5804 * @param subId Subscription index
5805 * @param reason the reason the data enable change is taking place
5806 * @return {@code true} if the overall data is enabled; {@code false} if not.
5807 */
5808 @Override
5809 public boolean isDataEnabledWithReason(int subId,
5810 @TelephonyManager.DataEnabledReason int reason) {
5811 try {
5812 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5813 null);
5814 } catch (Exception e) {
5815 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5816 "isDataEnabledWithReason");
5817 }
5818
5819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
5822 int phoneId = mSubscriptionController.getPhoneId(subId);
5823 if (DBG) {
5824 log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
5825 + " reason=" + reason);
5826 }
5827 Phone phone = PhoneFactory.getPhone(phoneId);
5828 if (phone != null) {
5829 boolean retVal;
5830 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5831 retVal = phone.isUserDataEnabled();
5832 } else {
5833 retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
5834 }
5835 if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
5836 return retVal;
5837 } else {
5838 if (DBG) {
5839 loge("isDataEnabledWithReason: no phone subId="
5840 + subId + " retVal=false");
5841 }
5842 return false;
5843 }
5844 } finally {
5845 Binder.restoreCallingIdentity(identity);
5846 }
5847 }
5848
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005849 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005850 Phone phone) {
5851 //load access rules from carrier configs, and check those as well: b/139133814
5852 SubscriptionController subController = SubscriptionController.getInstance();
5853 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5854 || subController == null) return privilegeFromSim;
5855
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005856 PackageManager pkgMgr = phone.getContext().getPackageManager();
5857 String[] packages = pkgMgr.getPackagesForUid(uid);
5858
5859 final long identity = Binder.clearCallingIdentity();
5860 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005861 int subId = phone.getSubId();
5862 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5863 // A test override is in place for the privileges for this subId, so don't try to
5864 // read the subscription privileges.
5865 return privilegeFromSim;
5866 }
5867 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005868 SubscriptionManager subManager = (SubscriptionManager)
5869 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5870 for (String pkg : packages) {
5871 if (subManager.canManageSubscription(subInfo, pkg)) {
5872 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5873 }
5874 }
5875 return privilegeFromSim;
5876 } finally {
5877 Binder.restoreCallingIdentity(identity);
5878 }
5879 }
5880
5881 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5882 String pkgName) {
5883 //load access rules from carrier configs, and check those as well: b/139133814
5884 SubscriptionController subController = SubscriptionController.getInstance();
5885 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5886 || subController == null) return privilegeFromSim;
5887
5888 final long identity = Binder.clearCallingIdentity();
5889 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005890 int subId = phone.getSubId();
5891 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5892 // A test override is in place for the privileges for this subId, so don't try to
5893 // read the subscription privileges.
5894 return privilegeFromSim;
5895 }
5896 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005897 SubscriptionManager subManager = (SubscriptionManager)
5898 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5899 return subManager.canManageSubscription(subInfo, pkgName)
5900 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5901 } finally {
5902 Binder.restoreCallingIdentity(identity);
5903 }
5904 }
5905
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005906 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005907 public int getCarrierPrivilegeStatus(int subId) {
5908 final Phone phone = getPhone(subId);
5909 if (phone == null) {
5910 loge("getCarrierPrivilegeStatus: Invalid subId");
5911 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5912 }
5913 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005914 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005915 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005916 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5917 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005918
5919 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5920 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005921 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005922 }
Junda Liu29340342014-07-10 15:23:27 -07005923
5924 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005925 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005926 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 final Phone phone = getPhone(subId);
5928 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005929 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005930 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5931 }
5932 UiccProfile profile =
5933 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5934 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005935 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005936 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5937 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005938 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005939 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005940 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005941 }
5942
5943 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005944 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5945 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005946 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005947 }
5948
5949 int phoneId = SubscriptionManager.getPhoneId(subId);
5950 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005951 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005952 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005953 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5954 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005955 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5956 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5957 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005958 }
5959
5960 @Override
5961 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005962 if (TextUtils.isEmpty(pkgName))
5963 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005964 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5965 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5966 UiccCard card = UiccController.getInstance().getUiccCard(i);
5967 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005968 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005969 continue;
5970 }
5971
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005972 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5973 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5974 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005975 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5976 break;
5977 }
5978 }
5979
5980 return result;
Junda Liu29340342014-07-10 15:23:27 -07005981 }
Derek Tan89e89d42014-07-08 17:00:10 -07005982
5983 @Override
Junda Liue64de782015-04-16 17:19:16 -07005984 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5985 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5986 loge("phoneId " + phoneId + " is not valid.");
5987 return null;
5988 }
5989 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005990 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005991 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005992 return null ;
5993 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005994 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005995 }
5996
Amith Yamasani6e118872016-02-19 12:53:51 -08005997 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005998 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005999 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08006000 List<String> privilegedPackages = new ArrayList<>();
6001 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07006002 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
6003 // has UICC in that slot.
6004 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006005 if (card.hasCarrierPrivilegeRules()) {
6006 if (packages == null) {
6007 // Only check packages in user 0 for now
6008 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07006009 PackageManager.MATCH_DISABLED_COMPONENTS
6010 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09006011 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08006012 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08006013 }
6014 for (int p = packages.size() - 1; p >= 0; p--) {
6015 PackageInfo pkgInfo = packages.get(p);
6016 if (pkgInfo != null && pkgInfo.packageName != null
6017 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006018 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006019 privilegedPackages.add(pkgInfo.packageName);
6020 }
6021 }
6022 }
6023 }
6024 return privilegedPackages;
6025 }
6026
chen xuf7e9fe82019-05-09 19:31:02 -07006027 @Override
6028 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00006029 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6030
6031 final long identity = Binder.clearCallingIdentity();
6032
chen xuf7e9fe82019-05-09 19:31:02 -07006033 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006034 try {
6035 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6036 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6037 }
6038 } finally {
6039 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006040 }
6041 return privilegedPackages;
6042 }
6043
Wink Savilleb564aae2014-10-23 10:18:09 -07006044 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006045 final Phone phone = getPhone(subId);
6046 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006047 if (card == null) {
6048 loge("getIccId: No UICC");
6049 return null;
6050 }
6051 String iccId = card.getIccId();
6052 if (TextUtils.isEmpty(iccId)) {
6053 loge("getIccId: ICC ID is null or empty.");
6054 return null;
6055 }
6056 return iccId;
6057 }
6058
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006059 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006060 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6061 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006062 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006063 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006064
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006065 final long identity = Binder.clearCallingIdentity();
6066 try {
6067 final String iccId = getIccId(subId);
6068 final Phone phone = getPhone(subId);
6069 if (phone == null) {
6070 return false;
6071 }
6072 final String subscriberId = phone.getSubscriberId();
6073
6074 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006075 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006076 + subscriberId + " to " + number);
6077 }
6078
6079 if (TextUtils.isEmpty(iccId)) {
6080 return false;
6081 }
6082
6083 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6084
6085 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6086 if (alphaTag == null) {
6087 editor.remove(alphaTagPrefKey);
6088 } else {
6089 editor.putString(alphaTagPrefKey, alphaTag);
6090 }
6091
6092 // Record both the line number and IMSI for this ICCID, since we need to
6093 // track all merged IMSIs based on line number
6094 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6095 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6096 if (number == null) {
6097 editor.remove(numberPrefKey);
6098 editor.remove(subscriberPrefKey);
6099 } else {
6100 editor.putString(numberPrefKey, number);
6101 editor.putString(subscriberPrefKey, subscriberId);
6102 }
6103
6104 editor.commit();
6105 return true;
6106 } finally {
6107 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006108 }
Derek Tan7226c842014-07-02 17:42:23 -07006109 }
6110
6111 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006112 public String getLine1NumberForDisplay(int subId, String callingPackage,
6113 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006114 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006115 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006116 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006117 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006118 return null;
6119 }
Derek Tan97ebb422014-09-05 16:55:38 -07006120
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006121 final long identity = Binder.clearCallingIdentity();
6122 try {
6123 String iccId = getIccId(subId);
6124 if (iccId != null) {
6125 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6126 if (DBG_MERGE) {
6127 log("getLine1NumberForDisplay returning "
6128 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6129 }
6130 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006131 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006132 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6133 return null;
6134 } finally {
6135 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006136 }
Derek Tan7226c842014-07-02 17:42:23 -07006137 }
6138
6139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006140 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6141 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006143 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006144 return null;
6145 }
Derek Tan97ebb422014-09-05 16:55:38 -07006146
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006147 final long identity = Binder.clearCallingIdentity();
6148 try {
6149 String iccId = getIccId(subId);
6150 if (iccId != null) {
6151 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6152 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6153 }
6154 return null;
6155 } finally {
6156 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006157 }
Derek Tan7226c842014-07-02 17:42:23 -07006158 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006159
6160 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006161 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6162 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006163 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6164 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006165 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006166 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006167 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006168 return null;
6169 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006170
Jordan Liub49b04b2019-05-06 14:45:15 -07006171 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6172 // the process, where TelephonyManager was instantiated.
6173 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006174 final long identity = Binder.clearCallingIdentity();
6175 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006176 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006177 final TelephonyManager tele = TelephonyManager.from(context);
6178 final SubscriptionManager sub = SubscriptionManager.from(context);
6179
6180 // Figure out what subscribers are currently active
6181 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006182
Jordan Liub49b04b2019-05-06 14:45:15 -07006183 // Only consider subs which match the current subId
6184 // This logic can be simplified. See b/131189269 for progress.
6185 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006186 activeSubscriberIds.add(tele.getSubscriberId(subId));
6187 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188
6189 // First pass, find a number override for an active subscriber
6190 String mergeNumber = null;
6191 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6192 for (String key : prefs.keySet()) {
6193 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6194 final String subscriberId = (String) prefs.get(key);
6195 if (activeSubscriberIds.contains(subscriberId)) {
6196 final String iccId = key.substring(
6197 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6198 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6199 mergeNumber = (String) prefs.get(numberKey);
6200 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006201 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006202 + " for active subscriber " + subscriberId);
6203 }
6204 if (!TextUtils.isEmpty(mergeNumber)) {
6205 break;
6206 }
6207 }
6208 }
6209 }
6210
6211 // Shortcut when no active merged subscribers
6212 if (TextUtils.isEmpty(mergeNumber)) {
6213 return null;
6214 }
6215
6216 // Second pass, find all subscribers under that line override
6217 final ArraySet<String> result = new ArraySet<>();
6218 for (String key : prefs.keySet()) {
6219 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6220 final String number = (String) prefs.get(key);
6221 if (mergeNumber.equals(number)) {
6222 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6223 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6224 final String subscriberId = (String) prefs.get(subscriberKey);
6225 if (!TextUtils.isEmpty(subscriberId)) {
6226 result.add(subscriberId);
6227 }
6228 }
6229 }
6230 }
6231
6232 final String[] resultArray = result.toArray(new String[result.size()]);
6233 Arrays.sort(resultArray);
6234 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006235 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006236 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6237 }
6238 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006239 } finally {
6240 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006241 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006242 }
6243
6244 @Override
zoey chen38003472019-12-13 17:16:31 +08006245 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6246 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006247
6248 final long identity = Binder.clearCallingIdentity();
6249 try {
6250 final TelephonyManager telephonyManager = mApp.getSystemService(
6251 TelephonyManager.class);
6252 String subscriberId = telephonyManager.getSubscriberId(subId);
6253 if (subscriberId == null) {
6254 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006255 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006256 + subId);
6257 }
6258 return null;
6259 }
6260
6261 final SubscriptionInfo info = SubscriptionController.getInstance()
6262 .getSubscriptionInfo(subId);
6263 final ParcelUuid groupUuid = info.getGroupUuid();
6264 // If it doesn't belong to any group, return just subscriberId of itself.
6265 if (groupUuid == null) {
6266 return new String[]{subscriberId};
6267 }
6268
6269 // Get all subscriberIds from the group.
6270 final List<String> mergedSubscriberIds = new ArrayList<>();
6271 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006272 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006273 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006274 for (SubscriptionInfo subInfo : groupInfos) {
6275 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6276 if (subscriberId != null) {
6277 mergedSubscriberIds.add(subscriberId);
6278 }
6279 }
6280
6281 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6282 } finally {
6283 Binder.restoreCallingIdentity(identity);
6284
6285 }
6286 }
6287
6288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006289 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006290 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006291 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006292
6293 final long identity = Binder.clearCallingIdentity();
6294 try {
6295 final Phone phone = getPhone(subId);
6296 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6297 } finally {
6298 Binder.restoreCallingIdentity(identity);
6299 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006300 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006301
6302 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006303 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006304 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6305 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006306 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6307 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006308
6309 final long identity = Binder.clearCallingIdentity();
6310 try {
6311 final Phone phone = getPhone(subId);
6312 if (phone == null) {
6313 return false;
6314 }
6315 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6316 cdmaNonRoamingList);
6317 } finally {
6318 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006319 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006320 }
6321
6322 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006323 @Deprecated
6324 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6325 enforceModifyPermission();
6326
6327 int returnValue = 0;
6328 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006329 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006330 if(result.exception == null) {
6331 if (result.result != null) {
6332 byte[] responseData = (byte[])(result.result);
6333 if(responseData.length > oemResp.length) {
6334 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6335 responseData.length + "bytes. Buffer Size is " +
6336 oemResp.length + "bytes.");
6337 }
6338 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6339 returnValue = responseData.length;
6340 }
6341 } else {
6342 CommandException ex = (CommandException) result.exception;
6343 returnValue = ex.getCommandError().ordinal();
6344 if(returnValue > 0) returnValue *= -1;
6345 }
6346 } catch (RuntimeException e) {
6347 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6348 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6349 if(returnValue > 0) returnValue *= -1;
6350 }
6351
6352 return returnValue;
6353 }
6354
6355 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006356 public void setRadioCapability(RadioAccessFamily[] rafs) {
6357 try {
6358 ProxyController.getInstance().setRadioCapability(rafs);
6359 } catch (RuntimeException e) {
6360 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6361 }
6362 }
6363
6364 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006365 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006366 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006367 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006368 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006369 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006370 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006371 final long identity = Binder.clearCallingIdentity();
6372 try {
chen xub97461a2018-10-26 14:17:57 -07006373 TelephonyPermissions
6374 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6375 mApp, phone.getSubId(), "getRadioAccessFamily");
6376 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 } finally {
6378 Binder.restoreCallingIdentity(identity);
6379 }
chen xub97461a2018-10-26 14:17:57 -07006380 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006381 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006382
6383 @Override
6384 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006385 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006386 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006387
6388 final long identity = Binder.clearCallingIdentity();
6389 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006390 ImsManager.getInstance(defaultPhone.getContext(),
6391 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006395 }
6396
6397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006399 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6401 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006402 return false;
6403 }
Svet Ganovb320e182015-04-16 12:30:10 -07006404
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006405 final long identity = Binder.clearCallingIdentity();
6406 try {
6407 // Check the user preference and the system-level IMS setting. Even if the user has
6408 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6409 // In the long run, we may instead need to check if there exists a connection service
6410 // which can support video calling.
6411 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006412 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 return imsManager.isVtEnabledByPlatform()
6414 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6415 && imsManager.isVtEnabledByUser();
6416 } finally {
6417 Binder.restoreCallingIdentity(identity);
6418 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006419 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006420
Andrew Leea1239f22015-03-02 17:44:07 -08006421 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006422 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6423 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006424 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006425 mApp, subId, callingPackage, callingFeatureId,
6426 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006427 return false;
6428 }
6429
6430 final long identity = Binder.clearCallingIdentity();
6431 try {
6432 CarrierConfigManager configManager =
6433 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006434 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006435 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6436 } finally {
6437 Binder.restoreCallingIdentity(identity);
6438 }
Andrew Leea1239f22015-03-02 17:44:07 -08006439 }
6440
6441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006442 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006444 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006445 return false;
6446 }
6447
6448 final long identity = Binder.clearCallingIdentity();
6449 try {
6450 CarrierConfigManager configManager =
6451 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006452 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6454 } finally {
6455 Binder.restoreCallingIdentity(identity);
6456 }
Andrew Leea1239f22015-03-02 17:44:07 -08006457 }
6458
Andrew Lee9431b832015-03-09 18:46:45 -07006459 @Override
6460 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006461 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006462 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006463 }
6464
6465 @Override
6466 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 final long identity = Binder.clearCallingIdentity();
6468 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006469 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 } finally {
6471 Binder.restoreCallingIdentity(identity);
6472 }
Andrew Lee9431b832015-03-09 18:46:45 -07006473 }
6474
Hall Liuf6668912018-10-31 17:05:23 -07006475 /**
6476 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6477 * support for the feature and device firmware support.
6478 *
6479 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6480 */
6481 @Override
6482 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006483 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006484 final Phone phone = getPhone(subscriptionId);
6485 if (phone == null) {
6486 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6487 return false;
6488 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006489 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006490 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006491 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6492 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006493 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006494 return isCarrierSupported && isDeviceSupported;
6495 } finally {
6496 Binder.restoreCallingIdentity(identity);
6497 }
Hall Liu98187582018-01-22 19:15:32 -08006498 }
6499
Hall Liuf6668912018-10-31 17:05:23 -07006500 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006501 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6502 * RTT setting, will return true if the device and carrier both support RTT.
6503 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006504 */
6505 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006506 final long identity = Binder.clearCallingIdentity();
6507 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006508 boolean isRttSupported = isRttSupported(subscriptionId);
6509 boolean isUserRttSettingOn = Settings.Secure.getInt(
6510 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6511 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6512 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6513 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006514 } finally {
6515 Binder.restoreCallingIdentity(identity);
6516 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006517 }
6518
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006519 @Deprecated
6520 @Override
6521 public String getDeviceId(String callingPackage) {
6522 return getDeviceIdWithFeature(callingPackage, null);
6523 }
6524
Sanket Padawe7310cc72015-01-14 09:53:20 -08006525 /**
6526 * Returns the unique device ID of phone, for example, the IMEI for
6527 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6528 *
6529 * <p>Requires Permission:
6530 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6531 */
6532 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006533 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006534 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006535 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006536 return null;
6537 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006538 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006539 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006540 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006541 return null;
6542 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006543
6544 final long identity = Binder.clearCallingIdentity();
6545 try {
6546 return phone.getDeviceId();
6547 } finally {
6548 Binder.restoreCallingIdentity(identity);
6549 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006550 }
6551
Ping Sunc67b7c22016-03-02 19:16:45 +08006552 /**
6553 * {@hide}
6554 * Returns the IMS Registration Status on a particular subid
6555 *
6556 * @param subId
6557 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006558 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006559 Phone phone = getPhone(subId);
6560 if (phone != null) {
6561 return phone.isImsRegistered();
6562 } else {
6563 return false;
6564 }
6565 }
6566
Santos Cordon7a1885b2015-02-03 11:15:19 -08006567 @Override
6568 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006569 final long identity = Binder.clearCallingIdentity();
6570 try {
6571 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6572 } finally {
6573 Binder.restoreCallingIdentity(identity);
6574 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006575 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006576
Tyler Gunnf70ed162019-04-03 15:28:53 -07006577 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006578 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006579 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006580 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006581 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006582 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6583 }
6584 final long identity = Binder.clearCallingIdentity();
6585 try {
6586 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6587 } finally {
6588 Binder.restoreCallingIdentity(identity);
6589 }
6590 }
6591
6592 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006593 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6594 final long identity = Binder.clearCallingIdentity();
6595 try {
6596 Phone phone = getPhone(subscriptionId);
6597 if (phone == null) {
6598 return null;
6599 }
6600 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6601 } finally {
6602 Binder.restoreCallingIdentity(identity);
6603 }
6604 }
6605
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006606 /**
6607 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006608 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006609 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006610 final long identity = Binder.clearCallingIdentity();
6611 try {
6612 Phone phone = getPhone(subId);
6613 if (phone != null) {
6614 return phone.isWifiCallingEnabled();
6615 } else {
6616 return false;
6617 }
6618 } finally {
6619 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006620 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006621 }
6622
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006623 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006624 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006625 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006626 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006627 final long identity = Binder.clearCallingIdentity();
6628 try {
6629 Phone phone = getPhone(subId);
6630 if (phone != null) {
6631 return phone.isVideoEnabled();
6632 } else {
6633 return false;
6634 }
6635 } finally {
6636 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006637 }
6638 }
6639
6640 /**
6641 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6642 * defined in {@link ImsRegistrationImplBase}.
6643 */
6644 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final long identity = Binder.clearCallingIdentity();
6646 try {
6647 Phone phone = getPhone(subId);
6648 if (phone != null) {
6649 return phone.getImsRegistrationTech();
6650 } else {
6651 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6652 }
6653 } finally {
6654 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006655 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006656 }
6657
Stuart Scott8eef64f2015-04-08 15:13:54 -07006658 @Override
6659 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006660 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006661 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6662 return;
6663 }
6664
Svet Ganovcc087f82015-05-12 20:35:54 -07006665 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006666
Svet Ganovcc087f82015-05-12 20:35:54 -07006667 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006668 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6669 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006670 setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
6671 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006672 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006673 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006674 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6675 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006676 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006677 // There has been issues when Sms raw table somehow stores orphan
6678 // fragments. They lead to garbled message when new fragments come
6679 // in and combined with those stale ones. In case this happens again,
6680 // user can reset all network settings which will clean up this table.
6681 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006682 // Clean up IMS settings as well here.
6683 int slotId = getSlotIndex(subId);
6684 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6685 ImsManager.getInstance(mApp, slotId).factoryReset();
6686 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006687
6688 // Erase modem config if erase modem on network setting is enabled.
6689 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6690 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6691 if (configValue != null && Boolean.parseBoolean(configValue)) {
6692 sendEraseModemConfig(getDefaultPhone());
6693 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006694 } finally {
6695 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006696 }
6697 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006698
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006699 private void cleanUpSmsRawTable(Context context) {
6700 ContentResolver resolver = context.getContentResolver();
6701 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6702 resolver.delete(uri, null, null);
6703 }
6704
Narayan Kamath1c496c22015-04-16 14:40:19 +01006705 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006706 public String getSimLocaleForSubscriber(int subId) {
6707 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6708 final Phone phone = getPhone(subId);
6709 if (phone == null) {
6710 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006711 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006712 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713 final long identity = Binder.clearCallingIdentity();
6714 try {
chen xu5d3637b2019-01-21 23:31:38 -08006715 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006716 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006717 if (info == null) {
6718 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6719 return null;
6720 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006721 // Try and fetch the locale from the carrier properties or from the SIM language
6722 // preferences (EF-PL and EF-LI)...
6723 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006724 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006725 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6726 if (localeFromDefaultSim != null) {
6727 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6728 if (DBG) log("Using locale from subId: " + subId + " locale: "
6729 + localeFromDefaultSim);
6730 return localeFromDefaultSim.toLanguageTag();
6731 } else {
6732 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 }
6734 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006735
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006736 // The SIM language preferences only store a language (e.g. fr = French), not an
6737 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6738 // the SIM and carrier preferences does not include a country we add the country
6739 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006740 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006741 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006742 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006743 return mccLocale.toLanguageTag();
6744 }
6745
6746 if (DBG) log("No locale found - returning null");
6747 return null;
6748 } finally {
6749 Binder.restoreCallingIdentity(identity);
6750 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006751 }
6752
6753 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006754 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006755 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006756 }
6757
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006758 /**
6759 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6760 */
6761 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006762 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006763 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006764 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006765
Chenjie Yu1ba97252018-01-11 18:16:20 -08006766 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006767 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006768
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006769 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006770 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6771 * representing the state of the modem.
6772 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006773 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6774 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006775 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006776 */
6777 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006778 public void requestModemActivityInfo(ResultReceiver result) {
6779 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006780 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006781
6782 final long identity = Binder.clearCallingIdentity();
6783 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006784 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006785 } finally {
6786 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006787 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006788 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006789
Siddharth Rayb8114062018-06-17 15:02:38 -07006790 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6791 // less than total activity duration.
6792 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6793 if (info == null) {
6794 return false;
6795 }
6796 int activityDurationMs =
6797 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6798 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006799 int[] txTimeMs = info.getTransmitTimeMillis();
6800 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6801 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006802 }
6803 return (info.isValid()
6804 && (info.getSleepTimeMillis() <= activityDurationMs)
6805 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006806 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006807 && (totalTxTimeMs <= activityDurationMs));
6808 }
6809
Jack Yu85bd38a2015-11-09 11:34:32 -08006810 /**
6811 * {@hide}
6812 * Returns the service state information on specified subscription.
6813 */
6814 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006815 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6816 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006817 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006818 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006819 return null;
6820 }
6821
Hall Liuf19c44f2018-11-27 14:38:17 -08006822 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6823 LocationAccessPolicy.checkLocationPermission(mApp,
6824 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6825 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006826 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006827 .setCallingPid(Binder.getCallingPid())
6828 .setCallingUid(Binder.getCallingUid())
6829 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006830 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006831 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006832 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6833 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006834 .build());
6835
6836 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6837 LocationAccessPolicy.checkLocationPermission(mApp,
6838 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6839 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006840 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006841 .setCallingPid(Binder.getCallingPid())
6842 .setCallingUid(Binder.getCallingUid())
6843 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006844 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006845 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006846 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6847 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006848 .build());
6849 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6850 boolean hasFinePermission =
6851 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6852 boolean hasCoarsePermission =
6853 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6854
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006855 final long identity = Binder.clearCallingIdentity();
6856 try {
6857 final Phone phone = getPhone(subId);
6858 if (phone == null) {
6859 return null;
6860 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006861
Hall Liuf19c44f2018-11-27 14:38:17 -08006862 ServiceState ss = phone.getServiceState();
6863
6864 // Scrub out the location info in ServiceState depending on what level of access
6865 // the caller has.
6866 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006867 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6868 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 } finally {
6870 Binder.restoreCallingIdentity(identity);
6871 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006872 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006873
6874 /**
6875 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6876 *
6877 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6878 * voicemail ringtone.
6879 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6880 * PhoneAccount.
6881 */
6882 @Override
6883 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006884 final long identity = Binder.clearCallingIdentity();
6885 try {
6886 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6887 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006888 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006889 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006890
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006891 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6892 } finally {
6893 Binder.restoreCallingIdentity(identity);
6894 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006895 }
6896
6897 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006898 * Sets the per-account voicemail ringtone.
6899 *
6900 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6901 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6902 *
6903 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6904 * voicemail ringtone.
6905 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6906 * PhoneAccount.
6907 */
6908 @Override
6909 public void setVoicemailRingtoneUri(String callingPackage,
6910 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006911 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006912 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006913 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6914 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006915 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6916 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6917 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006918 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919
6920 final long identity = Binder.clearCallingIdentity();
6921 try {
6922 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6923 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006924 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006925 }
6926 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006929 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006930 }
6931
6932 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006933 * Returns whether vibration is set for voicemail notification in Phone settings.
6934 *
6935 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6936 * voicemail vibration setting.
6937 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6938 */
6939 @Override
6940 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006941 final long identity = Binder.clearCallingIdentity();
6942 try {
6943 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6944 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006945 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006946 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006947
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006948 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6949 } finally {
6950 Binder.restoreCallingIdentity(identity);
6951 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006952 }
6953
Youhan Wange64578a2016-05-02 15:32:42 -07006954 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006955 * Sets the per-account voicemail vibration.
6956 *
6957 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6958 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6959 *
6960 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6961 * voicemail vibration setting.
6962 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6963 * specific PhoneAccount.
6964 */
6965 @Override
6966 public void setVoicemailVibrationEnabled(String callingPackage,
6967 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006968 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006969 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006970 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6971 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006972 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6973 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6974 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006975 }
6976
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006977 final long identity = Binder.clearCallingIdentity();
6978 try {
6979 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6980 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006981 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006982 }
6983 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6984 } finally {
6985 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006986 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006987 }
6988
6989 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006990 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6991 *
6992 * @throws SecurityException if the caller does not have the required permission
6993 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006994 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006995 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006996 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006997 }
6998
6999 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007000 * Make sure either called from same process as self (phone) or IPC caller has send SMS
7001 * permission.
7002 *
7003 * @throws SecurityException if the caller does not have the required permission
7004 */
7005 private void enforceSendSmsPermission() {
7006 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
7007 }
7008
7009 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007010 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007011 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007012 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007013 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08007014 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007015 final long identity = Binder.clearCallingIdentity();
7016 try {
7017 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007018 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007019 if (componentName == null) {
7020 throw new SecurityException(
7021 "Caller not current active visual voicemail package[null]");
7022 }
7023 String vvmPackage = componentName.getPackageName();
7024 if (!callingPackage.equals(vvmPackage)) {
7025 throw new SecurityException("Caller not current active visual voicemail package["
7026 + vvmPackage + "]");
7027 }
7028 } finally {
7029 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007030 }
7031 }
7032
7033 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007034 * Return the application ID for the app type.
7035 *
7036 * @param subId the subscription ID that this request applies to.
7037 * @param appType the uicc app type.
7038 * @return Application ID for specificied app type, or null if no uicc.
7039 */
7040 @Override
7041 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007042 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007043 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007044
7045 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007046 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007047 if (phone == null) {
7048 return null;
7049 }
7050 String aid = null;
7051 try {
7052 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7053 .getApplicationByType(appType).getAid();
7054 } catch (Exception e) {
7055 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7056 }
7057 return aid;
7058 } finally {
7059 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007060 }
Youhan Wange64578a2016-05-02 15:32:42 -07007061 }
7062
Youhan Wang4001d252016-05-11 10:29:41 -07007063 /**
7064 * Return the Electronic Serial Number.
7065 *
7066 * @param subId the subscription ID that this request applies to.
7067 * @return ESN or null if error.
7068 */
7069 @Override
7070 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007071 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007072 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007073
7074 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007075 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007076 if (phone == null) {
7077 return null;
7078 }
7079 String esn = null;
7080 try {
7081 esn = phone.getEsn();
7082 } catch (Exception e) {
7083 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7084 }
7085 return esn;
7086 } finally {
7087 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007088 }
Youhan Wang4001d252016-05-11 10:29:41 -07007089 }
7090
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007091 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007092 * Return the Preferred Roaming List Version.
7093 *
7094 * @param subId the subscription ID that this request applies to.
7095 * @return PRLVersion or null if error.
7096 */
7097 @Override
7098 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007099 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007100 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007101
7102 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007103 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007104 if (phone == null) {
7105 return null;
7106 }
7107 String cdmaPrlVersion = null;
7108 try {
7109 cdmaPrlVersion = phone.getCdmaPrlVersion();
7110 } catch (Exception e) {
7111 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7112 }
7113 return cdmaPrlVersion;
7114 } finally {
7115 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007116 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007117 }
7118
7119 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007120 * Get snapshot of Telephony histograms
7121 * @return List of Telephony histograms
7122 * @hide
7123 */
7124 @Override
7125 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007126 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7127 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007128
7129 final long identity = Binder.clearCallingIdentity();
7130 try {
7131 return RIL.getTelephonyRILTimingHistograms();
7132 } finally {
7133 Binder.restoreCallingIdentity(identity);
7134 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007135 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007136
7137 /**
7138 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007139 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7140 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007141 * Require system privileges. In the future we may add this to carrier APIs.
7142 *
Michele Berionne482f8202018-11-27 18:57:59 -08007143 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007144 */
7145 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007146 @TelephonyManager.SetCarrierRestrictionResult
7147 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007148 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007149 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007150
Michele Berionne482f8202018-11-27 18:57:59 -08007151 if (carrierRestrictionRules == null) {
7152 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007153 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007154
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007155 final long identity = Binder.clearCallingIdentity();
7156 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007157 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007158 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159 } finally {
7160 Binder.restoreCallingIdentity(identity);
7161 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007162 }
7163
7164 /**
7165 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007166 * Get the allowed carrier list and the excluded carrier list, including the priority between
7167 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007168 * Require system privileges. In the future we may add this to carrier APIs.
7169 *
Michele Berionne482f8202018-11-27 18:57:59 -08007170 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007171 */
7172 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007173 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007174 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007175 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007176
7177 final long identity = Binder.clearCallingIdentity();
7178 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007179 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7180 if (response instanceof CarrierRestrictionRules) {
7181 return (CarrierRestrictionRules) response;
7182 }
7183 // Response is an Exception of some kind,
7184 // which is signalled to the user as a NULL retval
7185 return null;
7186 } catch (Exception e) {
7187 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7188 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007189 } finally {
7190 Binder.restoreCallingIdentity(identity);
7191 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007192 }
7193
fionaxu59545b42016-05-25 15:53:37 -07007194 /**
fionaxu59545b42016-05-25 15:53:37 -07007195 * Action set from carrier signalling broadcast receivers to enable/disable radio
7196 * @param subId the subscription ID that this action applies to.
7197 * @param enabled control enable or disable radio.
7198 * {@hide}
7199 */
7200 @Override
7201 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7202 enforceModifyPermission();
7203 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007204
7205 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007206 if (phone == null) {
7207 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7208 return;
7209 }
7210 try {
7211 phone.carrierActionSetRadioEnabled(enabled);
7212 } catch (Exception e) {
7213 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007214 } finally {
7215 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007216 }
7217 }
7218
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007219 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007220 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7221 * network status based on which carrier apps could apply actions accordingly,
7222 * enable/disable default url handler for example.
7223 *
7224 * @param subId the subscription ID that this action applies to.
7225 * @param report control start/stop reporting the default network status.
7226 * {@hide}
7227 */
7228 @Override
7229 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7230 enforceModifyPermission();
7231 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007232
7233 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007234 if (phone == null) {
7235 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7236 return;
7237 }
7238 try {
7239 phone.carrierActionReportDefaultNetworkStatus(report);
7240 } catch (Exception e) {
7241 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007242 } finally {
7243 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007244 }
7245 }
7246
7247 /**
fionaxud9622282017-07-17 17:51:30 -07007248 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7249 * @param subId the subscription ID that this action applies to.
7250 * {@hide}
7251 */
7252 @Override
7253 public void carrierActionResetAll(int subId) {
7254 enforceModifyPermission();
7255 final Phone phone = getPhone(subId);
7256 if (phone == null) {
7257 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7258 return;
7259 }
7260 try {
7261 phone.carrierActionResetAll();
7262 } catch (Exception e) {
7263 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7264 }
7265 }
7266
7267 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007268 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7269 * bug report is being generated.
7270 */
7271 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007272 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007273 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7274 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007275 writer.println("Permission Denial: can't dump Phone from pid="
7276 + Binder.getCallingPid()
7277 + ", uid=" + Binder.getCallingUid()
7278 + "without permission "
7279 + android.Manifest.permission.DUMP);
7280 return;
7281 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007282 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007283 }
Jack Yueb89b242016-06-22 13:27:47 -07007284
Brad Ebingerdac2f002018-04-03 15:17:52 -07007285 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007286 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7287 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7288 @NonNull String[] args) {
7289 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7290 this, in.getFileDescriptor(), out.getFileDescriptor(),
7291 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007292 }
7293
Jack Yueb89b242016-06-22 13:27:47 -07007294 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007295 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007296 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007297 * @param reason the reason the data enable change is taking place
7298 * @param enabled True if enabling the data, otherwise disabling.
7299 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007300 */
7301 @Override
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007302 public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
7303 boolean enabled) {
7304 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7305 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7306 try {
7307 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7308 mApp, subId, "setDataEnabledWithReason");
7309 } catch (SecurityException se) {
7310 enforceModifyPermission();
7311 }
7312 } else {
7313 enforceModifyPermission();
7314 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315
7316 final long identity = Binder.clearCallingIdentity();
7317 try {
7318 Phone phone = getPhone(subId);
7319 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007320 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7321 phone.carrierActionSetMeteredApnsEnabled(enabled);
7322 } else {
7323 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7324 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007325 }
7326 } finally {
7327 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007328 }
7329 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007330
7331 /**
7332 * Get Client request stats
7333 * @return List of Client Request Stats
7334 * @hide
7335 */
7336 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007337 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7338 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007339 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007340 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007341 return null;
7342 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007343 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007344
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 if (phone != null) {
7348 return phone.getClientRequestStats();
7349 }
7350
7351 return null;
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
7354 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007355 }
7356
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007357 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007358 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007359 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007360 }
Jack Yueb4124c2017-02-16 15:32:43 -08007361
7362 /**
Grace Chen70990072017-03-24 17:21:30 -07007363 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007364 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007365 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007366 * @param state State of SIM (power down, power up, pass through)
7367 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7368 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7369 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007370 *
7371 **/
7372 @Override
Grace Chen70990072017-03-24 17:21:30 -07007373 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007374 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007375 Phone phone = PhoneFactory.getPhone(slotIndex);
7376
vagdeviaf9a5b92018-08-15 16:01:53 -07007377 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7378
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007379 final long identity = Binder.clearCallingIdentity();
7380 try {
7381 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007382 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007383 }
7384 } finally {
7385 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007386 }
7387 }
Shuo Qiandd210312017-04-12 22:11:33 +00007388
Tyler Gunn65d45c22017-06-05 11:22:26 -07007389 private boolean isUssdApiAllowed(int subId) {
7390 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007391 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007392 if (configManager == null) {
7393 return false;
7394 }
7395 PersistableBundle pb = configManager.getConfigForSubId(subId);
7396 if (pb == null) {
7397 return false;
7398 }
7399 return pb.getBoolean(
7400 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7401 }
7402
Shuo Qiandd210312017-04-12 22:11:33 +00007403 /**
7404 * Check if phone is in emergency callback mode
7405 * @return true if phone is in emergency callback mode
7406 * @param subId sub id
7407 */
goneil9c5f4872017-12-05 14:07:56 -08007408 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007409 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007410 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007411 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007412
7413 final long identity = Binder.clearCallingIdentity();
7414 try {
7415 if (phone != null) {
7416 return phone.isInEcm();
7417 } else {
7418 return false;
7419 }
7420 } finally {
7421 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007422 }
7423 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007424
7425 /**
7426 * Get the current signal strength information for the given subscription.
7427 * Because this information is not updated when the device is in a low power state
7428 * it should not be relied-upon to be current.
7429 * @param subId Subscription index
7430 * @return the most recent cached signal strength info from the modem
7431 */
7432 @Override
7433 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007434 final long identity = Binder.clearCallingIdentity();
7435 try {
7436 Phone p = getPhone(subId);
7437 if (p == null) {
7438 return null;
7439 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007440
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007441 return p.getSignalStrength();
7442 } finally {
7443 Binder.restoreCallingIdentity(identity);
7444 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007445 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007446
Pengquan Meng77b7f132018-08-22 14:49:57 -07007447 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007448 * Get the current modem radio state for the given slot.
7449 * @param slotIndex slot index.
7450 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007451 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007452 * @return the current radio power state from the modem
7453 */
7454 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007455 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007456 Phone phone = PhoneFactory.getPhone(slotIndex);
7457 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007458 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7459 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007460 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7461 }
7462
7463 final long identity = Binder.clearCallingIdentity();
7464 try {
7465 return phone.getRadioPowerState();
7466 } finally {
7467 Binder.restoreCallingIdentity(identity);
7468 }
7469 }
7470 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7471 }
7472
7473 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007474 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7475 *
7476 * <p>Requires one of the following permissions:
7477 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7478 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7479 * privileges.
7480 *
7481 * @param subId subscription id
7482 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7483 * {@code false}.
7484 */
7485 @Override
7486 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007487 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7488 null /* message */);
7489
Pengquan Menga1bb6272018-09-06 09:59:22 -07007490 boolean isEnabled = false;
7491 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007492 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007493 Phone phone = getPhone(subId);
7494 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007495 } catch (Exception e) {
7496 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7497 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007498 } finally {
7499 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007500 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007501 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007502 }
7503
7504
7505 /**
7506 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7507 *
7508 * <p> Requires permission:
7509 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7510 * privileges.
7511 *
7512 * @param subId subscription id
7513 * @param isEnabled {@code true} means enable, {@code false} means disable.
7514 */
7515 @Override
7516 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007517 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7518 mApp, subId, "setDataRoamingEnabled");
7519
Pengquan Menga1bb6272018-09-06 09:59:22 -07007520 final long identity = Binder.clearCallingIdentity();
7521 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007522 Phone phone = getPhone(subId);
7523 if (phone != null) {
7524 phone.setDataRoamingEnabled(isEnabled);
7525 }
7526 } finally {
7527 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007528 }
7529 }
7530
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007531 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007532 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007533 TelephonyPermissions
7534 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007535 mApp, subId, "isManualNetworkSelectionAllowed");
7536
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007537 boolean isAllowed = true;
7538 final long identity = Binder.clearCallingIdentity();
7539 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007540 Phone phone = getPhone(subId);
7541 if (phone != null) {
7542 isAllowed = phone.isCspPlmnEnabled();
7543 }
7544 } finally {
7545 Binder.restoreCallingIdentity(identity);
7546 }
7547 return isAllowed;
7548 }
7549
7550 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007551 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007552 // Verify that tha callingPackage belongs to the calling UID
7553 mApp.getSystemService(AppOpsManager.class)
7554 .checkPackage(Binder.getCallingUid(), callingPackage);
7555
Jordan Liu1e142fc2019-04-22 15:10:43 -07007556 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007557 try {
7558 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007559 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007560 } catch (SecurityException e) {
7561 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7562 // has carrier privileges on an active UICC
7563 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7564 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007565 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007566 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007567 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007568
7569 final long identity = Binder.clearCallingIdentity();
7570 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007571 UiccController uiccController = UiccController.getInstance();
7572 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007573 if (hasReadPermission) {
7574 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007575 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007576
7577 // Remove private info if the caller doesn't have access
7578 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7579 for (UiccCardInfo cardInfo : cardInfos) {
7580 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7581 // is available
7582 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7583 if (card == null || card.getUiccProfile() == null) {
7584 // assume no access if the card or profile is unavailable
7585 filteredInfos.add(cardInfo.getUnprivileged());
7586 continue;
7587 }
7588 UiccProfile profile = card.getUiccProfile();
7589 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7590 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7591 filteredInfos.add(cardInfo);
7592 } else {
7593 filteredInfos.add(cardInfo.getUnprivileged());
7594 }
7595 }
7596 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007597 } finally {
7598 Binder.restoreCallingIdentity(identity);
7599 }
7600 }
7601
7602 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007603 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007604 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007605
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007606 final long identity = Binder.clearCallingIdentity();
7607 try {
7608 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7609 if (slots == null) {
7610 Rlog.i(LOG_TAG, "slots is null.");
7611 return null;
7612 }
7613
7614 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7615 for (int i = 0; i < slots.length; i++) {
7616 UiccSlot slot = slots[i];
7617 if (slot == null) {
7618 continue;
7619 }
7620
Jordan Liu7be7e652019-05-06 18:55:02 +00007621 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007622 UiccCard card = slot.getUiccCard();
7623 if (card != null) {
7624 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007625 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007626 cardId = slot.getEid();
7627 if (TextUtils.isEmpty(cardId)) {
7628 cardId = slot.getIccId();
7629 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007630 }
7631
Jordan Liu857451f2019-05-09 16:35:35 -07007632 if (cardId != null) {
7633 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7634 // if cardId is an EID, it's all digits so this is fine
7635 cardId = IccUtils.stripTrailingFs(cardId);
7636 }
7637
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007638 int cardState = 0;
7639 switch (slot.getCardState()) {
7640 case CARDSTATE_ABSENT:
7641 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7642 break;
7643 case CARDSTATE_PRESENT:
7644 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7645 break;
7646 case CARDSTATE_ERROR:
7647 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7648 break;
7649 case CARDSTATE_RESTRICTED:
7650 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7651 break;
7652 default:
7653 break;
7654
7655 }
7656
7657 infos[i] = new UiccSlotInfo(
7658 slot.isActive(),
7659 slot.isEuicc(),
7660 cardId,
7661 cardState,
7662 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007663 slot.isExtendedApduSupported(),
7664 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007665 }
7666 return infos;
7667 } finally {
7668 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007669 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007670 }
7671
7672 @Override
7673 public boolean switchSlots(int[] physicalSlots) {
7674 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007675
7676 final long identity = Binder.clearCallingIdentity();
7677 try {
7678 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7679 } finally {
7680 Binder.restoreCallingIdentity(identity);
7681 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007682 }
Jack Yu4c988042018-02-27 15:30:01 -08007683
7684 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007685 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007686 final long identity = Binder.clearCallingIdentity();
7687 try {
7688 return UiccController.getInstance().getCardIdForDefaultEuicc();
7689 } finally {
7690 Binder.restoreCallingIdentity(identity);
7691 }
7692 }
7693
Pengquan Meng85728fb2018-03-12 16:31:21 -07007694 /**
goneil47ffb6e2018-04-06 15:40:58 -07007695 * A test API to reload the UICC profile.
7696 *
7697 * <p>Requires that the calling app has permission
7698 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7699 * @hide
7700 */
7701 @Override
7702 public void refreshUiccProfile(int subId) {
7703 enforceModifyPermission();
7704
7705 final long identity = Binder.clearCallingIdentity();
7706 try {
7707 Phone phone = getPhone(subId);
7708 if (phone == null) {
7709 return;
7710 }
7711 UiccCard uiccCard = phone.getUiccCard();
7712 if (uiccCard == null) {
7713 return;
7714 }
7715 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7716 if (uiccProfile == null) {
7717 return;
7718 }
7719 uiccProfile.refresh();
7720 } finally {
7721 Binder.restoreCallingIdentity(identity);
7722 }
7723 }
7724
7725 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007726 * Returns false if the mobile data is disabled by default, otherwise return true.
7727 */
7728 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007729 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007730 }
7731
7732 /**
7733 * Returns true if the data roaming is enabled by default, i.e the system property
7734 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7735 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7736 */
7737 private boolean getDefaultDataRoamingEnabled(int subId) {
7738 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007739 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007740 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007741 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7742 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7743 return isDataRoamingEnabled;
7744 }
7745
7746 /**
7747 * Returns the default network type for the given {@code subId}, if the default network type is
7748 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7749 */
7750 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007751 List<Integer> list = TelephonyProperties.default_network();
7752 int phoneId = mSubscriptionController.getPhoneId(subId);
7753 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7754 return list.get(phoneId);
7755 }
7756 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007757 }
fionaxua13278b2018-03-21 00:08:13 -07007758
7759 @Override
7760 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007761 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007762 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007763
7764 final long identity = Binder.clearCallingIdentity();
7765 try {
7766 final Phone phone = getPhone(subId);
7767 if (phone == null) {
7768 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7769 return;
7770 }
chen xueaba88a2019-03-15 13:15:10 -07007771 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7772 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007773 if (carrierPrivilegeRules == null) {
7774 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7775 } else {
7776 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7777 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007778 } finally {
7779 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007780 }
fionaxua13278b2018-03-21 00:08:13 -07007781 }
7782
7783 @Override
7784 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007785 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007786
7787 final long identity = Binder.clearCallingIdentity();
7788 try {
7789 final Phone phone = getPhone(subId);
7790 if (phone == null) {
7791 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7792 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7793 }
7794 return phone.getCarrierIdListVersion();
7795 } finally {
7796 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007797 }
fionaxua13278b2018-03-21 00:08:13 -07007798 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007799
7800 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007801 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7802 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007803 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007804 mApp, subId, callingPackage, callingFeatureId,
7805 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007806 return -1;
7807 }
7808
7809 final long identity = Binder.clearCallingIdentity();
7810 try {
7811 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7812 } finally {
7813 Binder.restoreCallingIdentity(identity);
7814 }
7815 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007816
7817 @Override
7818 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007819 TelephonyPermissions
7820 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007821 mApp, subId, "getCdmaRoamingMode");
7822
7823 final long identity = Binder.clearCallingIdentity();
7824 try {
7825 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7826 } finally {
7827 Binder.restoreCallingIdentity(identity);
7828 }
7829 }
7830
7831 @Override
7832 public boolean setCdmaRoamingMode(int subId, int mode) {
7833 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7834 mApp, subId, "setCdmaRoamingMode");
7835
7836 final long identity = Binder.clearCallingIdentity();
7837 try {
7838 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7839 } finally {
7840 Binder.restoreCallingIdentity(identity);
7841 }
7842 }
7843
7844 @Override
7845 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7847 mApp, subId, "setCdmaSubscriptionMode");
7848
7849 final long identity = Binder.clearCallingIdentity();
7850 try {
7851 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7852 } finally {
7853 Binder.restoreCallingIdentity(identity);
7854 }
7855 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007856
sqianc5eccab2018-10-19 18:46:41 -07007857 @Override
sqian8c685422019-02-22 15:55:18 -08007858 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007859 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007860 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007861 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7862 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007863 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7864 }
7865 final long identity = Binder.clearCallingIdentity();
7866 try {
sqian854d44b2018-12-12 16:48:18 -08007867 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7868 for (Phone phone: PhoneFactory.getPhones()) {
7869 if (phone.getEmergencyNumberTracker() != null
7870 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7871 emergencyNumberListInternal.put(
7872 phone.getSubId(),
7873 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7874 }
sqian11b7a0e2018-12-05 18:48:28 -08007875 }
sqian854d44b2018-12-12 16:48:18 -08007876 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007877 } finally {
7878 Binder.restoreCallingIdentity(identity);
7879 }
sqianc5eccab2018-10-19 18:46:41 -07007880 }
7881
7882 @Override
sqian8c685422019-02-22 15:55:18 -08007883 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007884 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007885 if (!exactMatch) {
7886 TelephonyPermissions
7887 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007888 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007889 }
7890 final long identity = Binder.clearCallingIdentity();
7891 try {
sqian854d44b2018-12-12 16:48:18 -08007892 for (Phone phone: PhoneFactory.getPhones()) {
7893 if (phone.getEmergencyNumberTracker() != null
7894 && phone.getEmergencyNumberTracker() != null) {
7895 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7896 number, exactMatch)) {
7897 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007898 }
7899 }
sqian11b7a0e2018-12-05 18:48:28 -08007900 }
7901 return false;
7902 } finally {
7903 Binder.restoreCallingIdentity(identity);
7904 }
7905 }
7906
sqianf4ca7ed2019-01-15 18:32:07 -08007907 /**
7908 * Update emergency number list for test mode.
7909 */
7910 @Override
7911 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7912 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7913 "updateEmergencyNumberListTestMode");
7914
7915 final long identity = Binder.clearCallingIdentity();
7916 try {
7917 for (Phone phone: PhoneFactory.getPhones()) {
7918 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7919 if (tracker != null) {
7920 tracker.executeEmergencyNumberTestModeCommand(action, num);
7921 }
7922 }
7923 } finally {
7924 Binder.restoreCallingIdentity(identity);
7925 }
7926 }
7927
7928 /**
7929 * Get the full emergency number list for test mode.
7930 */
7931 @Override
7932 public List<String> getEmergencyNumberListTestMode() {
7933 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7934 "getEmergencyNumberListTestMode");
7935
7936 final long identity = Binder.clearCallingIdentity();
7937 try {
7938 Set<String> emergencyNumbers = new HashSet<>();
7939 for (Phone phone: PhoneFactory.getPhones()) {
7940 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7941 if (tracker != null) {
7942 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7943 emergencyNumbers.add(num.getNumber());
7944 }
7945 }
7946 }
7947 return new ArrayList<>(emergencyNumbers);
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
7951 }
7952
chen xud6b45bd2018-10-30 22:27:10 -07007953 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007954 public int getEmergencyNumberDbVersion(int subId) {
7955 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7956
7957 final long identity = Binder.clearCallingIdentity();
7958 try {
7959 final Phone phone = getPhone(subId);
7960 if (phone == null) {
7961 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7962 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7963 }
7964 return phone.getEmergencyNumberDbVersion();
7965 } finally {
7966 Binder.restoreCallingIdentity(identity);
7967 }
7968 }
7969
7970 @Override
7971 public void notifyOtaEmergencyNumberDbInstalled() {
7972 enforceModifyPermission();
7973
7974 final long identity = Binder.clearCallingIdentity();
7975 try {
7976 for (Phone phone: PhoneFactory.getPhones()) {
7977 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7978 if (tracker != null) {
7979 tracker.updateOtaEmergencyNumberDatabase();
7980 }
7981 }
7982 } finally {
7983 Binder.restoreCallingIdentity(identity);
7984 }
7985 }
7986
7987 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007988 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007989 enforceActiveEmergencySessionPermission();
7990
7991 final long identity = Binder.clearCallingIdentity();
7992 try {
7993 for (Phone phone: PhoneFactory.getPhones()) {
7994 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7995 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007996 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7997 }
7998 }
7999 } finally {
8000 Binder.restoreCallingIdentity(identity);
8001 }
8002 }
8003
8004 @Override
8005 public void resetOtaEmergencyNumberDbFilePath() {
8006 enforceActiveEmergencySessionPermission();
8007
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
8010 for (Phone phone: PhoneFactory.getPhones()) {
8011 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8012 if (tracker != null) {
8013 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008014 }
8015 }
8016 } finally {
8017 Binder.restoreCallingIdentity(identity);
8018 }
8019 }
8020
8021 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008022 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8023 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8024 Phone phone = getPhone(subId);
8025 if (phone == null) {
8026 return null;
8027 }
8028 final long identity = Binder.clearCallingIdentity();
8029 try {
8030 UiccProfile profile = UiccController.getInstance()
8031 .getUiccProfileForPhone(phone.getPhoneId());
8032 if (profile != null) {
8033 return profile.getCertsFromCarrierPrivilegeAccessRules();
8034 }
8035 } finally {
8036 Binder.restoreCallingIdentity(identity);
8037 }
8038 return null;
8039 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008040
8041 /**
8042 * Enable or disable a modem stack.
8043 */
8044 @Override
8045 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8046 enforceModifyPermission();
8047
8048 final long identity = Binder.clearCallingIdentity();
8049 try {
8050 Phone phone = PhoneFactory.getPhone(slotIndex);
8051 if (phone == null) {
8052 return false;
8053 } else {
8054 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8055 }
8056 } finally {
8057 Binder.restoreCallingIdentity(identity);
8058 }
8059 }
Michelecea4cf22018-12-21 15:00:11 -08008060
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008061 /**
8062 * Whether a modem stack is enabled or not.
8063 */
8064 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008065 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8066 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008067 Phone phone = PhoneFactory.getPhone(slotIndex);
8068 if (phone == null) return false;
8069
8070 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008071 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8072 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008073 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8074 }
8075
8076 final long identity = Binder.clearCallingIdentity();
8077 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008078 try {
8079 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8080 } catch (NoSuchElementException ex) {
8081 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8082 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008083 } finally {
8084 Binder.restoreCallingIdentity(identity);
8085 }
8086 }
8087
Michelecea4cf22018-12-21 15:00:11 -08008088 @Override
Michele0ea7d782019-03-19 14:58:42 -07008089 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008090 enforceModifyPermission();
8091
8092 final long identity = Binder.clearCallingIdentity();
8093 try {
8094 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008095 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008096 .commit();
8097 } finally {
8098 Binder.restoreCallingIdentity(identity);
8099 }
8100 }
8101
8102 @Override
Michele0ea7d782019-03-19 14:58:42 -07008103 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008104 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008105 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008106 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8107 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008108 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008109 }
Michelecea4cf22018-12-21 15:00:11 -08008110
8111 final long identity = Binder.clearCallingIdentity();
8112 try {
Michele0ea7d782019-03-19 14:58:42 -07008113 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008114 } finally {
8115 Binder.restoreCallingIdentity(identity);
8116 }
8117 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008118
Michele0ea7d782019-03-19 14:58:42 -07008119 @TelephonyManager.IsMultiSimSupportedResult
8120 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008121 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8122 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8123 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008124 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8125 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008126 }
8127 // Check if the hardware supports multisim functionality. If usage of multisim is not
8128 // supported by the modem, indicate that it is restricted.
8129 PhoneCapability staticCapability =
8130 mPhoneConfigurationManager.getStaticPhoneCapability();
8131 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008132 loge("isMultiSimSupportedInternal: no static configuration available");
8133 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008134 }
Sarah Chin7caee492020-02-18 20:49:02 +00008135 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008136 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8137 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008138 }
8139 // Check if support of multiple SIMs is restricted by carrier
8140 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008141 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008142 }
8143
Michele0ea7d782019-03-19 14:58:42 -07008144 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008145 }
8146
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008147 /**
8148 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008149 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8150 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8151 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008152 * @param numOfSims number of active sims we want to switch to
8153 */
8154 @Override
8155 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008156 if (numOfSims == 1) {
8157 enforceModifyPermission();
8158 } else {
8159 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8160 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8161 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008162 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008163
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008164 try {
Michele30b57b22019-03-01 12:01:14 -08008165 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008166 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008167 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8168 return;
8169 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008170 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8171 } finally {
8172 Binder.restoreCallingIdentity(identity);
8173 }
8174 }
8175
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008176 @Override
8177 public boolean isApplicationOnUicc(int subId, int appType) {
8178 enforceReadPrivilegedPermission("isApplicationOnUicc");
8179 Phone phone = getPhone(subId);
8180 if (phone == null) {
8181 return false;
8182 }
8183 final long identity = Binder.clearCallingIdentity();
8184 try {
8185 UiccCard uiccCard = phone.getUiccCard();
8186 if (uiccCard == null) {
8187 return false;
8188 }
8189 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8190 if (uiccProfile == null) {
8191 return false;
8192 }
8193 if (TelephonyManager.APPTYPE_SIM <= appType
8194 && appType <= TelephonyManager.APPTYPE_ISIM) {
8195 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8196 }
8197 return false;
8198 } finally {
8199 Binder.restoreCallingIdentity(identity);
8200 }
8201 }
8202
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008203 /**
chen xub4baa772019-04-03 10:23:41 -07008204 * Get whether making changes to modem configurations will trigger reboot.
8205 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008206 */
8207 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008208 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8209 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008210 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008211 mApp, subId, callingPackage, callingFeatureId,
8212 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008213 return false;
8214 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008215 final long identity = Binder.clearCallingIdentity();
8216 try {
8217 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8218 } finally {
8219 Binder.restoreCallingIdentity(identity);
8220 }
8221 }
8222
Nathan Harold29f5f052019-02-15 13:41:57 -08008223 private void updateModemStateMetrics() {
8224 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8225 // TODO: check the state for each modem if the api is ready.
8226 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8227 }
8228
Pengquan Meng3889a572019-01-23 11:16:29 -08008229 @Override
8230 public int[] getSlotsMapping() {
8231 enforceReadPrivilegedPermission("getSlotsMapping");
8232
8233 final long identity = Binder.clearCallingIdentity();
8234 try {
8235 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8236 // All logical slots should have a mapping to a physical slot.
8237 int[] logicalSlotsMapping = new int[phoneCount];
8238 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8239 for (int i = 0; i < slotInfos.length; i++) {
8240 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8241 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8242 }
8243 }
8244 return logicalSlotsMapping;
8245 } finally {
8246 Binder.restoreCallingIdentity(identity);
8247 }
8248 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008249
8250 /**
8251 * Get the IRadio HAL Version
8252 */
8253 @Override
8254 public int getRadioHalVersion() {
8255 Phone phone = getDefaultPhone();
8256 if (phone == null) return -1;
8257 HalVersion hv = phone.getHalVersion();
8258 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8259 return hv.major * 100 + hv.minor;
8260 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008261
8262 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008263 * Get the current calling package name.
8264 * @return the current calling package name
8265 */
8266 @Override
8267 public String getCurrentPackageName() {
8268 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8269 }
8270
8271 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008272 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8273 * corresponding network requests on a subId.
8274 *
8275 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008276 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008277 * 2) APN is un-metered for this subscription, or
8278 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008279 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008280 *
8281 * @return whether data is allowed for a apn type.
8282 *
8283 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008284 */
8285 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008286 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008287 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8288 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008289
8290 // Now that all security checks passes, perform the operation as ourselves.
8291 final long identity = Binder.clearCallingIdentity();
8292 try {
8293 Phone phone = getPhone(subId);
8294 if (phone == null) return false;
8295
Jack Yu41407ee2019-05-13 16:54:09 -07008296 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008297 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8298 } finally {
8299 Binder.restoreCallingIdentity(identity);
8300 }
8301 }
8302
8303 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008304 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008305 enforceReadPrivilegedPermission("isApnMetered");
8306
8307 // Now that all security checks passes, perform the operation as ourselves.
8308 final long identity = Binder.clearCallingIdentity();
8309 try {
8310 Phone phone = getPhone(subId);
8311 if (phone == null) return true; // By default return true.
8312
Jack Yu41407ee2019-05-13 16:54:09 -07008313 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008314 } finally {
8315 Binder.restoreCallingIdentity(identity);
8316 }
8317 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008318
8319 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008320 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8321 int subscriptionId, IBooleanConsumer resultCallback) {
8322 enforceModifyPermission();
8323 long token = Binder.clearCallingIdentity();
8324 try {
8325 Phone phone = getPhone(subscriptionId);
8326 if (phone == null) {
8327 try {
8328 if (resultCallback != null) {
8329 resultCallback.accept(false);
8330 }
8331 } catch (RemoteException e) {
8332 // ignore
8333 }
8334 return;
8335 }
8336 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8337 Pair.create(specifiers, (x) -> {
8338 try {
8339 if (resultCallback != null) {
8340 resultCallback.accept(x);
8341 }
8342 } catch (RemoteException e) {
8343 // ignore
8344 }
8345 });
8346 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8347 } finally {
8348 Binder.restoreCallingIdentity(token);
8349 }
8350 }
8351
8352 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008353 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008354 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008355 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8356 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8357 if (iccRecords == null) {
8358 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8359 return false;
8360 }
8361 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8362 }
8363
8364 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008365 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8366 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008367 if (callingPackage == null) {
8368 callingPackage = getCurrentPackageName();
8369 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008370 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8371 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008372 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8373 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008374 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8375 }
8376 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8377 Intent intent = new Intent();
8378 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8379 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8380 // Bring up choose default SMS subscription dialog right now
8381 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8382 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8383 mApp.startActivity(intent);
8384 }
chen xud5ca2d52019-05-28 15:20:57 -07008385
8386 @Override
8387 public String getMmsUAProfUrl(int subId) {
8388 //TODO investigate if this API should require proper permission check in R b/133791609
8389 final long identity = Binder.clearCallingIdentity();
8390 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008391 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8392 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008393 } finally {
8394 Binder.restoreCallingIdentity(identity);
8395 }
8396 }
8397
8398 @Override
8399 public String getMmsUserAgent(int subId) {
8400 //TODO investigate if this API should require proper permission check in R b/133791609
8401 final long identity = Binder.clearCallingIdentity();
8402 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008403 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8404 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008405 } finally {
8406 Binder.restoreCallingIdentity(identity);
8407 }
8408 }
Jack Yub07d4972019-05-28 16:12:25 -07008409
8410 @Override
8411 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8412 enforceModifyPermission();
8413
8414 // Now that all security checks passes, perform the operation as ourselves.
8415 final long identity = Binder.clearCallingIdentity();
8416 try {
8417 Phone phone = getPhone(subId);
8418 if (phone == null) return false;
8419
8420 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8421 } finally {
8422 Binder.restoreCallingIdentity(identity);
8423 }
8424 }
8425
8426 @Override
8427 public boolean isDataAllowedInVoiceCall(int subId) {
8428 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8429
8430 // Now that all security checks passes, perform the operation as ourselves.
8431 final long identity = Binder.clearCallingIdentity();
8432 try {
8433 Phone phone = getPhone(subId);
8434 if (phone == null) return false;
8435
8436 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8437 } finally {
8438 Binder.restoreCallingIdentity(identity);
8439 }
8440 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008441
changbettyd5c246e2019-12-24 15:40:37 +08008442 @Override
8443 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8444 enforceModifyPermission();
8445
8446 // Now that all security checks passes, perform the operation as ourselves.
8447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 Phone phone = getPhone(subId);
8450 if (phone == null) return false;
8451
8452 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8453 } finally {
8454 Binder.restoreCallingIdentity(identity);
8455 }
8456 }
8457
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008458 /**
8459 * Updates whether conference event pacakge handling is enabled.
8460 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8461 * otherwise.
8462 */
8463 @Override
8464 public void setCepEnabled(boolean isCepEnabled) {
8465 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8466
8467 final long identity = Binder.clearCallingIdentity();
8468 try {
8469 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8470 for (Phone phone : PhoneFactory.getPhones()) {
8471 Phone defaultPhone = phone.getImsPhone();
8472 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8473 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8474 ImsPhoneCallTracker imsPhoneCallTracker =
8475 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8476 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8477 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8478 + imsPhone.getMsisdn());
8479 }
8480 }
8481 } finally {
8482 Binder.restoreCallingIdentity(identity);
8483 }
8484 }
allenwtsu46dcc572020-01-08 18:24:03 +08008485
8486 /**
8487 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8488 *
8489 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8490 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8491 * before being read.
8492 */
8493 @Override
8494 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8495 isCompressed) {
8496 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8497 mApp, subId, "notifyRcsAutoConfigurationReceived");
8498 try {
8499 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8500 if (configBinder == null) {
8501 Rlog.e(LOG_TAG, "null result for getImsConfig");
8502 } else {
8503 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8504 }
8505 } catch (RemoteException e) {
8506 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8507 }
8508 }
zoey chene02881a2019-12-30 16:11:23 +08008509
8510 @Override
8511 public boolean isIccLockEnabled(int subId) {
8512 enforceReadPrivilegedPermission("isIccLockEnabled");
8513
8514 // Now that all security checks passes, perform the operation as ourselves.
8515 final long identity = Binder.clearCallingIdentity();
8516 try {
8517 Phone phone = getPhone(subId);
8518 if (phone != null && phone.getIccCard() != null) {
8519 return phone.getIccCard().getIccLockEnabled();
8520 } else {
8521 return false;
8522 }
8523 } finally {
8524 Binder.restoreCallingIdentity(identity);
8525 }
8526 }
8527
8528 /**
8529 * Set the ICC pin lock enabled or disabled.
8530 *
8531 * @return an integer representing the status of IccLock enabled or disabled in the following
8532 * three cases:
8533 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8534 * successfully.
8535 * - Positive number and zero for remaining password attempts.
8536 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8537 *
8538 */
8539 @Override
8540 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8541 enforceModifyPermission();
8542
8543 Phone phone = getPhone(subId);
8544 if (phone == null) {
8545 return 0;
8546 }
8547 // Now that all security checks passes, perform the operation as ourselves.
8548 final long identity = Binder.clearCallingIdentity();
8549 try {
8550 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8551 new Pair<Boolean, String>(enabled, password), phone, null);
8552 return attemptsRemaining;
8553
8554 } catch (Exception e) {
8555 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8556 } finally {
8557 Binder.restoreCallingIdentity(identity);
8558 }
8559 return 0;
8560 }
8561
8562 /**
8563 * Change the ICC password used in ICC pin lock.
8564 *
8565 * @return an integer representing the status of IccLock changed in the following three cases:
8566 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8567 * - Positive number and zero for remaining password attempts.
8568 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8569 *
8570 */
8571 @Override
8572 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8573 enforceModifyPermission();
8574
8575 Phone phone = getPhone(subId);
8576 if (phone == null) {
8577 return 0;
8578 }
8579 // Now that all security checks passes, perform the operation as ourselves.
8580 final long identity = Binder.clearCallingIdentity();
8581 try {
8582 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8583 new Pair<String, String>(oldPassword, newPassword), phone, null);
8584 return attemptsRemaining;
8585
8586 } catch (Exception e) {
8587 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8588 } finally {
8589 Binder.restoreCallingIdentity(identity);
8590 }
8591 return 0;
8592 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008593
8594 /**
8595 * Request for receiving user activity notification
8596 */
8597 @Override
8598 public void requestUserActivityNotification() {
8599 if (!mNotifyUserActivity.get()
8600 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8601 mNotifyUserActivity.set(true);
8602 }
8603 }
8604
8605 /**
8606 * Called when userActivity is signalled in the power manager.
8607 * This is safe to call from any thread, with any window manager locks held or not.
8608 */
8609 @Override
8610 public void userActivity() {
8611 // ***************************************
8612 // * Inherited from PhoneWindowManager *
8613 // ***************************************
8614 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8615 // WITH ITS LOCKS HELD.
8616 //
8617 // This code must be VERY careful about the locks
8618 // it acquires.
8619 // In fact, the current code acquires way too many,
8620 // and probably has lurking deadlocks.
8621
8622 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8623 throw new SecurityException("Only the OS may call notifyUserActivity()");
8624 }
8625
8626 if (mNotifyUserActivity.getAndSet(false)) {
8627 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8628 USER_ACTIVITY_NOTIFICATION_DELAY);
8629 }
8630 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008631
8632 @Override
8633 public boolean canConnectTo5GInDsdsMode() {
8634 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8635 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008636}