blob: 13f7dad7c975a8d30c61c60726a27d119c6f8846 [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
Shuo Qian02dc2152021-02-22 18:32:21 -080021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_CDMA;
22import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_GSM;
Tyler Gunn7bcdc742019-10-04 15:56:59 -070023import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070024import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
25
Ta-wei Yen30a69c82016-12-27 14:52:32 -080026import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080027import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070028import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080030import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070031import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070032import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070033import android.content.Context;
34import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070035import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070036import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070037import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080038import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070039import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040import android.net.Uri;
41import android.os.AsyncResult;
42import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080043import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070044import android.os.Bundle;
45import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070046import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070047import android.os.Looper;
48import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070049import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080050import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070051import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070052import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080053import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080054import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070055import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070056import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070057import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070058import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070059import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070060import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070061import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080062import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070063import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090064import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080065import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080066import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070067import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070068import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080069import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070070import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080071import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070072import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080073import android.telephony.CellIdentityCdma;
74import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070075import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070076import android.telephony.CellInfoGsm;
77import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070078import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070079import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070080import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080081import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070082import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080083import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070084import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080085import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080086import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070087import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080088import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080090import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080091import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080092import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080093import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070094import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070095import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080096import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080097import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000098import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070099import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -0700100import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -0800101import android.telephony.data.ApnSetting;
102import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700103import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800104import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700105import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700106import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700108import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800109import android.telephony.ims.aidl.IImsMmTelFeature;
110import android.telephony.ims.aidl.IImsRcsFeature;
111import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700112import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700113import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800115import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800116import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800117import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800119import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700120import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700121import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800122import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800123
Andrew Lee312e8172014-10-23 17:01:36 -0700124import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800125import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800126import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700127import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700128import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700129import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800130import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700131import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700132import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800133import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700134import com.android.internal.telephony.DefaultPhoneNotifier;
Shuo Qian02dc2152021-02-22 18:32:21 -0800135import com.android.internal.telephony.GsmCdmaPhone;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800136import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800137import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700138import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800139import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700140import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800141import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700142import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700143import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700144import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700145import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700146import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800147import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700148import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700149import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700150import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700151import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700152import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700153import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700154import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700155import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800156import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800157import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800158import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700159import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800160import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700161import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800162import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700163import com.android.internal.telephony.imsphone.ImsPhone;
164import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800165import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700166import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700167import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800168import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700169import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800170import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700171import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800172import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700173import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800174import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000175import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800176import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700177import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800178import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700179import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700180import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800181import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700182import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700183import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800184import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800185
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700186import java.io.FileDescriptor;
187import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700188import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800189import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800190import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800191import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800192import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100193import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800194import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700195import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800196import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800197import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800198import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700199
200/**
201 * Implementation of the ITelephony interface.
202 */
Santos Cordon117fee72014-05-16 17:56:12 -0700203public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700204 private static final String LOG_TAG = "PhoneInterfaceManager";
205 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
206 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800207 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700208
209 // Message codes used with mMainThreadHandler
210 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700211 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
212 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700213 private static final int CMD_OPEN_CHANNEL = 9;
214 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
215 private static final int CMD_CLOSE_CHANNEL = 11;
216 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800217 private static final int CMD_NV_READ_ITEM = 13;
218 private static final int EVENT_NV_READ_ITEM_DONE = 14;
219 private static final int CMD_NV_WRITE_ITEM = 15;
220 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
221 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
222 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700223 private static final int CMD_RESET_MODEM_CONFIG = 19;
224 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800225 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
226 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
227 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
228 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800229 private static final int CMD_SEND_ENVELOPE = 25;
230 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000231 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
232 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700233 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
234 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
235 private static final int CMD_EXCHANGE_SIM_IO = 31;
236 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800237 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
238 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700239 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
240 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700241 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
242 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700243 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
244 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
245 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
246 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700247 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
248 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
249 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
250 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700251 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800252 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
253 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000254 private static final int CMD_SWITCH_SLOTS = 50;
255 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700256 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
257 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
258 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
259 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
260 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
261 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
262 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
263 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700264 private static final int CMD_GET_ALL_CELL_INFO = 60;
265 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
266 private static final int CMD_GET_CELL_LOCATION = 62;
267 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700268 private static final int CMD_MODEM_REBOOT = 64;
269 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700270 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
271 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800272 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
273 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700274 private static final int CMD_GET_MODEM_STATUS = 70;
275 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700276 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
277 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700278 private static final int CMD_ERASE_MODEM_CONFIG = 74;
279 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800280 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
281 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
282 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
283 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800284 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
285 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800286 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800287 private static final int CMD_GET_CALL_FORWARDING = 83;
288 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
289 private static final int CMD_SET_CALL_FORWARDING = 85;
290 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
291 private static final int CMD_GET_CALL_WAITING = 87;
292 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
293 private static final int CMD_SET_CALL_WAITING = 89;
294 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700295
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800296 // Parameters of select command.
297 private static final int SELECT_COMMAND = 0xA4;
298 private static final int SELECT_P1 = 0x04;
299 private static final int SELECT_P2 = 0;
300 private static final int SELECT_P3 = 0x10;
301
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700302 /** The singleton instance. */
303 private static PhoneInterfaceManager sInstance;
304
Wink Saville3ab207e2014-11-20 13:07:20 -0800305 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800307 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700308 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private AppOpsManager mAppOps;
310 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800311 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800312 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700313 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700314
Peter Wangdafb9ac2020-01-15 14:13:38 -0800315 /** User Activity */
316 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800317 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
318
Derek Tan97ebb422014-09-05 16:55:38 -0700319 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
320 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800321 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800322 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700323
Michelecea4cf22018-12-21 15:00:11 -0800324 // String to store multi SIM allowed
325 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
326
Derek Tan740e1672017-06-27 14:56:27 -0700327 // The AID of ISD-R.
328 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
329
yinxub1bed742017-04-17 11:45:04 -0700330 private NetworkScanRequestTracker mNetworkScanRequestTracker;
331
David Kelly5e06a7f2018-03-12 14:10:59 +0000332 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
333 private static final int MANUFACTURER_CODE_LENGTH = 8;
334
Derek Tan89e89d42014-07-08 17:00:10 -0700335 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700336 * Experiment flag to enable erase modem config on reset network, default value is false
337 */
338 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
339 "reset_network_erase_modem_config_enabled";
340
341 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700342 * A request object to use for transmitting data to an ICC.
343 */
344 private static final class IccAPDUArgument {
345 public int channel, cla, command, p1, p2, p3;
346 public String data;
347
348 public IccAPDUArgument(int channel, int cla, int command,
349 int p1, int p2, int p3, String data) {
350 this.channel = channel;
351 this.cla = cla;
352 this.command = command;
353 this.p1 = p1;
354 this.p2 = p2;
355 this.p3 = p3;
356 this.data = data;
357 }
358 }
359
360 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700361 * A request object to use for transmitting data to an ICC.
362 */
363 private static final class ManualNetworkSelectionArgument {
364 public OperatorInfo operatorInfo;
365 public boolean persistSelection;
366
367 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
368 this.operatorInfo = operatorInfo;
369 this.persistSelection = persistSelection;
370 }
371 }
372
373 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700374 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
375 * request after sending. The main thread will notify the request when it is complete.
376 */
377 private static final class MainThreadRequest {
378 /** The argument to use for the request */
379 public Object argument;
380 /** The result of the request that is run on the main thread */
381 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800382 // The subscriber id that this request applies to. Defaults to
383 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
384 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700385
Nathan Harold92bed182018-10-12 18:16:49 -0700386 // In cases where subId is unavailable, the caller needs to specify the phone.
387 public Phone phone;
388
vagdeviaf9a5b92018-08-15 16:01:53 -0700389 public WorkSource workSource;
390
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700391 public MainThreadRequest(Object argument) {
392 this.argument = argument;
393 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800394
Nathan Harold92bed182018-10-12 18:16:49 -0700395 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
396 this.argument = argument;
397 if (phone != null) {
398 this.phone = phone;
399 }
400 this.workSource = workSource;
401 }
402
vagdeviaf9a5b92018-08-15 16:01:53 -0700403 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800404 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800405 if (subId != null) {
406 this.subId = subId;
407 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700408 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800409 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700410 }
411
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800412 private static final class IncomingThirdPartyCallArgs {
413 public final ComponentName component;
414 public final String callId;
415 public final String callerDisplayName;
416
417 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
418 String callerDisplayName) {
419 this.component = component;
420 this.callId = callId;
421 this.callerDisplayName = callerDisplayName;
422 }
423 }
424
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700425 /**
426 * A handler that processes messages on the main thread in the phone process. Since many
427 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
428 * inbound binder threads to the main thread in the phone process. The Binder thread
429 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
430 * on, which will be notified when the operation completes and will contain the result of the
431 * request.
432 *
433 * <p>If a MainThreadRequest object is provided in the msg.obj field,
434 * note that request.result must be set to something non-null for the calling thread to
435 * unblock.
436 */
437 private final class MainThreadHandler extends Handler {
438 @Override
439 public void handleMessage(Message msg) {
440 MainThreadRequest request;
441 Message onCompleted;
442 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800443 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700444 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800445 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700446
447 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700448 case CMD_HANDLE_USSD_REQUEST: {
449 request = (MainThreadRequest) msg.obj;
450 final Phone phone = getPhoneFromRequest(request);
451 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
452 String ussdRequest = ussdObject.first;
453 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700454
Pengquan Menga1bb6272018-09-06 09:59:22 -0700455 if (!isUssdApiAllowed(request.subId)) {
456 // Carrier does not support use of this API, return failure.
457 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
458 UssdResponse response = new UssdResponse(ussdRequest, null);
459 Bundle returnData = new Bundle();
460 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
461 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700462
Pengquan Menga1bb6272018-09-06 09:59:22 -0700463 request.result = true;
464 notifyRequester(request);
465 return;
466 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700467
Pengquan Menga1bb6272018-09-06 09:59:22 -0700468 try {
469 request.result = phone != null
470 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
471 } catch (CallStateException cse) {
472 request.result = false;
473 }
474 // Wake up the requesting thread
475 notifyRequester(request);
476 break;
pkanwar32d516d2016-10-14 19:37:38 -0700477 }
478
Yorke Lee716f67e2015-06-17 15:39:16 -0700479 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700480 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700481 final Phone phone = getPhoneFromRequest(request);
482 request.result = phone != null ?
483 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
484 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700485 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700486 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700487 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700488 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700489
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700490 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700491 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700492 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800493 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700494 if (uiccCard == null) {
495 loge("iccTransmitApduLogicalChannel: No UICC");
496 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700497 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
500 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700501 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700502 iccArgument.channel, iccArgument.cla, iccArgument.command,
503 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700504 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700505 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 break;
507
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700508 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700509 ar = (AsyncResult) msg.obj;
510 request = (MainThreadRequest) ar.userObj;
511 if (ar.exception == null && ar.result != null) {
512 request.result = ar.result;
513 } else {
514 request.result = new IccIoResult(0x6F, 0, (byte[])null);
515 if (ar.result == null) {
516 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800517 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700518 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800519 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700520 } else {
521 loge("iccTransmitApduLogicalChannel: Unknown exception");
522 }
523 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700524 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700525 break;
526
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700527 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
528 request = (MainThreadRequest) msg.obj;
529 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800530 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700531 if (uiccCard == null) {
532 loge("iccTransmitApduBasicChannel: No UICC");
533 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700534 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700535 } else {
536 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
537 request);
538 uiccCard.iccTransmitApduBasicChannel(
539 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
540 iccArgument.p3, iccArgument.data, onCompleted);
541 }
542 break;
543
544 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
545 ar = (AsyncResult) msg.obj;
546 request = (MainThreadRequest) ar.userObj;
547 if (ar.exception == null && ar.result != null) {
548 request.result = ar.result;
549 } else {
550 request.result = new IccIoResult(0x6F, 0, (byte[])null);
551 if (ar.result == null) {
552 loge("iccTransmitApduBasicChannel: Empty response");
553 } else if (ar.exception instanceof CommandException) {
554 loge("iccTransmitApduBasicChannel: CommandException: " +
555 ar.exception);
556 } else {
557 loge("iccTransmitApduBasicChannel: Unknown exception");
558 }
559 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700560 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700561 break;
562
563 case CMD_EXCHANGE_SIM_IO:
564 request = (MainThreadRequest) msg.obj;
565 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800566 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700567 if (uiccCard == null) {
568 loge("iccExchangeSimIO: No UICC");
569 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700570 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700571 } else {
572 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
573 request);
574 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
575 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
576 iccArgument.data, onCompleted);
577 }
578 break;
579
580 case EVENT_EXCHANGE_SIM_IO_DONE:
581 ar = (AsyncResult) msg.obj;
582 request = (MainThreadRequest) ar.userObj;
583 if (ar.exception == null && ar.result != null) {
584 request.result = ar.result;
585 } else {
586 request.result = new IccIoResult(0x6f, 0, (byte[])null);
587 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700588 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700589 break;
590
Derek Tan4d5e5c12014-02-04 11:54:58 -0800591 case CMD_SEND_ENVELOPE:
592 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800593 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700594 if (uiccCard == null) {
595 loge("sendEnvelopeWithStatus: No UICC");
596 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700597 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700598 } else {
599 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
600 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
601 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800602 break;
603
604 case EVENT_SEND_ENVELOPE_DONE:
605 ar = (AsyncResult) msg.obj;
606 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 if (ar.exception == null && ar.result != null) {
608 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800609 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700610 request.result = new IccIoResult(0x6F, 0, (byte[])null);
611 if (ar.result == null) {
612 loge("sendEnvelopeWithStatus: Empty response");
613 } else if (ar.exception instanceof CommandException) {
614 loge("sendEnvelopeWithStatus: CommandException: " +
615 ar.exception);
616 } else {
617 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
618 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800619 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700620 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800621 break;
622
Shishir Agrawal566b7612013-10-28 14:41:00 -0700623 case CMD_OPEN_CHANNEL:
624 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800625 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800626 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700627 if (uiccCard == null) {
628 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800629 request.result = new IccOpenLogicalChannelResponse(-1,
630 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700631 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700632 } else {
633 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800634 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
635 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700636 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700637 break;
638
639 case EVENT_OPEN_CHANNEL_DONE:
640 ar = (AsyncResult) msg.obj;
641 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700642 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700643 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700644 int[] result = (int[]) ar.result;
645 int channelId = result[0];
646 byte[] selectResponse = null;
647 if (result.length > 1) {
648 selectResponse = new byte[result.length - 1];
649 for (int i = 1; i < result.length; ++i) {
650 selectResponse[i - 1] = (byte) result[i];
651 }
652 }
653 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700654 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700656 if (ar.result == null) {
657 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700658 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700659 if (ar.exception != null) {
660 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
661 }
662
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700663 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700664 if (ar.exception instanceof CommandException) {
665 CommandException.Error error =
666 ((CommandException) (ar.exception)).getCommandError();
667 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700668 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700669 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700670 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700671 }
672 }
673 openChannelResp = new IccOpenLogicalChannelResponse(
674 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700676 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700677 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700678 break;
679
680 case CMD_CLOSE_CHANNEL:
681 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800682 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700683 if (uiccCard == null) {
684 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900685 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700686 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700687 } else {
688 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
689 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
690 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700691 break;
692
693 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800694 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
695 break;
696
697 case CMD_NV_READ_ITEM:
698 request = (MainThreadRequest) msg.obj;
699 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800700 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
701 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800702 break;
703
704 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700705 ar = (AsyncResult) msg.obj;
706 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800707 if (ar.exception == null && ar.result != null) {
708 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700709 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800710 request.result = "";
711 if (ar.result == null) {
712 loge("nvReadItem: Empty response");
713 } else if (ar.exception instanceof CommandException) {
714 loge("nvReadItem: CommandException: " +
715 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700716 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800717 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 }
719 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700720 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700721 break;
722
Jake Hambye994d462014-02-03 13:10:13 -0800723 case CMD_NV_WRITE_ITEM:
724 request = (MainThreadRequest) msg.obj;
725 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
726 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800727 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700728 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800729 break;
730
731 case EVENT_NV_WRITE_ITEM_DONE:
732 handleNullReturnEvent(msg, "nvWriteItem");
733 break;
734
735 case CMD_NV_WRITE_CDMA_PRL:
736 request = (MainThreadRequest) msg.obj;
737 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800738 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800739 break;
740
741 case EVENT_NV_WRITE_CDMA_PRL_DONE:
742 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
743 break;
744
chen xu6dac5ab2018-10-26 17:39:23 -0700745 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800746 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700747 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800748 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800749 break;
750
chen xu6dac5ab2018-10-26 17:39:23 -0700751 case EVENT_RESET_MODEM_CONFIG_DONE:
752 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800753 break;
754
Jake Hamby7c27be32014-03-03 13:25:59 -0800755 case CMD_GET_PREFERRED_NETWORK_TYPE:
756 request = (MainThreadRequest) msg.obj;
757 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700758 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800759 break;
760
761 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
762 ar = (AsyncResult) msg.obj;
763 request = (MainThreadRequest) ar.userObj;
764 if (ar.exception == null && ar.result != null) {
765 request.result = ar.result; // Integer
766 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800767 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800768 if (ar.result == null) {
769 loge("getPreferredNetworkType: Empty response");
770 } else if (ar.exception instanceof CommandException) {
771 loge("getPreferredNetworkType: CommandException: " +
772 ar.exception);
773 } else {
774 loge("getPreferredNetworkType: Unknown exception");
775 }
776 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700777 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800778 break;
779
780 case CMD_SET_PREFERRED_NETWORK_TYPE:
781 request = (MainThreadRequest) msg.obj;
782 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
783 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700784 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800785 break;
786
787 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
788 handleNullReturnEvent(msg, "setPreferredNetworkType");
789 break;
790
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000791 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
792 request = (MainThreadRequest)msg.obj;
793 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800794 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000795 break;
796
797 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
798 ar = (AsyncResult)msg.obj;
799 request = (MainThreadRequest)ar.userObj;
800 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700801 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000802 break;
803
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800804 case CMD_SET_VOICEMAIL_NUMBER:
805 request = (MainThreadRequest) msg.obj;
806 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
807 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800808 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
809 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800810 break;
811
812 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
813 handleNullReturnEvent(msg, "setVoicemailNumber");
814 break;
815
Stuart Scott54788802015-03-30 13:18:01 -0700816 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
817 request = (MainThreadRequest) msg.obj;
818 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
819 request);
820 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
821 break;
822
823 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
824 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
825 break;
826
Shishir Agrawal302c8692015-06-19 13:49:39 -0700827 case CMD_PERFORM_NETWORK_SCAN:
828 request = (MainThreadRequest) msg.obj;
829 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
830 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
831 break;
832
Shuo Qian4a594052020-01-23 11:59:30 -0800833 case CMD_GET_CALL_FORWARDING:
834 request = (MainThreadRequest) msg.obj;
835 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
836 int callForwardingReason = (Integer) request.argument;
837 getPhoneFromRequest(request).getCallForwardingOption(
838 callForwardingReason, onCompleted);
839 break;
840
841 case EVENT_GET_CALL_FORWARDING_DONE:
842 ar = (AsyncResult) msg.obj;
843 request = (MainThreadRequest) ar.userObj;
844 CallForwardingInfo callForwardingInfo = null;
845 if (ar.exception == null && ar.result != null) {
846 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
847 for (CallForwardInfo callForwardInfo : callForwardInfos) {
848 // Service Class is a bit mask per 3gpp 27.007. Search for
849 // any service for voice call.
850 if ((callForwardInfo.serviceClass
851 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
852 callForwardingInfo = new CallForwardingInfo(
853 callForwardInfo.serviceClass, callForwardInfo.reason,
854 callForwardInfo.number,
855 callForwardInfo.timeSeconds);
856 break;
857 }
858 }
859 // Didn't find a call forward info for voice call.
860 if (callForwardingInfo == null) {
861 callForwardingInfo = new CallForwardingInfo(
862 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
863 0 /* reason */, null /* number */, 0 /* timeout */);
864 }
865 } else {
866 if (ar.result == null) {
867 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
868 }
869 if (ar.exception != null) {
870 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
871 }
872 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
873 if (ar.exception instanceof CommandException) {
874 CommandException.Error error =
875 ((CommandException) (ar.exception)).getCommandError();
876 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
877 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
878 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
879 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
880 }
881 }
882 callForwardingInfo = new CallForwardingInfo(
883 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
884 }
885 request.result = callForwardingInfo;
886 notifyRequester(request);
887 break;
888
889 case CMD_SET_CALL_FORWARDING:
890 request = (MainThreadRequest) msg.obj;
891 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
892 CallForwardingInfo callForwardingInfoToSet =
893 (CallForwardingInfo) request.argument;
894 getPhoneFromRequest(request).setCallForwardingOption(
895 callForwardingInfoToSet.getStatus(),
896 callForwardingInfoToSet.getReason(),
897 callForwardingInfoToSet.getNumber(),
898 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
899 break;
900
901 case EVENT_SET_CALL_FORWARDING_DONE:
902 ar = (AsyncResult) msg.obj;
903 request = (MainThreadRequest) ar.userObj;
904 if (ar.exception == null) {
905 request.result = true;
906 } else {
907 request.result = false;
908 loge("setCallForwarding exception: " + ar.exception);
909 }
910 notifyRequester(request);
911 break;
912
913 case CMD_GET_CALL_WAITING:
914 request = (MainThreadRequest) msg.obj;
915 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
916 getPhoneFromRequest(request).getCallWaiting(onCompleted);
917 break;
918
919 case EVENT_GET_CALL_WAITING_DONE:
920 ar = (AsyncResult) msg.obj;
921 request = (MainThreadRequest) ar.userObj;
922 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
923 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800924 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800925 // Service Class is a bit mask per 3gpp 27.007.
926 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800927 if (callForwardResults.length > 1
928 && ((callForwardResults[1]
929 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
930 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800931 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
932 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
933 } else {
934 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
935 }
936 } else {
937 if (ar.result == null) {
938 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
939 }
940 if (ar.exception != null) {
941 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
942 }
943 if (ar.exception instanceof CommandException) {
944 CommandException.Error error =
945 ((CommandException) (ar.exception)).getCommandError();
946 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
947 callForwardingStatus =
948 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
949 }
950 }
951 }
952 request.result = callForwardingStatus;
953 notifyRequester(request);
954 break;
955
956 case CMD_SET_CALL_WAITING:
957 request = (MainThreadRequest) msg.obj;
958 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
959 boolean isEnable = (Boolean) request.argument;
960 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
961 break;
962
963 case EVENT_SET_CALL_WAITING_DONE:
964 ar = (AsyncResult) msg.obj;
965 request = (MainThreadRequest) ar.userObj;
966 if (ar.exception == null) {
967 request.result = true;
968 } else {
969 request.result = false;
970 loge("setCallWaiting exception: " + ar.exception);
971 }
972 notifyRequester(request);
973 break;
974
Shishir Agrawal302c8692015-06-19 13:49:39 -0700975 case EVENT_PERFORM_NETWORK_SCAN_DONE:
976 ar = (AsyncResult) msg.obj;
977 request = (MainThreadRequest) ar.userObj;
978 CellNetworkScanResult cellScanResult;
979 if (ar.exception == null && ar.result != null) {
980 cellScanResult = new CellNetworkScanResult(
981 CellNetworkScanResult.STATUS_SUCCESS,
982 (List<OperatorInfo>) ar.result);
983 } else {
984 if (ar.result == null) {
985 loge("getCellNetworkScanResults: Empty response");
986 }
987 if (ar.exception != null) {
988 loge("getCellNetworkScanResults: Exception: " + ar.exception);
989 }
990 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
991 if (ar.exception instanceof CommandException) {
992 CommandException.Error error =
993 ((CommandException) (ar.exception)).getCommandError();
994 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
995 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
996 } else if (error == CommandException.Error.GENERIC_FAILURE) {
997 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
998 }
999 }
1000 cellScanResult = new CellNetworkScanResult(errorCode, null);
1001 }
1002 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001003 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001004 break;
1005
1006 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1007 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001008 ManualNetworkSelectionArgument selArg =
1009 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001010 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1011 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001012 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1013 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001014 break;
1015
1016 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001017 ar = (AsyncResult) msg.obj;
1018 request = (MainThreadRequest) ar.userObj;
1019 if (ar.exception == null) {
1020 request.result = true;
1021 } else {
1022 request.result = false;
1023 loge("setNetworkSelectionModeManual " + ar.exception);
1024 }
1025 notifyRequester(request);
1026 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001027 break;
1028
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001029 case CMD_GET_MODEM_ACTIVITY_INFO:
1030 request = (MainThreadRequest) msg.obj;
1031 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001032 if (defaultPhone != null) {
1033 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian1d931ee2020-02-20 17:12:10 -08001034 } else {
1035 ResultReceiver result = (ResultReceiver) request.argument;
1036 Bundle bundle = new Bundle();
1037 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1038 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1039 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001040 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001041 break;
1042
1043 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1044 ar = (AsyncResult) msg.obj;
1045 request = (MainThreadRequest) ar.userObj;
Shuo Qian1d931ee2020-02-20 17:12:10 -08001046 ResultReceiver result = (ResultReceiver) request.argument;
1047
1048 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001049 if (ar.exception == null && ar.result != null) {
Shuo Qian1d931ee2020-02-20 17:12:10 -08001050 // Update the last modem activity info and the result of the request.
1051 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1052 if (isModemActivityInfoValid(info)) {
1053 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1054 int[] txTimeMs = info.getTransmitTimeMillis();
1055 int[] lastModemTxTimeMs = mLastModemActivityInfo
1056 .getTransmitTimeMillis();
1057 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1058 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1059 }
1060 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1061 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1062 + mLastModemActivityInfo.getSleepTimeMillis());
1063 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1064 + mLastModemActivityInfo.getIdleTimeMillis());
1065 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1066 mLastModemActivityInfo.setReceiveTimeMillis(
1067 info.getReceiveTimeMillis()
1068 + mLastModemActivityInfo.getReceiveTimeMillis());
1069 }
1070 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1071 mLastModemActivityInfo.getSleepTimeMillis(),
1072 mLastModemActivityInfo.getIdleTimeMillis(),
1073 mLastModemActivityInfo.getTransmitTimeMillis(),
1074 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001075 } else {
1076 if (ar.result == null) {
1077 loge("queryModemActivityInfo: Empty response");
1078 } else if (ar.exception instanceof CommandException) {
1079 loge("queryModemActivityInfo: CommandException: " +
1080 ar.exception);
1081 } else {
1082 loge("queryModemActivityInfo: Unknown exception");
1083 }
1084 }
Shuo Qian1d931ee2020-02-20 17:12:10 -08001085 Bundle bundle = new Bundle();
1086 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1087 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001088 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001089 break;
1090
Meng Wang1a7c35a2016-05-05 20:56:15 -07001091 case CMD_SET_ALLOWED_CARRIERS:
1092 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001093 CarrierRestrictionRules argument =
1094 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001095 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001096 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001097 break;
1098
1099 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1100 ar = (AsyncResult) msg.obj;
1101 request = (MainThreadRequest) ar.userObj;
1102 if (ar.exception == null && ar.result != null) {
1103 request.result = ar.result;
1104 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001105 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1106 if (ar.exception instanceof CommandException) {
1107 loge("setAllowedCarriers: CommandException: " + ar.exception);
1108 CommandException.Error error =
1109 ((CommandException) (ar.exception)).getCommandError();
1110 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1111 request.result =
1112 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1113 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001114 } else {
1115 loge("setAllowedCarriers: Unknown exception");
1116 }
1117 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001118 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001119 break;
1120
1121 case CMD_GET_ALLOWED_CARRIERS:
1122 request = (MainThreadRequest) msg.obj;
1123 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001124 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001125 break;
1126
1127 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1128 ar = (AsyncResult) msg.obj;
1129 request = (MainThreadRequest) ar.userObj;
1130 if (ar.exception == null && ar.result != null) {
1131 request.result = ar.result;
1132 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001133 request.result = new IllegalStateException(
1134 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001135 if (ar.result == null) {
1136 loge("getAllowedCarriers: Empty response");
1137 } else if (ar.exception instanceof CommandException) {
1138 loge("getAllowedCarriers: CommandException: " +
1139 ar.exception);
1140 } else {
1141 loge("getAllowedCarriers: Unknown exception");
1142 }
1143 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001144 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001145 break;
1146
Nathan Haroldb3014052017-01-25 15:57:32 -08001147 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1148 ar = (AsyncResult) msg.obj;
1149 request = (MainThreadRequest) ar.userObj;
1150 if (ar.exception == null && ar.result != null) {
1151 request.result = ar.result;
1152 } else {
1153 request.result = new IllegalArgumentException(
1154 "Failed to retrieve Forbidden Plmns");
1155 if (ar.result == null) {
1156 loge("getForbiddenPlmns: Empty response");
1157 } else {
1158 loge("getForbiddenPlmns: Unknown exception");
1159 }
1160 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001161 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001162 break;
1163
1164 case CMD_GET_FORBIDDEN_PLMNS:
1165 request = (MainThreadRequest) msg.obj;
1166 uiccCard = getUiccCardFromRequest(request);
1167 if (uiccCard == null) {
1168 loge("getForbiddenPlmns() UiccCard is null");
1169 request.result = new IllegalArgumentException(
1170 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001171 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001172 break;
1173 }
1174 Integer appType = (Integer) request.argument;
1175 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1176 if (uiccApp == null) {
1177 loge("getForbiddenPlmns() no app with specified type -- "
1178 + appType);
1179 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001180 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001181 break;
1182 } else {
1183 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1184 + " specified type -- " + appType);
1185 }
1186 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1187 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1188 onCompleted);
1189 break;
1190
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001191 case CMD_SWITCH_SLOTS:
1192 request = (MainThreadRequest) msg.obj;
1193 int[] physicalSlots = (int[]) request.argument;
1194 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1195 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1196 break;
1197
1198 case EVENT_SWITCH_SLOTS_DONE:
1199 ar = (AsyncResult) msg.obj;
1200 request = (MainThreadRequest) ar.userObj;
1201 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001202 notifyRequester(request);
1203 break;
1204 case CMD_GET_NETWORK_SELECTION_MODE:
1205 request = (MainThreadRequest) msg.obj;
1206 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1207 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1208 break;
1209
1210 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1211 ar = (AsyncResult) msg.obj;
1212 request = (MainThreadRequest) ar.userObj;
1213 if (ar.exception != null) {
1214 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1215 } else {
1216 int mode = ((int[]) ar.result)[0];
1217 if (mode == 0) {
1218 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1219 } else {
1220 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1221 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001222 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001223 notifyRequester(request);
1224 break;
1225 case CMD_GET_CDMA_ROAMING_MODE:
1226 request = (MainThreadRequest) msg.obj;
1227 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1228 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1229 break;
1230 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1231 ar = (AsyncResult) msg.obj;
1232 request = (MainThreadRequest) ar.userObj;
1233 if (ar.exception != null) {
1234 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1235 } else {
1236 request.result = ((int[]) ar.result)[0];
1237 }
1238 notifyRequester(request);
1239 break;
1240 case CMD_SET_CDMA_ROAMING_MODE:
1241 request = (MainThreadRequest) msg.obj;
1242 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1243 int mode = (int) request.argument;
1244 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1245 break;
1246 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1247 ar = (AsyncResult) msg.obj;
1248 request = (MainThreadRequest) ar.userObj;
1249 request.result = ar.exception == null;
1250 notifyRequester(request);
1251 break;
1252 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1253 request = (MainThreadRequest) msg.obj;
1254 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1255 int subscriptionMode = (int) request.argument;
1256 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1257 break;
1258 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1259 ar = (AsyncResult) msg.obj;
1260 request = (MainThreadRequest) ar.userObj;
1261 request.result = ar.exception == null;
1262 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001263 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001264 case CMD_GET_ALL_CELL_INFO:
1265 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001266 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001267 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001269 case EVENT_GET_ALL_CELL_INFO_DONE:
1270 ar = (AsyncResult) msg.obj;
1271 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001272 // If a timeout occurs, the response will be null
1273 request.result = (ar.exception == null && ar.result != null)
1274 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001275 synchronized (request) {
1276 request.notifyAll();
1277 }
1278 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001279 case CMD_REQUEST_CELL_INFO_UPDATE:
1280 request = (MainThreadRequest) msg.obj;
1281 request.phone.requestCellInfoUpdate(request.workSource,
1282 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1283 break;
1284 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1285 ar = (AsyncResult) msg.obj;
1286 request = (MainThreadRequest) ar.userObj;
1287 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1288 try {
1289 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001290 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001291 cb.onError(
1292 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1293 ar.exception.getClass().getName(),
1294 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001296 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001297 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001298 } else {
1299 // use the result as returned
1300 cb.onCellInfo((List<CellInfo>) ar.result);
1301 }
1302 } catch (RemoteException re) {
1303 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1304 }
1305 break;
1306 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001307 request = (MainThreadRequest) msg.obj;
1308 WorkSource ws = (WorkSource) request.argument;
1309 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001310 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001311 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001312 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001313 ar = (AsyncResult) msg.obj;
1314 request = (MainThreadRequest) ar.userObj;
1315 if (ar.exception == null) {
1316 request.result = ar.result;
1317 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001318 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001319 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001320 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001321 }
1322
1323 synchronized (request) {
1324 request.notifyAll();
1325 }
1326 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001327 case CMD_MODEM_REBOOT:
1328 request = (MainThreadRequest) msg.obj;
1329 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001330 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001331 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001332 case EVENT_CMD_MODEM_REBOOT_DONE:
1333 handleNullReturnEvent(msg, "rebootModem");
1334 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001335 case CMD_REQUEST_ENABLE_MODEM:
1336 request = (MainThreadRequest) msg.obj;
1337 boolean enable = (boolean) request.argument;
1338 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001339 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001340 PhoneConfigurationManager.getInstance()
1341 .enablePhone(request.phone, enable, onCompleted);
1342 break;
1343 case EVENT_ENABLE_MODEM_DONE:
1344 ar = (AsyncResult) msg.obj;
1345 request = (MainThreadRequest) ar.userObj;
1346 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001347 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001348 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001349 if ((boolean) request.result) {
1350 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1351 updateModemStateMetrics();
1352 } else {
1353 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1354 + ar.exception);
1355 }
1356 notifyRequester(request);
1357 break;
1358 case CMD_GET_MODEM_STATUS:
1359 request = (MainThreadRequest) msg.obj;
1360 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1361 PhoneConfigurationManager.getInstance()
1362 .getPhoneStatusFromModem(request.phone, onCompleted);
1363 break;
1364 case EVENT_GET_MODEM_STATUS_DONE:
1365 ar = (AsyncResult) msg.obj;
1366 request = (MainThreadRequest) ar.userObj;
1367 int id = request.phone.getPhoneId();
1368 if (ar.exception == null && ar.result != null) {
1369 request.result = ar.result;
1370 //update the cache as modem status has changed
1371 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1372 (boolean) request.result);
1373 } else {
1374 // Return true if modem status cannot be retrieved. For most cases,
1375 // modem status is on. And for older version modems, GET_MODEM_STATUS
1376 // and disable modem are not supported. Modem is always on.
1377 // TODO: this should be fixed in R to support a third
1378 // status UNKNOWN b/131631629
1379 request.result = true;
1380 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1381 + ar.exception);
1382 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001383 notifyRequester(request);
1384 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001385 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1386 request = (MainThreadRequest) msg.obj;
1387 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1388 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1389 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1390 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1391 break;
1392 }
1393 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1394 ar = (AsyncResult) msg.obj;
1395 request = (MainThreadRequest) ar.userObj;
1396 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1397 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1398 args.second.accept(ar.exception == null);
1399 notifyRequester(request);
1400 break;
1401 }
yincheng zhao2737e882019-09-06 17:06:54 -07001402 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1403 ar = (AsyncResult) msg.obj;
1404 request = (MainThreadRequest) ar.userObj;
1405 if (ar.exception == null && ar.result != null) {
1406 request.result = ar.result;
1407 } else {
1408 request.result = -1;
1409 loge("Failed to set Forbidden Plmns");
1410 if (ar.result == null) {
1411 loge("setForbidenPlmns: Empty response");
1412 } else if (ar.exception != null) {
1413 loge("setForbiddenPlmns: Exception: " + ar.exception);
1414 request.result = -1;
1415 } else {
1416 loge("setForbiddenPlmns: Unknown exception");
1417 }
1418 }
1419 notifyRequester(request);
1420 break;
1421 case CMD_SET_FORBIDDEN_PLMNS:
1422 request = (MainThreadRequest) msg.obj;
1423 uiccCard = getUiccCardFromRequest(request);
1424 if (uiccCard == null) {
1425 loge("setForbiddenPlmns: UiccCard is null");
1426 request.result = -1;
1427 notifyRequester(request);
1428 break;
1429 }
1430 Pair<Integer, List<String>> setFplmnsArgs =
1431 (Pair<Integer, List<String>>) request.argument;
1432 appType = setFplmnsArgs.first;
1433 List<String> fplmns = setFplmnsArgs.second;
1434 uiccApp = uiccCard.getApplicationByType(appType);
1435 if (uiccApp == null) {
1436 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1437 request.result = -1;
1438 loge("Failed to get UICC App");
1439 notifyRequester(request);
1440 } else {
1441 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1442 ((SIMRecords) uiccApp.getIccRecords())
1443 .setForbiddenPlmns(onCompleted, fplmns);
1444 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001445 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001446 case CMD_ERASE_MODEM_CONFIG:
1447 request = (MainThreadRequest) msg.obj;
1448 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1449 defaultPhone.eraseModemConfig(onCompleted);
1450 break;
1451 case EVENT_ERASE_MODEM_CONFIG_DONE:
1452 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001453 break;
zoey chene02881a2019-12-30 16:11:23 +08001454
1455 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1456 request = (MainThreadRequest) msg.obj;
1457 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1458 Pair<String, String> changed = (Pair<String, String>) request.argument;
1459 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1460 changed.first, changed.second, onCompleted);
1461 break;
1462 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1463 ar = (AsyncResult) msg.obj;
1464 request = (MainThreadRequest) ar.userObj;
1465 if (ar.exception == null) {
1466 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1467 } else {
1468 request.result = msg.arg1;
1469 }
1470 notifyRequester(request);
1471 break;
1472
1473 case CMD_SET_ICC_LOCK_ENABLED:
1474 request = (MainThreadRequest) msg.obj;
1475 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1476 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1477 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1478 enabled.first, enabled.second, onCompleted);
1479 break;
1480 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1481 ar = (AsyncResult) msg.obj;
1482 request = (MainThreadRequest) ar.userObj;
1483 if (ar.exception == null) {
1484 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1485 } else {
1486 request.result = msg.arg1;
1487 }
1488 notifyRequester(request);
1489 break;
1490
Peter Wangdafb9ac2020-01-15 14:13:38 -08001491 case MSG_NOTIFY_USER_ACTIVITY:
1492 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001493 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001494 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1495 getDefaultPhone().getContext().sendBroadcastAsUser(
1496 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1497 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001498 default:
1499 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1500 break;
1501 }
1502 }
Jake Hambye994d462014-02-03 13:10:13 -08001503
Pengquan Menga1bb6272018-09-06 09:59:22 -07001504 private void notifyRequester(MainThreadRequest request) {
1505 synchronized (request) {
1506 request.notifyAll();
1507 }
1508 }
1509
Jake Hambye994d462014-02-03 13:10:13 -08001510 private void handleNullReturnEvent(Message msg, String command) {
1511 AsyncResult ar = (AsyncResult) msg.obj;
1512 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1513 if (ar.exception == null) {
1514 request.result = true;
1515 } else {
1516 request.result = false;
1517 if (ar.exception instanceof CommandException) {
1518 loge(command + ": CommandException: " + ar.exception);
1519 } else {
1520 loge(command + ": Unknown exception");
1521 }
1522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001523 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001524 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001525 }
1526
1527 /**
1528 * Posts the specified command to be executed on the main thread,
1529 * waits for the request to complete, and returns the result.
1530 * @see #sendRequestAsync
1531 */
1532 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001533 return sendRequest(
1534 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001535 }
1536
1537 /**
1538 * Posts the specified command to be executed on the main thread,
1539 * waits for the request to complete, and returns the result.
1540 * @see #sendRequestAsync
1541 */
1542 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1543 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001544 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001545 }
1546
1547 /**
1548 * Posts the specified command to be executed on the main thread,
1549 * waits for the request to complete, and returns the result.
1550 * @see #sendRequestAsync
1551 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001552 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001553 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001554 }
1555
1556 /**
1557 * Posts the specified command to be executed on the main thread,
1558 * waits for the request to complete, and returns the result.
1559 * @see #sendRequestAsync
1560 */
Nathan Harold92bed182018-10-12 18:16:49 -07001561 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1562 return sendRequest(command, argument, subId, null, workSource);
1563 }
1564
1565 /**
1566 * Posts the specified command to be executed on the main thread,
1567 * waits for the request to complete, and returns the result.
1568 * @see #sendRequestAsync
1569 */
1570 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1571 return sendRequest(
1572 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1573 }
1574
1575 /**
1576 * Posts the specified command to be executed on the main thread,
1577 * waits for the request to complete, and returns the result.
1578 * @see #sendRequestAsync
1579 */
1580 private Object sendRequest(
1581 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001582 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1583 throw new RuntimeException("This method will deadlock if called from the main thread.");
1584 }
1585
Nathan Harold92bed182018-10-12 18:16:49 -07001586 MainThreadRequest request = null;
1587 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1588 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1589 } else if (phone != null) {
1590 request = new MainThreadRequest(argument, phone, workSource);
1591 } else {
1592 request = new MainThreadRequest(argument, subId, workSource);
1593 }
1594
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001595 Message msg = mMainThreadHandler.obtainMessage(command, request);
1596 msg.sendToTarget();
1597
1598 // Wait for the request to complete
1599 synchronized (request) {
1600 while (request.result == null) {
1601 try {
1602 request.wait();
1603 } catch (InterruptedException e) {
1604 // Do nothing, go back and wait until the request is complete
1605 }
1606 }
1607 }
1608 return request.result;
1609 }
1610
1611 /**
1612 * Asynchronous ("fire and forget") version of sendRequest():
1613 * Posts the specified command to be executed on the main thread, and
1614 * returns immediately.
1615 * @see #sendRequest
1616 */
1617 private void sendRequestAsync(int command) {
1618 mMainThreadHandler.sendEmptyMessage(command);
1619 }
1620
1621 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001622 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001623 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001624 */
1625 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001626 sendRequestAsync(command, argument, null, null);
1627 }
1628
1629 /**
1630 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1631 * @see {@link #sendRequest(int,Object)}
1632 */
1633 private void sendRequestAsync(
1634 int command, Object argument, Phone phone, WorkSource workSource) {
1635 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001636 Message msg = mMainThreadHandler.obtainMessage(command, request);
1637 msg.sendToTarget();
1638 }
1639
1640 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001641 * Initialize the singleton PhoneInterfaceManager instance.
1642 * This is only done once, at startup, from PhoneApp.onCreate().
1643 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001644 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001645 synchronized (PhoneInterfaceManager.class) {
1646 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001647 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001648 } else {
1649 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1650 }
1651 return sInstance;
1652 }
1653 }
1654
1655 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001656 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001658 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001659 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001660 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001661 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1662 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001663 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001664 mTelephonySharedPreferences =
1665 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001666 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001667 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001668 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001669
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001670 publish();
1671 }
1672
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001673 private Phone getDefaultPhone() {
1674 Phone thePhone = getPhone(getDefaultSubscription());
1675 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1676 }
1677
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001678 private void publish() {
1679 if (DBG) log("publish: " + this);
1680
Peter Wangc035ce42020-01-08 21:00:22 -08001681 TelephonyFrameworkInitializer
1682 .getTelephonyServiceManager()
1683 .getTelephonyServiceRegisterer()
1684 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001685 }
1686
Stuart Scott584921c2015-01-15 17:10:34 -08001687 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001688 if (request.phone != null) {
1689 return request.phone;
1690 } else {
1691 return getPhoneFromSubId(request.subId);
1692 }
1693 }
1694
1695 private Phone getPhoneFromSubId(int subId) {
1696 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1697 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001698 }
1699
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001700 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1701 Phone phone = getPhoneFromRequest(request);
1702 return phone == null ? null :
1703 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1704 }
1705
Wink Saville36469e72014-06-11 15:17:00 -07001706 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001707 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001708 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001709 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001710
Naina Nallurid63128d2019-09-17 14:10:30 -07001711 private void sendEraseModemConfig(Phone phone) {
1712 if (phone != null) {
1713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1714 mApp, phone.getSubId(), "eraseModemConfig");
1715 final long identity = Binder.clearCallingIdentity();
1716 try {
1717 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1718 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1719 } finally {
1720 Binder.restoreCallingIdentity(identity);
1721 }
1722 }
1723 }
1724
Peter Wang44b186e2020-01-13 23:33:09 -08001725 private boolean isImsAvailableOnDevice() {
1726 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1727 if (pm == null) {
1728 // For some reason package manger is not available.. This will fail internally anyway,
1729 // so do not throw error and allow.
1730 return true;
1731 }
1732 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1733 }
1734
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001735 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001736 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001737 }
1738
Wink Savilleb564aae2014-10-23 10:18:09 -07001739 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001740 if (DBG) log("dial: " + number);
1741 // No permission check needed here: This is just a wrapper around the
1742 // ACTION_DIAL intent, which is available to any app since it puts up
1743 // the UI before it does anything.
1744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001745 final long identity = Binder.clearCallingIdentity();
1746 try {
1747 String url = createTelUrl(number);
1748 if (url == null) {
1749 return;
1750 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001751
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001752 // PENDING: should we just silently fail if phone is offhook or ringing?
1753 PhoneConstants.State state = mCM.getState(subId);
1754 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1755 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1756 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1757 mApp.startActivity(intent);
1758 }
1759 } finally {
1760 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001761 }
1762 }
1763
1764 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001765 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001766 }
1767
Wink Savilleb564aae2014-10-23 10:18:09 -07001768 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001769 if (DBG) log("call: " + number);
1770
1771 // This is just a wrapper around the ACTION_CALL intent, but we still
1772 // need to do a permission check since we're calling startActivity()
1773 // from the context of the phone app.
1774 enforceCallPermission();
1775
Jordan Liu1617b712019-07-10 15:06:26 -07001776 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001777 != AppOpsManager.MODE_ALLOWED) {
1778 return;
1779 }
1780
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001781 final long identity = Binder.clearCallingIdentity();
1782 try {
1783 String url = createTelUrl(number);
1784 if (url == null) {
1785 return;
1786 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001787
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001788 boolean isValid = false;
1789 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1790 if (slist != null) {
1791 for (SubscriptionInfo subInfoRecord : slist) {
1792 if (subInfoRecord.getSubscriptionId() == subId) {
1793 isValid = true;
1794 break;
1795 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001796 }
Wink Saville08874612014-08-31 19:19:58 -07001797 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001798 if (!isValid) {
1799 return;
1800 }
Wink Saville08874612014-08-31 19:19:58 -07001801
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001802 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1803 intent.putExtra(SUBSCRIPTION_KEY, subId);
1804 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1805 mApp.startActivity(intent);
1806 } finally {
1807 Binder.restoreCallingIdentity(identity);
1808 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001809 }
1810
Wink Savilleb564aae2014-10-23 10:18:09 -07001811 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001812 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001813 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1814 }
1815
Wink Savilleb564aae2014-10-23 10:18:09 -07001816 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001817 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001818 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1819 }
1820
Wink Savilleb564aae2014-10-23 10:18:09 -07001821 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001822 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001823
1824 final long identity = Binder.clearCallingIdentity();
1825 try {
1826 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1827 checkSimPin.start();
1828 return checkSimPin.unlockSim(null, pin);
1829 } finally {
1830 Binder.restoreCallingIdentity(identity);
1831 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001832 }
1833
Wink Savilleb564aae2014-10-23 10:18:09 -07001834 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001835 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001836
1837 final long identity = Binder.clearCallingIdentity();
1838 try {
1839 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1840 checkSimPuk.start();
1841 return checkSimPuk.unlockSim(puk, pin);
1842 } finally {
1843 Binder.restoreCallingIdentity(identity);
1844 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001845 }
1846
1847 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001848 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001849 * a synchronous one.
1850 */
1851 private static class UnlockSim extends Thread {
1852
1853 private final IccCard mSimCard;
1854
1855 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001856 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1857 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001858
1859 // For replies from SimCard interface
1860 private Handler mHandler;
1861
1862 // For async handler to identify request type
1863 private static final int SUPPLY_PIN_COMPLETE = 100;
1864
1865 public UnlockSim(IccCard simCard) {
1866 mSimCard = simCard;
1867 }
1868
1869 @Override
1870 public void run() {
1871 Looper.prepare();
1872 synchronized (UnlockSim.this) {
1873 mHandler = new Handler() {
1874 @Override
1875 public void handleMessage(Message msg) {
1876 AsyncResult ar = (AsyncResult) msg.obj;
1877 switch (msg.what) {
1878 case SUPPLY_PIN_COMPLETE:
1879 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1880 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001881 mRetryCount = msg.arg1;
1882 if (ar.exception != null) {
1883 if (ar.exception instanceof CommandException &&
1884 ((CommandException)(ar.exception)).getCommandError()
1885 == CommandException.Error.PASSWORD_INCORRECT) {
1886 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
1887 } else {
1888 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1889 }
1890 } else {
1891 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1892 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001893 mDone = true;
1894 UnlockSim.this.notifyAll();
1895 }
1896 break;
1897 }
1898 }
1899 };
1900 UnlockSim.this.notifyAll();
1901 }
1902 Looper.loop();
1903 }
1904
1905 /*
1906 * Use PIN or PUK to unlock SIM card
1907 *
1908 * If PUK is null, unlock SIM card with PIN
1909 *
1910 * If PUK is not null, unlock SIM card with PUK and set PIN code
1911 */
Wink Saville9de0f752013-10-22 19:04:03 -07001912 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001913
1914 while (mHandler == null) {
1915 try {
1916 wait();
1917 } catch (InterruptedException e) {
1918 Thread.currentThread().interrupt();
1919 }
1920 }
1921 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1922
1923 if (puk == null) {
1924 mSimCard.supplyPin(pin, callback);
1925 } else {
1926 mSimCard.supplyPuk(puk, pin, callback);
1927 }
1928
1929 while (!mDone) {
1930 try {
1931 Log.d(LOG_TAG, "wait for done");
1932 wait();
1933 } catch (InterruptedException e) {
1934 // Restore the interrupted status
1935 Thread.currentThread().interrupt();
1936 }
1937 }
1938 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001939 int[] resultArray = new int[2];
1940 resultArray[0] = mResult;
1941 resultArray[1] = mRetryCount;
1942 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001943 }
1944 }
1945
1946 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001947 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001948
1949 }
1950
Wink Savilleb564aae2014-10-23 10:18:09 -07001951 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001952 // No permission check needed here: this call is harmless, and it's
1953 // needed for the ServiceState.requestStateUpdate() call (which is
1954 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001955 final long identity = Binder.clearCallingIdentity();
1956 try {
1957 final Phone phone = getPhone(subId);
1958 if (phone != null) {
1959 phone.updateServiceLocation();
1960 }
1961 } finally {
1962 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001963 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001964 }
1965
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001966 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001967 @Override
1968 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001969 return isRadioOnWithFeature(callingPackage, null);
1970 }
1971
1972
1973 @Override
1974 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1975 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1976 callingFeatureId);
1977 }
1978
1979 @Deprecated
1980 @Override
1981 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1982 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001983 }
1984
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001985 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001986 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1987 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001988 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001989 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001990 return false;
1991 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001992
1993 final long identity = Binder.clearCallingIdentity();
1994 try {
1995 return isRadioOnForSubscriber(subId);
1996 } finally {
1997 Binder.restoreCallingIdentity(identity);
1998 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001999 }
2000
2001 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002002 final long identity = Binder.clearCallingIdentity();
2003 try {
2004 final Phone phone = getPhone(subId);
2005 if (phone != null) {
2006 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2007 } else {
2008 return false;
2009 }
2010 } finally {
2011 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002012 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002013 }
2014
2015 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002016 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
Wink Saville36469e72014-06-11 15:17:00 -07002018
Wink Savilleb564aae2014-10-23 10:18:09 -07002019 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002020 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002021
2022 final long identity = Binder.clearCallingIdentity();
2023 try {
2024 final Phone phone = getPhone(subId);
2025 if (phone != null) {
2026 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2027 }
2028 } finally {
2029 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002030 }
Wink Saville36469e72014-06-11 15:17:00 -07002031 }
2032
2033 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002034 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
Wink Savilleb564aae2014-10-23 10:18:09 -07002037 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002038 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002039
2040 final long identity = Binder.clearCallingIdentity();
2041 try {
2042 final Phone phone = getPhone(subId);
2043 if (phone == null) {
2044 return false;
2045 }
2046 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2047 toggleRadioOnOffForSubscriber(subId);
2048 }
2049 return true;
2050 } finally {
2051 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002052 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
Wink Saville36469e72014-06-11 15:17:00 -07002054
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002055 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002056 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002057 /*
2058 * If any of the Radios are available, it will need to be
2059 * shutdown. So return true if any Radio is available.
2060 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002061 final long identity = Binder.clearCallingIdentity();
2062 try {
2063 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2064 Phone phone = PhoneFactory.getPhone(i);
2065 if (phone != null && phone.isRadioAvailable()) return true;
2066 }
2067 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2068 return false;
2069 } finally {
2070 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002071 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002072 }
2073
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002074 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002076 enforceModifyPermission();
2077
2078 final long identity = Binder.clearCallingIdentity();
2079 try {
2080 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2081 logv("Shutting down Phone " + i);
2082 shutdownRadioUsingPhoneId(i);
2083 }
2084 } finally {
2085 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002086 }
2087 }
2088
2089 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002090 Phone phone = PhoneFactory.getPhone(phoneId);
2091 if (phone != null && phone.isRadioAvailable()) {
2092 phone.shutdownRadio();
2093 }
2094 }
2095
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002096 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002097 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002098
2099 final long identity = Binder.clearCallingIdentity();
2100 try {
2101 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2102 if (defaultPhone != null) {
2103 defaultPhone.setRadioPower(turnOn);
2104 return true;
2105 } else {
2106 loge("There's no default phone.");
2107 return false;
2108 }
2109 } finally {
2110 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002111 }
Wink Saville36469e72014-06-11 15:17:00 -07002112 }
2113
Wink Savilleb564aae2014-10-23 10:18:09 -07002114 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002115 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002116
2117 final long identity = Binder.clearCallingIdentity();
2118 try {
2119 final Phone phone = getPhone(subId);
2120 if (phone != null) {
2121 phone.setRadioPower(turnOn);
2122 return true;
2123 } else {
2124 return false;
2125 }
2126 } finally {
2127 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002128 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002129 }
2130
Wink Saville36469e72014-06-11 15:17:00 -07002131 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 public boolean enableDataConnectivity() {
2134 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002135
2136 final long identity = Binder.clearCallingIdentity();
2137 try {
2138 int subId = mSubscriptionController.getDefaultDataSubId();
2139 final Phone phone = getPhone(subId);
2140 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002141 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002142 return true;
2143 } else {
2144 return false;
2145 }
2146 } finally {
2147 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002148 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002149 }
2150
Wink Saville36469e72014-06-11 15:17:00 -07002151 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002152 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002153 public boolean disableDataConnectivity() {
2154 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002155
2156 final long identity = Binder.clearCallingIdentity();
2157 try {
2158 int subId = mSubscriptionController.getDefaultDataSubId();
2159 final Phone phone = getPhone(subId);
2160 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002161 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002162 return true;
2163 } else {
2164 return false;
2165 }
2166 } finally {
2167 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 }
2170
Sanket Padawe356d7632015-06-22 14:03:32 -07002171 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002172 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002173 final long identity = Binder.clearCallingIdentity();
2174 try {
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002177 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 } else {
2179 return false;
2180 }
2181 } finally {
2182 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002183 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002184 }
2185
2186 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002187 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002188 }
2189
pkanwarae03a6b2016-11-06 20:37:09 -08002190 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191 enforceCallPermission();
2192
2193 final long identity = Binder.clearCallingIdentity();
2194 try {
2195 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2196 return;
2197 }
2198 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2199 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2200 } finally {
2201 Binder.restoreCallingIdentity(identity);
2202 }
pkanwar32d516d2016-10-14 19:37:38 -07002203 };
2204
Wink Savilleb564aae2014-10-23 10:18:09 -07002205 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002206 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002207
2208 final long identity = Binder.clearCallingIdentity();
2209 try {
2210 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2211 return false;
2212 }
2213 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2214 } finally {
2215 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002216 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002217 }
2218
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002219 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002220 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002221 }
2222
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002223 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002224 final long identity = Binder.clearCallingIdentity();
2225 try {
2226 Phone phone = PhoneFactory.getPhone(slotIndex);
2227 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2228 PhoneConstantConversions.convertCallState(phone.getState());
2229 } finally {
2230 Binder.restoreCallingIdentity(identity);
2231 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002232 }
2233
Sanket Padawe356d7632015-06-22 14:03:32 -07002234 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002235 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002236 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2237 }
2238
2239 @Override
2240 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002241 final long identity = Binder.clearCallingIdentity();
2242 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002243 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002244 if (phone != null) {
2245 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2246 } else {
2247 return PhoneConstantConversions.convertDataState(
2248 PhoneConstants.DataState.DISCONNECTED);
2249 }
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Sanket Padawe356d7632015-06-22 14:03:32 -07002255 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002256 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002257 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2258 }
2259
2260 @Override
2261 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002262 final long identity = Binder.clearCallingIdentity();
2263 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002264 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002265 if (phone != null) {
2266 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2267 } else {
2268 return TelephonyManager.DATA_ACTIVITY_NONE;
2269 }
2270 } finally {
2271 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002272 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002273 }
2274
2275 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002276 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002277 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002278 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002279
2280 LocationAccessPolicy.LocationPermissionResult locationResult =
2281 LocationAccessPolicy.checkLocationPermission(mApp,
2282 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2283 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002284 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002285 .setCallingPid(Binder.getCallingPid())
2286 .setCallingUid(Binder.getCallingUid())
2287 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002288 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002289 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2290 .build());
2291 switch (locationResult) {
2292 case DENIED_HARD:
2293 throw new SecurityException("Not allowed to access cell location");
2294 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002295 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2296 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002297 }
2298
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002299 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002300 final long identity = Binder.clearCallingIdentity();
2301 try {
2302 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002303 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002304 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002305 } finally {
2306 Binder.restoreCallingIdentity(identity);
2307 }
Svetoslav64fad262015-04-14 14:35:21 -07002308 }
2309
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002310 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002311 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002312 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2313 // registered cell info, so return a NULL country instead.
2314 final long identity = Binder.clearCallingIdentity();
2315 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002316 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2317 // Get default phone in this case.
2318 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2319 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002320 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002321 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002322 if (phone == null) return "";
2323 ServiceStateTracker sst = phone.getServiceStateTracker();
2324 if (sst == null) return "";
2325 LocaleTracker lt = sst.getLocaleTracker();
2326 if (lt == null) return "";
2327 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2328 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2329 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002330 } finally {
2331 Binder.restoreCallingIdentity(identity);
2332 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002333 }
2334
2335 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002336 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002337 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002338 }
2339
Sanket Padawe356d7632015-06-22 14:03:32 -07002340 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002341 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 mApp.enforceCallingOrSelfPermission(
2343 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002344
2345 final long identity = Binder.clearCallingIdentity();
2346 try {
2347 final Phone phone = getPhone(subId);
2348 if (phone != null) {
2349 phone.enableLocationUpdates();
2350 }
2351 } finally {
2352 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002353 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002354 }
2355
2356 @Override
2357 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002358 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002359 }
2360
Sanket Padawe356d7632015-06-22 14:03:32 -07002361 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002362 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002363 mApp.enforceCallingOrSelfPermission(
2364 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002365
2366 final long identity = Binder.clearCallingIdentity();
2367 try {
2368 final Phone phone = getPhone(subId);
2369 if (phone != null) {
2370 phone.disableLocationUpdates();
2371 }
2372 } finally {
2373 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002374 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002375 }
2376
Nathan Harold31d7ff32018-10-15 20:20:30 -07002377 /**
2378 * Returns the target SDK version number for a given package name.
2379 *
Nathan Haroldec184742019-07-10 17:04:16 -07002380 * This call MUST be invoked before clearing the calling UID.
2381 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002382 * @return target SDK if the package is found or INT_MAX.
2383 */
2384 private int getTargetSdk(String packageName) {
2385 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002386 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002387 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 if (ai != null) return ai.targetSdkVersion;
2389 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002390 loge("Failed to get package info for pkg="
2391 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002392 }
2393 return Integer.MAX_VALUE;
2394 }
2395
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002396 @Override
2397 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002398 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2399 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002400 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002401 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2402 throw new SecurityException(
2403 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2404 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002405
Jordan Liu1617b712019-07-10 15:06:26 -07002406 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002407 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2408 return null;
2409 }
Svetoslav64fad262015-04-14 14:35:21 -07002410
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002411 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002412
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002413 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002414 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002415
Nathan Haroldf180aac2018-06-01 18:43:55 -07002416 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2417 for (CellInfo ci : info) {
2418 if (ci instanceof CellInfoGsm) {
2419 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2420 } else if (ci instanceof CellInfoWcdma) {
2421 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2422 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002423 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002424 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002425 }
2426
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002427 private List<CellInfo> getCachedCellInfo() {
2428 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2429 for (Phone phone : PhoneFactory.getPhones()) {
2430 List<CellInfo> info = phone.getAllCellInfo();
2431 if (info != null) cellInfos.addAll(info);
2432 }
2433 return cellInfos;
2434 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
2436 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002437 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002438 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002439 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002440
2441 LocationAccessPolicy.LocationPermissionResult locationResult =
2442 LocationAccessPolicy.checkLocationPermission(mApp,
2443 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2444 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002445 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002446 .setCallingPid(Binder.getCallingPid())
2447 .setCallingUid(Binder.getCallingUid())
2448 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002449 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002450 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2451 .build());
2452 switch (locationResult) {
2453 case DENIED_HARD:
2454 throw new SecurityException("Not allowed to access cell info");
2455 case DENIED_SOFT:
2456 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002457 }
2458
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002459 final int targetSdk = getTargetSdk(callingPackage);
2460 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2461 return getCachedCellInfo();
2462 }
2463
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002464 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002465 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002466 final long identity = Binder.clearCallingIdentity();
2467 try {
2468 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2469 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002470 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002471 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 if (info != null) cellInfos.addAll(info);
2473 }
2474 return cellInfos;
2475 } finally {
2476 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478 }
2479
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002480 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002481 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2482 String callingFeatureId) {
2483 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2484 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002485 }
2486
2487 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002488 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2489 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002490 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002491 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002492 }
2493
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002494 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2495 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002496 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002497 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002498
2499 LocationAccessPolicy.LocationPermissionResult locationResult =
2500 LocationAccessPolicy.checkLocationPermission(mApp,
2501 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2502 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002503 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002504 .setCallingPid(Binder.getCallingPid())
2505 .setCallingUid(Binder.getCallingUid())
2506 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002507 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2508 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002509 .build());
2510 switch (locationResult) {
2511 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002512 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2513 // Safetynet logging for b/154934934
2514 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2515 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002516 throw new SecurityException("Not allowed to access cell info");
2517 case DENIED_SOFT:
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 }
Nathan Harold5320c422019-05-09 10:26:08 -07002522 try {
2523 cb.onCellInfo(new ArrayList<CellInfo>());
2524 } catch (RemoteException re) {
2525 // Drop without consequences
2526 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002527 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002528 }
2529
Nathan Harolda939a962019-05-09 10:13:47 -07002530
2531 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002532 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2533
2534 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2535 }
2536
2537 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002538 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002539 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002540 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002541
2542 final long identity = Binder.clearCallingIdentity();
2543 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002544 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002545 } finally {
2546 Binder.restoreCallingIdentity(identity);
2547 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002548 }
2549
Shishir Agrawala9f32182016-04-12 12:00:16 -07002550 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002551 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002552 Phone phone = PhoneFactory.getPhone(slotIndex);
2553 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002554 return null;
2555 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002556 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002557 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002558 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002559 return null;
2560 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
2564 return phone.getImei();
2565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002568 }
2569
2570 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002571 public String getTypeAllocationCodeForSlot(int slotIndex) {
2572 Phone phone = PhoneFactory.getPhone(slotIndex);
2573 String tac = null;
2574 if (phone != null) {
2575 String imei = phone.getImei();
2576 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2577 }
2578 return tac;
2579 }
2580
2581 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002582 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002583 Phone phone = PhoneFactory.getPhone(slotIndex);
2584 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002585 return null;
2586 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002587
Jeff Davidson913390f2018-02-23 17:11:49 -08002588 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002589 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002590 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002591 return null;
2592 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002593
2594 final long identity = Binder.clearCallingIdentity();
2595 try {
2596 return phone.getMeid();
2597 } finally {
2598 Binder.restoreCallingIdentity(identity);
2599 }
Jack Yu2af8d712017-03-15 17:14:14 -07002600 }
2601
2602 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002603 public String getManufacturerCodeForSlot(int slotIndex) {
2604 Phone phone = PhoneFactory.getPhone(slotIndex);
2605 String manufacturerCode = null;
2606 if (phone != null) {
2607 String meid = phone.getMeid();
2608 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2609 }
2610 return manufacturerCode;
2611 }
2612
2613 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002614 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2615 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002616 Phone phone = PhoneFactory.getPhone(slotIndex);
2617 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002618 return null;
2619 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002620 int subId = phone.getSubId();
2621 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002622 mApp, subId, callingPackage, callingFeatureId,
2623 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002624 return null;
2625 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002626
2627 final long identity = Binder.clearCallingIdentity();
2628 try {
2629 return phone.getDeviceSvn();
2630 } finally {
2631 Binder.restoreCallingIdentity(identity);
2632 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002633 }
2634
fionaxu43304da2017-11-27 22:51:16 -08002635 @Override
2636 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002637 final long identity = Binder.clearCallingIdentity();
2638 try {
2639 final Phone phone = getPhone(subId);
2640 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2641 } finally {
2642 Binder.restoreCallingIdentity(identity);
2643 }
fionaxu43304da2017-11-27 22:51:16 -08002644 }
2645
2646 @Override
2647 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002648 final long identity = Binder.clearCallingIdentity();
2649 try {
2650 final Phone phone = getPhone(subId);
2651 return phone == null ? null : phone.getCarrierName();
2652 } finally {
2653 Binder.restoreCallingIdentity(identity);
2654 }
fionaxu43304da2017-11-27 22:51:16 -08002655 }
2656
calvinpanffe225e2018-11-01 19:43:06 +08002657 @Override
chen xu0026ca62019-03-06 15:28:50 -08002658 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002659 final long identity = Binder.clearCallingIdentity();
2660 try {
2661 final Phone phone = getPhone(subId);
2662 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002663 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002664 } finally {
2665 Binder.restoreCallingIdentity(identity);
2666 }
2667 }
2668
2669 @Override
chen xu0026ca62019-03-06 15:28:50 -08002670 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002671 final long identity = Binder.clearCallingIdentity();
2672 try {
2673 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002674 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002675 } finally {
2676 Binder.restoreCallingIdentity(identity);
2677 }
2678 }
2679
chen xu651eec72018-11-11 19:03:44 -08002680 @Override
chen xu864e11c2018-12-06 22:10:03 -08002681 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2682 if (!isSubscriptionMccMnc) {
2683 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2684 }
chen xu651eec72018-11-11 19:03:44 -08002685 final Phone phone = PhoneFactory.getPhone(slotIndex);
2686 if (phone == null) {
2687 return TelephonyManager.UNKNOWN_CARRIER_ID;
2688 }
2689 final long identity = Binder.clearCallingIdentity();
2690 try {
2691 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2692 } finally {
2693 Binder.restoreCallingIdentity(identity);
2694 }
2695 }
2696
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002697 //
2698 // Internal helper methods.
2699 //
2700
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002701 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002702 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2703 *
2704 * @throws SecurityException if the caller does not have the required permission
2705 */
2706 private void enforceModifyPermission() {
2707 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2708 }
2709
Shuo Qiancd19c462020-01-16 20:51:11 -08002710 /**
2711 * Make sure the caller is system.
2712 *
2713 * @throws SecurityException if the caller is not system.
2714 */
2715 private void enforceSystemCaller() {
2716 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2717 throw new SecurityException("Caller must be system");
2718 }
2719 }
2720
Shuo Qian3b6ee772019-11-13 17:43:31 -08002721 private void enforceActiveEmergencySessionPermission() {
2722 mApp.enforceCallingOrSelfPermission(
2723 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2724 }
2725
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002726 /**
2727 * Make sure the caller has the CALL_PHONE permission.
2728 *
2729 * @throws SecurityException if the caller does not have the required permission
2730 */
2731 private void enforceCallPermission() {
2732 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2733 }
2734
paulhu5a773602019-08-23 19:17:33 +08002735 private void enforceSettingsPermission() {
2736 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002737 }
2738
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002739 private String createTelUrl(String number) {
2740 if (TextUtils.isEmpty(number)) {
2741 return null;
2742 }
2743
Jake Hambye994d462014-02-03 13:10:13 -08002744 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 }
2746
Ihab Awadf9e92732013-12-05 18:02:52 -08002747 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002748 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2749 }
2750
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002751 private static void logv(String msg) {
2752 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2753 }
2754
Ihab Awadf9e92732013-12-05 18:02:52 -08002755 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002756 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2757 }
2758
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002759 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002760 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002761 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002762 }
2763
Sanket Padawe356d7632015-06-22 14:03:32 -07002764 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002765 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002766 final long identity = Binder.clearCallingIdentity();
2767 try {
2768 final Phone phone = PhoneFactory.getPhone(slotIndex);
2769 if (phone == null) {
2770 return PhoneConstants.PHONE_TYPE_NONE;
2771 } else {
2772 return phone.getPhoneType();
2773 }
2774 } finally {
2775 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002776 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002777 }
2778
2779 /**
2780 * Returns the CDMA ERI icon index to display
2781 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002783 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2784 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2785 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002786 }
2787
Sanket Padawe356d7632015-06-22 14:03:32 -07002788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002789 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2790 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002791 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002792 mApp, subId, callingPackage, callingFeatureId,
2793 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002794 return -1;
2795 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002796
2797 final long identity = Binder.clearCallingIdentity();
2798 try {
2799 final Phone phone = getPhone(subId);
2800 if (phone != null) {
2801 return phone.getCdmaEriIconIndex();
2802 } else {
2803 return -1;
2804 }
2805 } finally {
2806 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002808 }
2809
2810 /**
2811 * Returns the CDMA ERI icon mode,
2812 * 0 - ON
2813 * 1 - FLASHING
2814 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002815 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002816 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2817 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2818 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002819 }
2820
Sanket Padawe356d7632015-06-22 14:03:32 -07002821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2823 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002824 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002825 mApp, subId, callingPackage, callingFeatureId,
2826 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002827 return -1;
2828 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002829
2830 final long identity = Binder.clearCallingIdentity();
2831 try {
2832 final Phone phone = getPhone(subId);
2833 if (phone != null) {
2834 return phone.getCdmaEriIconMode();
2835 } else {
2836 return -1;
2837 }
2838 } finally {
2839 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002840 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002841 }
2842
2843 /**
2844 * Returns the CDMA ERI text,
2845 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002846 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002847 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2848 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2849 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002850 }
2851
Sanket Padawe356d7632015-06-22 14:03:32 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2854 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002855 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002856 mApp, subId, callingPackage, callingFeatureId,
2857 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002858 return null;
2859 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002860
2861 final long identity = Binder.clearCallingIdentity();
2862 try {
2863 final Phone phone = getPhone(subId);
2864 if (phone != null) {
2865 return phone.getCdmaEriText();
2866 } else {
2867 return null;
2868 }
2869 } finally {
2870 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002871 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002872 }
2873
2874 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002875 * Returns the CDMA MDN.
2876 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002878 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002879 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2880 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002881
2882 final long identity = Binder.clearCallingIdentity();
2883 try {
2884 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002885 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002886 return phone.getLine1Number();
2887 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002888 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002889 return null;
2890 }
2891 } finally {
2892 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002893 }
2894 }
2895
2896 /**
2897 * Returns the CDMA MIN.
2898 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002899 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002900 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002901 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2902 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002903
2904 final long identity = Binder.clearCallingIdentity();
2905 try {
2906 final Phone phone = getPhone(subId);
2907 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2908 return phone.getCdmaMin();
2909 } else {
2910 return null;
2911 }
2912 } finally {
2913 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002914 }
2915 }
2916
Hall Liud892bec2018-11-30 14:51:45 -08002917 @Override
2918 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2919 INumberVerificationCallback callback, String callingPackage) {
2920 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2921 != PERMISSION_GRANTED) {
2922 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2923 }
2924 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2925
2926 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2927 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2928 throw new SecurityException("Calling package must be configured in the device config");
2929 }
2930
2931 if (range == null) {
2932 throw new NullPointerException("Range must be non-null");
2933 }
2934
2935 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002936 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002937
2938 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2939 }
2940
Junda Liuca05d5d2014-08-14 22:36:34 -07002941 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002942 * Returns true if CDMA provisioning needs to run.
2943 */
2944 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002945 final long identity = Binder.clearCallingIdentity();
2946 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002947 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002948 } finally {
2949 Binder.restoreCallingIdentity(identity);
2950 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002951 }
2952
2953 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002954 * Sets the voice mail number of a given subId.
2955 */
2956 @Override
2957 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002958 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2959 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002960
2961 final long identity = Binder.clearCallingIdentity();
2962 try {
2963 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2964 new Pair<String, String>(alphaTag, number), new Integer(subId));
2965 return success;
2966 } finally {
2967 Binder.restoreCallingIdentity(identity);
2968 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002969 }
2970
Ta-wei Yen87c49842016-05-13 21:19:52 -07002971 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002972 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2973 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002974 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2975 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002976 if (!TextUtils.equals(callingPackage, systemDialer)) {
2977 throw new SecurityException("caller must be system dialer");
2978 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002979
2980 final long identity = Binder.clearCallingIdentity();
2981 try {
2982 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2983 if (phoneAccountHandle == null) {
2984 return null;
2985 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002986 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002987 } finally {
2988 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002989 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002990 }
2991
2992 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002993 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
2994 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002995 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08002996 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002997 mApp, subId, callingPackage, callingFeatureId,
2998 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08002999 return null;
3000 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003001
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003002 final long identity = Binder.clearCallingIdentity();
3003 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003004 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003005 } finally {
3006 Binder.restoreCallingIdentity(identity);
3007 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003008 }
3009
3010 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003011 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3012 VisualVoicemailSmsFilterSettings settings) {
3013 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003014
3015 final long identity = Binder.clearCallingIdentity();
3016 try {
3017 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003018 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003019 } finally {
3020 Binder.restoreCallingIdentity(identity);
3021 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003022 }
3023
3024 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003025 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3026 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003027
3028 final long identity = Binder.clearCallingIdentity();
3029 try {
3030 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003031 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003032 } finally {
3033 Binder.restoreCallingIdentity(identity);
3034 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003035 }
3036
3037 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003038 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3039 String callingPackage, int subId) {
3040 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003041
3042 final long identity = Binder.clearCallingIdentity();
3043 try {
3044 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003045 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003046 } finally {
3047 Binder.restoreCallingIdentity(identity);
3048 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003049 }
3050
3051 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003052 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003053 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003054
3055 final long identity = Binder.clearCallingIdentity();
3056 try {
3057 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003058 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003059 } finally {
3060 Binder.restoreCallingIdentity(identity);
3061 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003062 }
3063
3064 @Override
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003065 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3066 String callingAttributionTag, int subId, String number, int port, String text,
3067 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003068 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003069 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003070 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003071 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmannacc63642020-03-19 21:37:01 +00003072 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3073 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003074 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003075
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003076 /**
fionaxu0152e512016-11-14 13:36:14 -08003077 * Sets the voice activation state of a given subId.
3078 */
3079 @Override
3080 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003081 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3082 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003083
3084 final long identity = Binder.clearCallingIdentity();
3085 try {
3086 final Phone phone = getPhone(subId);
3087 if (phone != null) {
3088 phone.setVoiceActivationState(activationState);
3089 } else {
3090 loge("setVoiceActivationState fails with invalid subId: " + subId);
3091 }
3092 } finally {
3093 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003094 }
3095 }
3096
3097 /**
3098 * Sets the data activation state of a given subId.
3099 */
3100 @Override
3101 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003102 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3103 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003104
3105 final long identity = Binder.clearCallingIdentity();
3106 try {
3107 final Phone phone = getPhone(subId);
3108 if (phone != null) {
3109 phone.setDataActivationState(activationState);
3110 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003111 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003112 }
3113 } finally {
3114 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003115 }
3116 }
3117
3118 /**
3119 * Returns the voice activation state of a given subId.
3120 */
3121 @Override
3122 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003123 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
fionaxu0152e512016-11-14 13:36:14 -08003125 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003126 final long identity = Binder.clearCallingIdentity();
3127 try {
3128 if (phone != null) {
3129 return phone.getVoiceActivationState();
3130 } else {
3131 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3132 }
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003135 }
3136 }
3137
3138 /**
3139 * Returns the data activation state of a given subId.
3140 */
3141 @Override
3142 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
fionaxu0152e512016-11-14 13:36:14 -08003145 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 if (phone != null) {
3149 return phone.getDataActivationState();
3150 } else {
3151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003155 }
3156 }
3157
3158 /**
Wink Saville36469e72014-06-11 15:17:00 -07003159 * Returns the unread count of voicemails for a subId
3160 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003161 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003162 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3163 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003164 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003165 mApp, subId, callingPackage, callingFeatureId,
3166 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003167 return 0;
3168 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003169 final long identity = Binder.clearCallingIdentity();
3170 try {
3171 final Phone phone = getPhone(subId);
3172 if (phone != null) {
3173 return phone.getVoiceMessageCount();
3174 } else {
3175 return 0;
3176 }
3177 } finally {
3178 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003179 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003180 }
3181
3182 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003183 * returns true, if the device is in a state where both voice and data
3184 * are supported simultaneously. This can change based on location or network condition.
3185 */
3186 @Override
3187 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003188 final long identity = Binder.clearCallingIdentity();
3189 try {
3190 final Phone phone = getPhone(subId);
3191 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3192 } finally {
3193 Binder.restoreCallingIdentity(identity);
3194 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003195 }
3196
3197 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003198 * Send the dialer code if called from the current default dialer or the caller has
3199 * carrier privilege.
3200 * @param inputCode The dialer code to send
3201 */
3202 @Override
3203 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003204 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003205 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003206 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3207 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003208 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003209 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003210 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003211 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003212
3213 final long identity = Binder.clearCallingIdentity();
3214 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003215 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003216 } finally {
3217 Binder.restoreCallingIdentity(identity);
3218 }
fionaxu235cc5e2017-03-06 22:25:57 -08003219 }
3220
Pengquan Menga1bb6272018-09-06 09:59:22 -07003221 @Override
3222 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003223 TelephonyPermissions
3224 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3225 mApp, subId, "getNetworkSelectionMode");
3226 final long identity = Binder.clearCallingIdentity();
3227 try {
3228 if (!isActiveSubscription(subId)) {
3229 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3230 }
3231 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3232 } finally {
3233 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003234 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003235 }
3236
Brad Ebinger35c841c2018-10-01 10:40:55 -07003237 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003238 public boolean isInEmergencySmsMode() {
3239 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3240 final long identity = Binder.clearCallingIdentity();
3241 try {
3242 for (Phone phone : PhoneFactory.getPhones()) {
3243 if (phone.isInEmergencySmsMode()) {
3244 return true;
3245 }
3246 }
3247 } finally {
3248 Binder.restoreCallingIdentity(identity);
3249 }
3250 return false;
3251 }
3252
shilu366312e2019-12-17 09:28:10 -08003253 /**
3254 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3255 * @param subId The subscription to use to check the configuration.
3256 * @param c The callback that will be used to send the result.
3257 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003258 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003259 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3260 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003261 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3262 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003263
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003264 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3265 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3266 "IMS not available on device.");
3267 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003268 final long token = Binder.clearCallingIdentity();
3269 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003270 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003271 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003272 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003273 } catch (ImsException e) {
3274 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003275 } finally {
3276 Binder.restoreCallingIdentity(token);
3277 }
3278 }
3279
shilu366312e2019-12-17 09:28:10 -08003280 /**
3281 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3282 * @param subId The subscription to use to check the configuration.
3283 * @param c The callback that will be used to send the result.
3284 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003285 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003286 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003287 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3288 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003289 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3290 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3291 }
Meng Wangafbc5852019-09-19 17:37:13 -07003292 final long token = Binder.clearCallingIdentity();
3293 try {
3294 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3295 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3296 .removeRegistrationCallbackForSubscription(c, subId);
3297 } catch (ImsException e) {
3298 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3299 + "is inactive, ignoring unregister.");
3300 // If the subscription is no longer active, just return, since the callback
3301 // will already have been removed internally.
3302 } finally {
3303 Binder.restoreCallingIdentity(token);
3304 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 }
3306
Brad Ebingera34a6c22019-10-22 17:36:18 -07003307 /**
3308 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3309 */
3310 @Override
3311 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3312 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3313 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3314 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3315 "IMS not available on device.");
3316 }
3317 final long token = Binder.clearCallingIdentity();
3318 try {
3319 Phone phone = getPhone(subId);
3320 if (phone == null) {
3321 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3322 + subId + "'");
3323 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3324 }
3325 phone.getImsRegistrationState(regState -> {
3326 try {
3327 consumer.accept((regState == null)
3328 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3329 } catch (RemoteException e) {
3330 // Ignore if the remote process is no longer available to call back.
3331 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3332 }
3333 });
3334 } finally {
3335 Binder.restoreCallingIdentity(token);
3336 }
3337 }
3338
3339 /**
3340 * Get the transport type for the IMS service registration state.
3341 */
3342 @Override
3343 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003344 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3345 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003346 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3347 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3348 "IMS not available on device.");
3349 }
3350 final long token = Binder.clearCallingIdentity();
3351 try {
3352 Phone phone = getPhone(subId);
3353 if (phone == null) {
3354 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3355 + subId + "'");
3356 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3357 }
3358 phone.getImsRegistrationTech(regTech -> {
3359 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3360 int regTechConverted = (regTech == null)
3361 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3362 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3363 regTechConverted);
3364 try {
3365 consumer.accept(regTechConverted);
3366 } catch (RemoteException e) {
3367 // Ignore if the remote process is no longer available to call back.
3368 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3369 }
3370 });
3371 } finally {
3372 Binder.restoreCallingIdentity(token);
3373 }
3374 }
3375
shilu366312e2019-12-17 09:28:10 -08003376 /**
3377 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3378 * @param subId The subscription to use to check the configuration.
3379 * @param c The callback that will be used to send the result.
3380 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003381 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003382 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3383 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003384 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3385 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003386 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3387 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3388 "IMS not available on device.");
3389 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003390 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3391 final long token = Binder.clearCallingIdentity();
3392 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003393 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003394 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003395 } catch (ImsException e) {
3396 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003397 } finally {
3398 Binder.restoreCallingIdentity(token);
3399 }
3400 }
3401
shilu366312e2019-12-17 09:28:10 -08003402 /**
3403 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3404 * @param subId The subscription to use to check the configuration.
3405 * @param c The callback that will be used to send the result.
3406 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003407 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003408 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003409 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3410 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003411 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3412 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3413 }
Meng Wangafbc5852019-09-19 17:37:13 -07003414
3415 final long token = Binder.clearCallingIdentity();
3416 try {
3417 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3418 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003419 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003420 } catch (ImsException e) {
3421 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3422 + "is inactive, ignoring unregister.");
3423 // If the subscription is no longer active, just return, since the callback
3424 // will already have been removed internally.
3425 } finally {
3426 Binder.restoreCallingIdentity(token);
3427 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003428 }
3429
3430 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003431 public boolean isCapable(int subId, int capability, int regTech) {
3432 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003433 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3434 final long token = Binder.clearCallingIdentity();
3435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003436 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003437 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003438 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3440 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003441 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003442 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3443 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003444 } finally {
3445 Binder.restoreCallingIdentity(token);
3446 }
3447 }
3448
3449 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003450 public boolean isAvailable(int subId, int capability, int regTech) {
3451 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003452 final long token = Binder.clearCallingIdentity();
3453 try {
3454 Phone phone = getPhone(subId);
3455 if (phone == null) return false;
3456 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003457 } catch (com.android.ims.ImsException e) {
3458 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3459 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003460 } finally {
3461 Binder.restoreCallingIdentity(token);
3462 }
3463 }
3464
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003465 /**
3466 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3467 * subscription.
3468 * @param subId The subscription to use to check the configuration.
3469 * @param callback The callback that will be used to send the result.
3470 * @param capability The MmTelFeature capability that will be used to send the result.
3471 * @param transportType The transport type of the MmTelFeature capability.
3472 */
3473 @Override
3474 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3475 int transportType) {
3476 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3477 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3478 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3479 "IMS not available on device.");
3480 }
3481 final long token = Binder.clearCallingIdentity();
3482 try {
3483 int slotId = getSlotIndex(subId);
3484 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3485 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3486 + subId + "'");
3487 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3488 }
3489 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3490 transportType, aBoolean -> {
3491 try {
3492 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3493 } catch (RemoteException e) {
3494 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3495 + "running. Ignore");
3496 }
3497 });
3498 } finally {
3499 Binder.restoreCallingIdentity(token);
3500 }
3501 }
3502
shilu366312e2019-12-17 09:28:10 -08003503 /**
3504 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3505 * @param subId The subscription to use to check the configuration.
3506 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003507 @Override
3508 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003509 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3510 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003511
Brad Ebinger35c841c2018-10-01 10:40:55 -07003512 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3513 final long token = Binder.clearCallingIdentity();
3514 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003515 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003516 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003517 } catch (ImsException e) {
3518 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003519 } finally {
3520 Binder.restoreCallingIdentity(token);
3521 }
3522 }
3523
3524 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003525 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003527 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003528 final long identity = Binder.clearCallingIdentity();
3529 try {
3530 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003531 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003533 } catch (ImsException e) {
3534 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003535 } finally {
3536 Binder.restoreCallingIdentity(identity);
3537 }
3538 }
3539
shilu366312e2019-12-17 09:28:10 -08003540 /**
3541 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3542 * @param subId The subscription to use to check the configuration.
3543 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003544 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003545 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003546 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3547 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003551 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3552 } catch (ImsException e) {
3553 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 } finally {
3555 Binder.restoreCallingIdentity(identity);
3556 }
3557 }
3558
3559 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003560 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003561 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003562 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003563 final long identity = Binder.clearCallingIdentity();
3564 try {
3565 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003566 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003567 } catch (ImsException e) {
3568 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 } finally {
3570 Binder.restoreCallingIdentity(identity);
3571 }
3572 }
3573
shilu366312e2019-12-17 09:28:10 -08003574 /**
3575 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3576 * @param subId The subscription to use to check the configuration.
3577 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003578 @Override
3579 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003580 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3581 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003582 final long identity = Binder.clearCallingIdentity();
3583 try {
3584 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003585 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003586 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
3594 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003595 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003597 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 final long identity = Binder.clearCallingIdentity();
3599 try {
3600 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003601 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003602 } catch (ImsException e) {
3603 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 } finally {
3605 Binder.restoreCallingIdentity(identity);
3606 }
3607 }
3608
shilu366312e2019-12-17 09:28:10 -08003609 /**
3610 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3611 * @param subId The subscription to use to check the configuration.
3612 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003613 @Override
3614 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003615 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3616 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003617 final long identity = Binder.clearCallingIdentity();
3618 try {
3619 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003620 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003621 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003622 } catch (ImsException e) {
3623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
3629 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003630 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003631 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003632 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 final long identity = Binder.clearCallingIdentity();
3634 try {
3635 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003636 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003638 } catch (ImsException e) {
3639 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003640 } finally {
3641 Binder.restoreCallingIdentity(identity);
3642 }
3643 }
3644
3645 @Override
3646 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3647 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3648 "setVoWiFiNonPersistent");
3649 final long identity = Binder.clearCallingIdentity();
3650 try {
3651 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003652 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003653 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003654 } catch (ImsException e) {
3655 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003656 } finally {
3657 Binder.restoreCallingIdentity(identity);
3658 }
3659 }
3660
shilu366312e2019-12-17 09:28:10 -08003661 /**
3662 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3663 * @param subId The subscription to use to check the configuration.
3664 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003665 @Override
3666 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003667 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3668 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003673 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (ImsException e) {
3675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
3681 @Override
3682 public void setVoWiFiModeSetting(int subId, int mode) {
3683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3684 "setVoWiFiModeSetting");
3685 final long identity = Binder.clearCallingIdentity();
3686 try {
3687 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003688 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003690 } catch (ImsException e) {
3691 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003692 } finally {
3693 Binder.restoreCallingIdentity(identity);
3694 }
3695 }
3696
3697 @Override
3698 public int getVoWiFiRoamingModeSetting(int subId) {
3699 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3700 final long identity = Binder.clearCallingIdentity();
3701 try {
3702 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003703 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003704 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003705 } catch (ImsException e) {
3706 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003707 } finally {
3708 Binder.restoreCallingIdentity(identity);
3709 }
3710 }
3711
3712 @Override
3713 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3714 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3715 "setVoWiFiRoamingModeSetting");
3716 final long identity = Binder.clearCallingIdentity();
3717 try {
3718 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003719 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003720 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003721 } catch (ImsException e) {
3722 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003723 } finally {
3724 Binder.restoreCallingIdentity(identity);
3725 }
3726 }
3727
3728 @Override
3729 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3730 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3731 "setRttCapabilityEnabled");
3732 final long identity = Binder.clearCallingIdentity();
3733 try {
3734 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003735 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3736 } catch (ImsException e) {
3737 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003738 } finally {
3739 Binder.restoreCallingIdentity(identity);
3740 }
3741 }
3742
shilu366312e2019-12-17 09:28:10 -08003743 /**
3744 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3745 * @param subId The subscription to use to check the configuration.
3746 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003747 @Override
3748 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003749 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3750 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003751 final long identity = Binder.clearCallingIdentity();
3752 try {
3753 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003754 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003755 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003763 @Override
3764 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3765 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3766 final long identity = Binder.clearCallingIdentity();
3767 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003768 if (!isImsAvailableOnDevice()) {
3769 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3770 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003771 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003772 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003773 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003774 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003775 } catch (ImsException e) {
3776 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003777 } finally {
3778 Binder.restoreCallingIdentity(identity);
3779 }
3780 }
3781
3782 @Override
3783 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3784 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3785 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003786 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3787 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3788 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003789 try {
3790 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003791 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003792 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003793 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003794 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3795 + "is inactive, ignoring unregister.");
3796 // If the subscription is no longer active, just return, since the callback will already
3797 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003798 } finally {
3799 Binder.restoreCallingIdentity(identity);
3800 }
3801 }
3802
allenwtsu99c623b2020-01-03 18:24:23 +08003803
3804 private void checkModifyPhoneStatePermission(int subId, String message) {
3805 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3806 message);
3807 }
3808
3809 private boolean isImsProvisioningRequired(int subId, int capability,
3810 boolean isMmtelCapability) {
3811 Phone phone = getPhone(subId);
3812 if (phone == null) {
3813 loge("phone instance null for subid " + subId);
3814 return false;
3815 }
3816 if (isMmtelCapability) {
3817 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3818 return false;
3819 }
3820 } else {
3821 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3822 return false;
3823 }
3824 }
3825 return true;
3826 }
3827
3828 @Override
3829 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3830 boolean isProvisioned) {
3831 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3832
3833 final long identity = Binder.clearCallingIdentity();
3834 try {
3835 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3836 if (!isImsProvisioningRequired(subId, capability, false)) {
3837 return;
3838 }
3839
3840 // this capability requires provisioning, route to the correct API.
3841 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3842 switch (capability) {
3843 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3844 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3845 ims.setEabProvisioned(isProvisioned);
3846 break;
3847 default: {
3848 throw new IllegalArgumentException("Tried to set provisioning for "
3849 + "rcs capability '" + capability + "', which does not require "
3850 + "provisioning.");
3851 }
3852 }
3853 } finally {
3854 Binder.restoreCallingIdentity(identity);
3855 }
3856
3857 }
3858
3859
3860 @Override
3861 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3862 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3863 final long identity = Binder.clearCallingIdentity();
3864 try {
3865 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3866 if (!isImsProvisioningRequired(subId, capability, false)) {
3867 return true;
3868 }
3869
3870 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3871 switch (capability) {
3872 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3873 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3874 return ims.isEabProvisionedOnDevice();
3875
3876 default: {
3877 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3878 + "capability '" + capability + "', which does not require "
3879 + "provisioning.");
3880 }
3881 }
3882
3883 } finally {
3884 Binder.restoreCallingIdentity(identity);
3885 }
3886 }
3887
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003888 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003889 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3890 boolean isProvisioned) {
3891 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3892 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3893 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3894 }
allenwtsu99c623b2020-01-03 18:24:23 +08003895 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003896 final long identity = Binder.clearCallingIdentity();
3897 try {
3898 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003899 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003900 return;
3901 }
3902
3903 // this capability requires provisioning, route to the correct API.
3904 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3905 switch (capability) {
3906 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3907 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3908 ims.setVolteProvisioned(isProvisioned);
3909 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3910 ims.setWfcProvisioned(isProvisioned);
3911 }
3912 break;
3913 }
3914 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3915 // There is currently no difference in VT provisioning type.
3916 ims.setVtProvisioned(isProvisioned);
3917 break;
3918 }
3919 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3920 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3921 // change the capability of the feature instead if needed.
3922 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3923 == isProvisioned) {
3924 // No change in provisioning.
3925 return;
3926 }
3927 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3928 try {
3929 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003930 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003931 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3932 + ", Exception" + e.getMessage());
3933 }
3934 break;
3935 }
3936 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003937 throw new IllegalArgumentException("Tried to set provisioning for "
3938 + "MmTel capability '" + capability + "', which does not require "
3939 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003940 }
3941 }
3942
3943 } finally {
3944 Binder.restoreCallingIdentity(identity);
3945 }
3946 }
3947
3948 @Override
3949 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3950 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3951 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3952 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3953 }
3954 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3955 final long identity = Binder.clearCallingIdentity();
3956 try {
3957 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003958 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003959 return true;
3960 }
3961
3962 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3963 switch (capability) {
3964 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3965 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3966 return ims.isVolteProvisionedOnDevice();
3967 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3968 return ims.isWfcProvisionedOnDevice();
3969 }
3970 // This should never happen, since we are checking tech above to make sure it
3971 // is either LTE or IWLAN.
3972 throw new IllegalArgumentException("Invalid radio technology for voice "
3973 + "capability.");
3974 }
3975 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3976 // There is currently no difference in VT provisioning type.
3977 return ims.isVtProvisionedOnDevice();
3978 }
3979 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3980 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3981 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3982 }
3983 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003984 throw new IllegalArgumentException(
3985 "Tried to get provisioning for MmTel capability '" + capability
3986 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003987 }
3988 }
3989
3990 } finally {
3991 Binder.restoreCallingIdentity(identity);
3992 }
3993 }
3994
3995 @Override
3996 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
3997 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3998 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3999 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4000 }
4001 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4002 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4003 return (provisionedBits & capability) > 0;
4004 }
4005
4006 @Override
4007 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4008 boolean isProvisioned) {
4009 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4010 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4011 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4012 }
4013 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4014 "setProvisioningStatusForCapability");
4015 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4016 // If the current provisioning status for capability already matches isProvisioned,
4017 // do nothing.
4018 if (((provisionedBits & capability) > 0) == isProvisioned) {
4019 return;
4020 }
4021 if (isProvisioned) {
4022 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4023 } else {
4024 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4025 }
4026 }
4027
4028 /**
4029 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4030 * technology. The bitfield should mirror the bitfield defined by
4031 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4032 */
4033 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4034 String key = getMmTelProvisioningKey(subId, tech);
4035 // Default is no capabilities are provisioned.
4036 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4037 }
4038
4039 /**
4040 * Sets the MmTel capability provisioning bitfield (defined by
4041 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4042 * technology specified.
4043 *
4044 * Note: This is a synchronous command and should not be called on UI thread.
4045 */
4046 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4047 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4048 String key = getMmTelProvisioningKey(subId, tech);
4049 editor.putInt(key, newField);
4050 editor.commit();
4051 }
4052
4053 private static String getMmTelProvisioningKey(int subId, int tech) {
4054 // resulting key is provision_ims_mmtel_{subId}_{tech}
4055 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4056 }
4057
4058 /**
4059 * Query CarrierConfig to see if the specified capability requires provisioning for the
4060 * carrier associated with the subscription id.
4061 */
4062 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4063 int capability) {
4064 CarrierConfigManager configManager = new CarrierConfigManager(context);
4065 PersistableBundle c = configManager.getConfigForSubId(subId);
4066 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004067 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004068 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4069 false);
4070 boolean requireVoiceVtProvisioning = c.getBoolean(
4071 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4072
4073 // First check to make sure that the capability requires provisioning.
4074 switch (capability) {
4075 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4076 // intentional fallthrough
4077 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4078 if (requireVoiceVtProvisioning) {
4079 // Voice and Video requires provisioning
4080 return true;
4081 }
4082 break;
4083 }
4084 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4085 if (requireUtProvisioning) {
4086 // UT requires provisioning
4087 return true;
4088 }
4089 break;
4090 }
4091 }
4092 return false;
4093 }
4094
allenwtsu99c623b2020-01-03 18:24:23 +08004095 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4096 int capability) {
4097 CarrierConfigManager configManager = new CarrierConfigManager(context);
4098 PersistableBundle c = configManager.getConfigForSubId(subId);
4099
4100 boolean requireRcsProvisioning = c.getBoolean(
4101 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4102
4103 // First check to make sure that the capability requires provisioning.
4104 switch (capability) {
4105 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4106 // intentional fallthrough
4107 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4108 if (requireRcsProvisioning) {
4109 // OPTION or PRESENCE requires provisioning
4110 return true;
4111 }
4112 break;
4113 }
4114 }
4115 return false;
4116 }
4117
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004118 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004119 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004120 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4121 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4122 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004123 enforceReadPrivilegedPermission("getImsProvisioningInt");
4124 final long identity = Binder.clearCallingIdentity();
4125 try {
4126 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004127 int slotId = getSlotIndex(subId);
4128 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4129 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4130 + subId + "' for key:" + key);
4131 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4132 }
4133 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004134 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004135 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4136 + subId + "' for key:" + key);
4137 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004138 } finally {
4139 Binder.restoreCallingIdentity(identity);
4140 }
4141 }
4142
4143 @Override
4144 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004145 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4146 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4147 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004148 enforceReadPrivilegedPermission("getImsProvisioningString");
4149 final long identity = Binder.clearCallingIdentity();
4150 try {
4151 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004152 int slotId = getSlotIndex(subId);
4153 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4154 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4155 + subId + "' for key:" + key);
4156 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4157 }
4158 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004159 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004160 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4161 + subId + "' for key:" + key);
4162 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004163 } finally {
4164 Binder.restoreCallingIdentity(identity);
4165 }
4166 }
4167
4168 @Override
4169 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004170 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4171 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4172 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004173 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4174 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004175 final long identity = Binder.clearCallingIdentity();
4176 try {
4177 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004178 int slotId = getSlotIndex(subId);
4179 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4180 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4181 + subId + "' for key:" + key);
4182 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4183 }
4184 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004185 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004186 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4187 + "' for key:" + key);
4188 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004189 } finally {
4190 Binder.restoreCallingIdentity(identity);
4191 }
4192 }
4193
4194 @Override
4195 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004196 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4197 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4198 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004199 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4200 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004201 final long identity = Binder.clearCallingIdentity();
4202 try {
4203 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004204 int slotId = getSlotIndex(subId);
4205 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4206 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4207 + subId + "' for key:" + key);
4208 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4209 }
4210 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004211 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004212 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4213 + "' for key:" + key);
4214 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004215 } finally {
4216 Binder.restoreCallingIdentity(identity);
4217 }
4218 }
4219
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004220 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004221 int slotId = SubscriptionManager.getSlotIndex(subId);
4222 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004223 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4224 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004225 }
4226 return slotId;
4227 }
4228
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004229 private int getSlotIndex(int subId) {
4230 int slotId = SubscriptionManager.getSlotIndex(subId);
4231 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4232 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4233 }
4234 return slotId;
4235 }
4236
Wink Saville36469e72014-06-11 15:17:00 -07004237 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004238 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004239 */
4240 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004241 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4242 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004243 final int targetSdk = getTargetSdk(callingPackage);
4244 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004245 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004246 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004247 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004248 mApp, subId, callingPackage, callingFeatureId,
4249 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004250 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4251 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004252
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004253 final long identity = Binder.clearCallingIdentity();
4254 try {
4255 final Phone phone = getPhone(subId);
4256 if (phone != null) {
4257 return phone.getServiceState().getDataNetworkType();
4258 } else {
4259 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4260 }
4261 } finally {
4262 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004263 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004264 }
4265
4266 /**
4267 * Returns the data network type
4268 */
4269 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004270 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4271 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4272 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004273 }
4274
4275 /**
4276 * Returns the data network type for a subId
4277 */
4278 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004279 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4280 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004281 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004282 mApp, subId, callingPackage, callingFeatureId,
4283 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004284 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4285 }
4286
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004287 final long identity = Binder.clearCallingIdentity();
4288 try {
4289 final Phone phone = getPhone(subId);
4290 if (phone != null) {
4291 return phone.getServiceState().getDataNetworkType();
4292 } else {
4293 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4294 }
4295 } finally {
4296 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004297 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004298 }
4299
4300 /**
Wink Saville36469e72014-06-11 15:17:00 -07004301 * Returns the Voice network type for a subId
4302 */
4303 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004304 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4305 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004306 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004307 mApp, subId, callingPackage, callingFeatureId,
4308 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004309 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4310 }
4311
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004312 final long identity = Binder.clearCallingIdentity();
4313 try {
4314 final Phone phone = getPhone(subId);
4315 if (phone != null) {
4316 return phone.getServiceState().getVoiceNetworkType();
4317 } else {
4318 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4319 }
4320 } finally {
4321 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004322 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004323 }
4324
4325 /**
4326 * @return true if a ICC card is present
4327 */
4328 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004329 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004330 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4331 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004332 }
4333
4334 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004335 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004336 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004337 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004338 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004339 final long identity = Binder.clearCallingIdentity();
4340 try {
4341 final Phone phone = PhoneFactory.getPhone(slotIndex);
4342 if (phone != null) {
4343 return phone.getIccCard().hasIccCard();
4344 } else {
4345 return false;
4346 }
4347 } finally {
4348 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004349 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004350 }
4351
4352 /**
4353 * Return if the current radio is LTE on CDMA. This
4354 * is a tri-state return value as for a period of time
4355 * the mode may be unknown.
4356 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004357 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004358 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004359 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004360 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004361 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004362 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4363 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4364 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004365 }
4366
Sanket Padawe356d7632015-06-22 14:03:32 -07004367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4369 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004370 try {
4371 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4372 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004373 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4374 }
4375
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004376 final long identity = Binder.clearCallingIdentity();
4377 try {
4378 final Phone phone = getPhone(subId);
4379 if (phone == null) {
4380 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4381 } else {
4382 return phone.getLteOnCdmaMode();
4383 }
4384 } finally {
4385 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004386 }
Wink Saville36469e72014-06-11 15:17:00 -07004387 }
4388
Wink Saville36469e72014-06-11 15:17:00 -07004389 /**
4390 * {@hide}
4391 * Returns Default subId, 0 in the case of single standby.
4392 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004393 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004394 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004395 }
4396
Shishir Agrawala9f32182016-04-12 12:00:16 -07004397 private int getSlotForDefaultSubscription() {
4398 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4399 }
4400
Wink Savilleb564aae2014-10-23 10:18:09 -07004401 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004402 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004403 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004404
Pengquan Menge92a50d2018-09-21 15:54:48 -07004405 private boolean isActiveSubscription(int subId) {
4406 return mSubscriptionController.isActiveSubId(subId);
4407 }
4408
Ihab Awadf2177b72013-11-25 13:33:23 -08004409 /**
4410 * @see android.telephony.TelephonyManager.WifiCallingChoices
4411 */
4412 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004413 final long identity = Binder.clearCallingIdentity();
4414 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004415 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004416 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4417 getWhenToMakeWifiCallsDefaultPreference());
4418 } finally {
4419 Binder.restoreCallingIdentity(identity);
4420 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004421 }
4422
4423 /**
4424 * @see android.telephony.TelephonyManager.WifiCallingChoices
4425 */
4426 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004427 final long identity = Binder.clearCallingIdentity();
4428 try {
4429 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004430 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004431 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4432 } finally {
4433 Binder.restoreCallingIdentity(identity);
4434 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004435 }
4436
Sailesh Nepald1e68152013-12-12 19:08:02 -08004437 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004438 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004439 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004440 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004441
Jordan Liu4c733742019-02-28 12:03:40 -08004442 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4443 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4444 if (phoneId == -1) {
4445 throw new IllegalArgumentException("Given slot index: " + slotIndex
4446 + " does not correspond to an active phone");
4447 }
4448 return PhoneFactory.getPhone(phoneId);
4449 }
4450
Shishir Agrawal566b7612013-10-28 14:41:00 -07004451 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004452 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4453 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004454 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4455 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004456 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004457 if (DBG) {
4458 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4459 }
4460 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4461 p2);
4462 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004463
Jordan Liu4c733742019-02-28 12:03:40 -08004464
4465 @Override
4466 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4467 int slotIndex, String callingPackage, String aid, int p2) {
4468 enforceModifyPermission();
4469 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4470 if (DBG) {
4471 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4472 }
4473 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4474 callingPackage, aid, p2);
4475 }
4476
4477 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4478 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004479 final long identity = Binder.clearCallingIdentity();
4480 try {
4481 if (TextUtils.equals(ISDR_AID, aid)) {
4482 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004483 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4484 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 if (bestComponent == null
4486 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4487 loge("The calling package is not allowed to access ISD-R.");
4488 throw new SecurityException(
4489 "The calling package is not allowed to access ISD-R.");
4490 }
Derek Tan740e1672017-06-27 14:56:27 -07004491 }
Derek Tan740e1672017-06-27 14:56:27 -07004492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004493 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004494 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4495 null /* workSource */);
4496 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004497 return response;
4498 } finally {
4499 Binder.restoreCallingIdentity(identity);
4500 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004501 }
4502
4503 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004504 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004505 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4506 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004507 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4508 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4509 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004510
Jordan Liu4c733742019-02-28 12:03:40 -08004511 @Override
4512 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4513 enforceModifyPermission();
4514 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4515 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4516 channel);
4517 }
4518
4519 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004520 final long identity = Binder.clearCallingIdentity();
4521 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004522 if (channel < 0) {
4523 return false;
4524 }
Jordan Liu4c733742019-02-28 12:03:40 -08004525 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4526 null /* workSource */);
4527 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 return success;
4529 } finally {
4530 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004531 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004532 }
4533
4534 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004535 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004536 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004537 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4538 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004539 if (DBG) {
4540 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4541 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4542 + p3 + " data=" + data);
4543 }
4544 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4545 command, p1, p2, p3, data);
4546 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004547
Jordan Liu4c733742019-02-28 12:03:40 -08004548 @Override
4549 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4550 int command, int p1, int p2, int p3, String data) {
4551 enforceModifyPermission();
4552 if (DBG) {
4553 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4554 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4555 + p3 + " data=" + data);
4556 }
4557 return iccTransmitApduLogicalChannelWithPermission(
4558 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4559 data);
4560 }
4561
4562 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4563 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004564 final long identity = Binder.clearCallingIdentity();
4565 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004566 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004567 return "";
4568 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004571 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4572 null /* workSource */);
4573 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004574
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004575 // Append the returned status code to the end of the response payload.
4576 String s = Integer.toHexString(
4577 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4578 if (response.payload != null) {
4579 s = IccUtils.bytesToHexString(response.payload) + s;
4580 }
4581 return s;
4582 } finally {
4583 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004584 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004585 }
Jake Hambye994d462014-02-03 13:10:13 -08004586
Evan Charltonc66da362014-05-16 14:06:40 -07004587 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004588 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4589 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004590 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4591 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004592 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004593 if (DBG) {
4594 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4595 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4596 }
4597 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4598 cla, command, p1, p2, p3, data);
4599 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004600
Jordan Liu4c733742019-02-28 12:03:40 -08004601 @Override
4602 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4603 int command, int p1, int p2, int p3, String data) {
4604 enforceModifyPermission();
4605 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4606 if (DBG) {
4607 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4608 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4609 + " data=" + data);
4610 }
4611
4612 return iccTransmitApduBasicChannelWithPermission(
4613 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4614 p2, p3, data);
4615 }
4616
4617 // open APDU basic channel assuming the caller has sufficient permissions
4618 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4619 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004620 final long identity = Binder.clearCallingIdentity();
4621 try {
4622 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4623 && TextUtils.equals(ISDR_AID, data)) {
4624 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004625 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4626 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004627 if (bestComponent == null
4628 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4629 loge("The calling package is not allowed to select ISD-R.");
4630 throw new SecurityException(
4631 "The calling package is not allowed to select ISD-R.");
4632 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004633 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004634
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004635 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004636 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4637 null /* workSource */);
4638 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004639
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004640 // Append the returned status code to the end of the response payload.
4641 String s = Integer.toHexString(
4642 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4643 if (response.payload != null) {
4644 s = IccUtils.bytesToHexString(response.payload) + s;
4645 }
4646 return s;
4647 } finally {
4648 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004649 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004650 }
4651
4652 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004653 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004654 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004655 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4656 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004657
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004658 final long identity = Binder.clearCallingIdentity();
4659 try {
4660 if (DBG) {
4661 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4662 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4663 }
4664
4665 IccIoResult response =
4666 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4667 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4668 subId);
4669
4670 if (DBG) {
4671 log("Exchange SIM_IO [R]" + response);
4672 }
4673
4674 byte[] result = null;
4675 int length = 2;
4676 if (response.payload != null) {
4677 length = 2 + response.payload.length;
4678 result = new byte[length];
4679 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4680 } else {
4681 result = new byte[length];
4682 }
4683
4684 result[length - 1] = (byte) response.sw2;
4685 result[length - 2] = (byte) response.sw1;
4686 return result;
4687 } finally {
4688 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004689 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004690 }
4691
Nathan Haroldb3014052017-01-25 15:57:32 -08004692 /**
4693 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4694 * on a particular subscription
4695 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004696 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4697 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004698 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004699 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004700 return null;
4701 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004702
4703 final long identity = Binder.clearCallingIdentity();
4704 try {
4705 if (appType != TelephonyManager.APPTYPE_USIM
4706 && appType != TelephonyManager.APPTYPE_SIM) {
4707 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4708 return null;
4709 }
4710 Object response = sendRequest(
4711 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4712 if (response instanceof String[]) {
4713 return (String[]) response;
4714 }
yincheng zhao2737e882019-09-06 17:06:54 -07004715 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004716 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004717 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004718 } finally {
4719 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004720 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004721 }
4722
yincheng zhao2737e882019-09-06 17:06:54 -07004723 /**
4724 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4725 * subscription.
4726 *
4727 * @param subId the id of the subscription.
4728 * @param appType the uicc app type, must be USIM or SIM.
4729 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4730 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004731 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004732 * @return number of fplmns that is successfully written to the SIM.
4733 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004734 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4735 String callingFeatureId) {
4736 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4737 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004738 if (DBG) logv("no permissions for setForbiddenplmns");
4739 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4740 }
4741 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4742 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4743 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4744 }
4745 if (fplmns == null) {
4746 throw new IllegalArgumentException("Fplmn List provided is null");
4747 }
4748 for (String fplmn : fplmns) {
4749 if (!CellIdentity.isValidPlmn(fplmn)) {
4750 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4751 }
4752 }
4753 final long identity = Binder.clearCallingIdentity();
4754 try {
4755 Object response = sendRequest(
4756 CMD_SET_FORBIDDEN_PLMNS,
4757 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4758 subId);
4759 return (int) response;
4760 } finally {
4761 Binder.restoreCallingIdentity(identity);
4762 }
4763 }
4764
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004765 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004766 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004767 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4768 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004769
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004770 final long identity = Binder.clearCallingIdentity();
4771 try {
4772 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4773 if (response.payload == null) {
4774 return "";
4775 }
Evan Charltonc66da362014-05-16 14:06:40 -07004776
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004777 // Append the returned status code to the end of the response payload.
4778 String s = Integer.toHexString(
4779 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4780 s = IccUtils.bytesToHexString(response.payload) + s;
4781 return s;
4782 } finally {
4783 Binder.restoreCallingIdentity(identity);
4784 }
Evan Charltonc66da362014-05-16 14:06:40 -07004785 }
4786
Jake Hambye994d462014-02-03 13:10:13 -08004787 /**
4788 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4789 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4790 *
4791 * @param itemID the ID of the item to read
4792 * @return the NV item as a String, or null on error.
4793 */
4794 @Override
4795 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004796 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004797 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4798 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004799
4800 final long identity = Binder.clearCallingIdentity();
4801 try {
4802 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004803 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004804 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4805 return value;
4806 } finally {
4807 Binder.restoreCallingIdentity(identity);
4808 }
Jake Hambye994d462014-02-03 13:10:13 -08004809 }
4810
4811 /**
4812 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4813 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4814 *
4815 * @param itemID the ID of the item to read
4816 * @param itemValue the value to write, as a String
4817 * @return true on success; false on any failure
4818 */
4819 @Override
4820 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004821 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4823 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004824
4825 final long identity = Binder.clearCallingIdentity();
4826 try {
4827 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4828 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004829 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4831 return success;
4832 } finally {
4833 Binder.restoreCallingIdentity(identity);
4834 }
Jake Hambye994d462014-02-03 13:10:13 -08004835 }
4836
4837 /**
4838 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4839 * Used for device configuration by some CDMA operators.
4840 *
4841 * @param preferredRoamingList byte array containing the new PRL
4842 * @return true on success; false on any failure
4843 */
4844 @Override
4845 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004846 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4847 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004848
4849 final long identity = Binder.clearCallingIdentity();
4850 try {
4851 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4852 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4853 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4854 return success;
4855 } finally {
4856 Binder.restoreCallingIdentity(identity);
4857 }
Jake Hambye994d462014-02-03 13:10:13 -08004858 }
4859
4860 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004861 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004862 * Used for device configuration by some CDMA operators.
4863 *
chen xu6dac5ab2018-10-26 17:39:23 -07004864 * @param slotIndex - device slot.
4865 *
Jake Hambye994d462014-02-03 13:10:13 -08004866 * @return true on success; false on any failure
4867 */
4868 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004869 public boolean resetModemConfig(int slotIndex) {
4870 Phone phone = PhoneFactory.getPhone(slotIndex);
4871 if (phone != null) {
4872 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4873 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004874
chen xu6dac5ab2018-10-26 17:39:23 -07004875 final long identity = Binder.clearCallingIdentity();
4876 try {
4877 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4878 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4879 return success;
4880 } finally {
4881 Binder.restoreCallingIdentity(identity);
4882 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004883 }
chen xu6dac5ab2018-10-26 17:39:23 -07004884 return false;
4885 }
4886
4887 /**
4888 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4889 *
4890 * @param slotIndex - device slot.
4891 *
4892 * @return true on success; false on any failure
4893 */
4894 @Override
4895 public boolean rebootModem(int slotIndex) {
4896 Phone phone = PhoneFactory.getPhone(slotIndex);
4897 if (phone != null) {
4898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4899 mApp, phone.getSubId(), "rebootModem");
4900
4901 final long identity = Binder.clearCallingIdentity();
4902 try {
4903 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4904 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4905 return success;
4906 } finally {
4907 Binder.restoreCallingIdentity(identity);
4908 }
4909 }
4910 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004911 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004912
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004913 public String[] getPcscfAddress(String apnType, String callingPackage,
4914 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004915 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004916 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4917 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004918 return new String[0];
4919 }
4920
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004921 final long identity = Binder.clearCallingIdentity();
4922 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004923 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004924 } finally {
4925 Binder.restoreCallingIdentity(identity);
4926 }
Wink Saville36469e72014-06-11 15:17:00 -07004927 }
4928
Brad Ebinger51f743a2017-01-23 13:50:20 -08004929 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004930 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4931 * {@link #disableIms(int)}.
4932 * @param slotIndex device slot.
4933 */
4934 public void resetIms(int slotIndex) {
4935 enforceModifyPermission();
4936
4937 final long identity = Binder.clearCallingIdentity();
4938 try {
4939 if (mImsResolver == null) {
4940 // may happen if the does not support IMS.
4941 return;
4942 }
4943 mImsResolver.disableIms(slotIndex);
4944 mImsResolver.enableIms(slotIndex);
4945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
4948 }
4949
4950 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004951 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4952 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004953 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004954 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004955 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004956
4957 final long identity = Binder.clearCallingIdentity();
4958 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004959 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004960 // may happen if the device does not support IMS.
4961 return;
4962 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004963 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004964 } finally {
4965 Binder.restoreCallingIdentity(identity);
4966 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004967 }
4968
4969 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004970 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4971 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004972 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004973 public void disableIms(int slotId) {
4974 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004975
4976 final long identity = Binder.clearCallingIdentity();
4977 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004978 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004979 // may happen if the device does not support IMS.
4980 return;
4981 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004982 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004983 } finally {
4984 Binder.restoreCallingIdentity(identity);
4985 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004986 }
4987
4988 /**
4989 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4990 * feature or {@link null} if the service is not available. If the feature is available, the
4991 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4992 */
4993 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08004994 IImsServiceFeatureCallback callback) {
4995 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 // may happen if the device does not support IMS.
5001 return null;
5002 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005003 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005007 }
5008
5009 /**
5010 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5011 * feature during emergency calling or {@link null} if the service is not available. If the
5012 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5013 * listener for feature updates.
5014 */
5015 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005020 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 // may happen if the device does not support IMS.
5022 return null;
5023 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005024 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005028 }
5029
Brad Ebinger5f64b052017-12-14 14:26:15 -08005030 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005031 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5032 */
5033 public void unregisterImsFeatureCallback(int slotId, int featureType,
5034 IImsServiceFeatureCallback callback) {
5035 enforceModifyPermission();
5036
5037 final long identity = Binder.clearCallingIdentity();
5038 try {
5039 if (mImsResolver == null) return;
5040 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5041 } finally {
5042 Binder.restoreCallingIdentity(identity);
5043 }
5044 }
5045
5046 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005047 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005048 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005049 */
5050 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5051 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005052
5053 final long identity = Binder.clearCallingIdentity();
5054 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005055 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005056 // may happen if the device does not support IMS.
5057 return null;
5058 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005059 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005060 } finally {
5061 Binder.restoreCallingIdentity(identity);
5062 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005063 }
5064
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005065 /**
5066 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005067 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005068 */
5069 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5070 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005071
5072 final long identity = Binder.clearCallingIdentity();
5073 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005074 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005075 // may happen if the device does not support IMS.
5076 return null;
5077 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005078 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005079 } finally {
5080 Binder.restoreCallingIdentity(identity);
5081 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005082 }
5083
Brad Ebinger884c07b2018-02-15 16:17:40 -08005084 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005085 * Sets the ImsService Package Name that Telephony will bind to.
5086 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005087 * @param slotIndex the slot ID that the ImsService should bind for.
5088 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005089 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005090 * @param featureTypes An integer array of feature types associated with a packageName.
5091 * @param packageName The name of the package that the current configuration will be replaced
5092 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005093 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005094 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005095 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5096 int[] featureTypes, String packageName) {
5097 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5098 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005099 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5100 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005101 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005102
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005103 final long identity = Binder.clearCallingIdentity();
5104 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005105 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005106 // may happen if the device does not support IMS.
5107 return false;
5108 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005109 Map<Integer, String> featureConfig = new HashMap<>();
5110 for (int featureType : featureTypes) {
5111 featureConfig.put(featureType, packageName);
5112 }
5113 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5114 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005115 } finally {
5116 Binder.restoreCallingIdentity(identity);
5117 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005118 }
5119
5120 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005121 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005122 *
5123 * @param slotId The slot that the ImsService is associated with.
5124 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5125 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005126 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005127 * @return the package name of the ImsService configuration.
5128 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005129 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5130 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005131 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005132 TelephonyPermissions
5133 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5134 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5135 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005136
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005137 final long identity = Binder.clearCallingIdentity();
5138 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005139 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005140 // may happen if the device does not support IMS.
5141 return "";
5142 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005143 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005144 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5145 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005146 } finally {
5147 Binder.restoreCallingIdentity(identity);
5148 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005149 }
5150
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005151 /**
5152 * Get the MmTelFeature state associated with the requested subscription id.
5153 * @param subId The subscription that the MmTelFeature is associated with.
5154 * @param callback A callback with an integer containing the
5155 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5156 */
5157 @Override
5158 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5159 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5160 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5161 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5162 "IMS not available on device.");
5163 }
5164 final long token = Binder.clearCallingIdentity();
5165 try {
5166 int slotId = getSlotIndex(subId);
5167 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5168 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5169 + subId + "'");
5170 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5171 }
5172 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5173 try {
5174 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5175 } catch (RemoteException e) {
5176 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5177 + "Ignore");
5178 }
5179 });
5180 } finally {
5181 Binder.restoreCallingIdentity(token);
5182 }
5183 }
5184
Wink Saville36469e72014-06-11 15:17:00 -07005185 public void setImsRegistrationState(boolean registered) {
5186 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005187
5188 final long identity = Binder.clearCallingIdentity();
5189 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005190 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005191 } finally {
5192 Binder.restoreCallingIdentity(identity);
5193 }
Wink Saville36469e72014-06-11 15:17:00 -07005194 }
5195
5196 /**
Stuart Scott54788802015-03-30 13:18:01 -07005197 * Set the network selection mode to automatic.
5198 *
5199 */
5200 @Override
5201 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005202 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5203 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005204
5205 final long identity = Binder.clearCallingIdentity();
5206 try {
shilufc958392020-01-20 11:36:01 -08005207 if (!isActiveSubscription(subId)) {
5208 return;
5209 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5211 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Stuart Scott54788802015-03-30 13:18:01 -07005215 }
5216
Pengquan Mengea84e042018-09-20 14:57:26 -07005217 /**
5218 * Ask the radio to connect to the input network and change selection mode to manual.
5219 *
5220 * @param subId the id of the subscription.
5221 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5222 * the operator to attach to.
5223 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5224 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5225 * normal network selection next time.
5226 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005227 */
5228 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005229 public boolean setNetworkSelectionModeManual(
5230 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005231 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5232 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005233
5234 if (!isActiveSubscription(subId)) {
5235 return false;
5236 }
5237
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005238 final long identity = Binder.clearCallingIdentity();
5239 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005240 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005241 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005242 if (DBG) {
5243 log("setNetworkSelectionModeManual: subId: " + subId
5244 + " operator: " + operatorInfo);
5245 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005246 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5247 } finally {
5248 Binder.restoreCallingIdentity(identity);
5249 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005250 }
shilu84f6e8b2019-12-19 13:58:01 -08005251 /**
5252 * Get the manual network selection
5253 *
5254 * @param subId the id of the subscription.
5255 *
5256 * @return the previously saved user selected PLMN
5257 */
5258 @Override
5259 public String getManualNetworkSelectionPlmn(int subId) {
5260 TelephonyPermissions
5261 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5262 mApp, subId, "getManualNetworkSelectionPlmn");
5263
5264 final long identity = Binder.clearCallingIdentity();
5265 try {
5266 if (!isActiveSubscription(subId)) {
5267 return "";
5268 }
5269
5270 final Phone phone = getPhone(subId);
5271 if (phone == null) {
5272 return "";
5273 }
5274 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5275 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5276 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5277 } finally {
5278 Binder.restoreCallingIdentity(identity);
5279 }
5280 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005281
5282 /**
5283 * Scans for available networks.
5284 */
5285 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005286 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5287 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005288 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5289 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005290 LocationAccessPolicy.LocationPermissionResult locationResult =
5291 LocationAccessPolicy.checkLocationPermission(mApp,
5292 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5293 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005294 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005295 .setCallingPid(Binder.getCallingPid())
5296 .setCallingUid(Binder.getCallingUid())
5297 .setMethod("getCellNetworkScanResults")
5298 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5299 .build());
5300 switch (locationResult) {
5301 case DENIED_HARD:
5302 throw new SecurityException("Not allowed to access scan results -- location");
5303 case DENIED_SOFT:
5304 return null;
5305 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005306
Pengquan Menga1bb6272018-09-06 09:59:22 -07005307 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005308 try {
5309 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005310 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005311 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005312 } finally {
5313 Binder.restoreCallingIdentity(identity);
5314 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005315 }
5316
5317 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005318 * Get the call forwarding info, given the call forwarding reason.
5319 */
5320 @Override
5321 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5322 enforceReadPrivilegedPermission("getCallForwarding");
5323 long identity = Binder.clearCallingIdentity();
5324 try {
5325 if (DBG) {
5326 log("getCallForwarding: subId " + subId
5327 + " callForwardingReason" + callForwardingReason);
5328 }
5329 return (CallForwardingInfo) sendRequest(
5330 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5331 } finally {
5332 Binder.restoreCallingIdentity(identity);
5333 }
5334 }
5335
5336 /**
5337 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5338 * reason, the number to forward, and the timeout before the forwarding is attempted.
5339 */
5340 @Override
5341 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5342 enforceModifyPermission();
5343 long identity = Binder.clearCallingIdentity();
5344 try {
5345 if (DBG) {
5346 log("setCallForwarding: subId " + subId
5347 + " callForwardingInfo" + callForwardingInfo);
5348 }
5349 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5350 } finally {
5351 Binder.restoreCallingIdentity(identity);
5352 }
5353 }
5354
5355 /**
5356 * Get the call forwarding info, given the call forwarding reason.
5357 */
5358 @Override
5359 public int getCallWaitingStatus(int subId) {
5360 enforceReadPrivilegedPermission("getCallForwarding");
5361 long identity = Binder.clearCallingIdentity();
5362 try {
5363 if (DBG) log("getCallWaitingStatus: subId " + subId);
5364 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5365 } finally {
5366 Binder.restoreCallingIdentity(identity);
5367 }
5368 }
5369
5370 /**
5371 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5372 * reason, the number to forward, and the timeout before the forwarding is attempted.
5373 */
5374 @Override
5375 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5376 enforceModifyPermission();
5377 long identity = Binder.clearCallingIdentity();
5378 try {
5379 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5380 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5381 } finally {
5382 Binder.restoreCallingIdentity(identity);
5383 }
5384 }
5385
5386 /**
yinxub1bed742017-04-17 11:45:04 -07005387 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005388 *
yinxub1bed742017-04-17 11:45:04 -07005389 * @param subId id of the subscription
5390 * @param request contains the radio access networks with bands/channels to scan
5391 * @param messenger callback messenger for scan results or errors
5392 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005393 * @return the id of the requested scan which can be used to stop the scan.
5394 */
5395 @Override
5396 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005397 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005398 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5399 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005400 LocationAccessPolicy.LocationPermissionResult locationResult =
5401 LocationAccessPolicy.checkLocationPermission(mApp,
5402 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5403 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005404 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005405 .setCallingPid(Binder.getCallingPid())
5406 .setCallingUid(Binder.getCallingUid())
5407 .setMethod("requestNetworkScan")
5408 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5409 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005410 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Nathan Harold1c11dba2020-09-22 17:54:53 -07005411 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(
5412 request, subId, callingPackage);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005413 if (e != null) {
5414 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5415 throw e;
5416 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005417 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 return TelephonyScanManager.INVALID_SCAN_ID;
5419 }
5420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005421 }
Hall Liu912dfd32019-04-25 14:02:26 -07005422 int callingUid = Binder.getCallingUid();
5423 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005424 final long identity = Binder.clearCallingIdentity();
5425 try {
5426 return mNetworkScanRequestTracker.startNetworkScan(
5427 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005428 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005429 } finally {
5430 Binder.restoreCallingIdentity(identity);
5431 }
yinxu504e1392017-04-12 16:03:22 -07005432 }
5433
Hall Liub2ac8ef2019-02-28 15:56:23 -08005434 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Nathan Harold1c11dba2020-09-22 17:54:53 -07005435 NetworkScanRequest request, int subId, String callingPackage) {
5436 boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage)
Hall Liu558027f2019-05-15 19:14:05 -07005437 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5438 boolean hasNetworkScanPermission =
5439 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5440 == PERMISSION_GRANTED;
5441
5442 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5443 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5444 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005445 }
5446
5447 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5448 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005449 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5450 return new SecurityException("Specific channels must not be"
5451 + " scanned without location access.");
5452 }
5453 }
5454 }
5455
Hall Liub2ac8ef2019-02-28 15:56:23 -08005456 return null;
5457 }
5458
yinxu504e1392017-04-12 16:03:22 -07005459 /**
5460 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005461 *
5462 * @param subId id of the subscription
5463 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005464 */
5465 @Override
5466 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005467 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5468 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005469
Hall Liu912dfd32019-04-25 14:02:26 -07005470 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005471 final long identity = Binder.clearCallingIdentity();
5472 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005473 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005474 } finally {
5475 Binder.restoreCallingIdentity(identity);
5476 }
yinxu504e1392017-04-12 16:03:22 -07005477 }
5478
5479 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005480 * Get the calculated preferred network type.
5481 * Used for debugging incorrect network type.
5482 *
5483 * @return the preferred network type, defined in RILConstants.java.
5484 */
5485 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005486 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005487 final Phone defaultPhone = getDefaultPhone();
5488 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005489 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005490 return RILConstants.PREFERRED_NETWORK_MODE;
5491 }
5492
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005493 final long identity = Binder.clearCallingIdentity();
5494 try {
5495 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005496 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005497 } finally {
5498 Binder.restoreCallingIdentity(identity);
5499 }
Junda Liu84d15a22014-07-02 11:21:04 -07005500 }
5501
5502 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005503 * Get the preferred network type.
5504 * Used for device configuration by some CDMA operators.
5505 *
5506 * @return the preferred network type, defined in RILConstants.java.
5507 */
5508 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005509 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005510 TelephonyPermissions
5511 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5512 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513
5514 final long identity = Binder.clearCallingIdentity();
5515 try {
5516 if (DBG) log("getPreferredNetworkType");
5517 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5518 int networkType = (result != null ? result[0] : -1);
5519 if (DBG) log("getPreferredNetworkType: " + networkType);
5520 return networkType;
5521 } finally {
5522 Binder.restoreCallingIdentity(identity);
5523 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005524 }
5525
5526 /**
5527 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005528 *
5529 * @param networkType the preferred network type, defined in RILConstants.java.
5530 * @return true on success; false on any failure.
5531 */
5532 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005533 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005534 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5535 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005536
5537 final long identity = Binder.clearCallingIdentity();
5538 try {
calvinpan8ed33732020-03-12 14:17:55 +08005539 Boolean success = (Boolean) sendRequest(
5540 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
calvinpan03641a72020-08-18 16:53:59 +08005541
5542 if (success) {
5543 Settings.Global.putInt(mApp.getContentResolver(),
5544 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
5545 }
calvinpan8ed33732020-03-12 14:17:55 +08005546 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5547 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005548 } finally {
5549 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005550 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005551 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005552
5553 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005554 * Get the allowed network types that store in the telephony provider.
5555 *
5556 * @param subId the id of the subscription.
5557 * @return allowedNetworkTypes the allowed network types.
5558 */
5559 @Override
5560 public long getAllowedNetworkTypes(int subId) {
5561 TelephonyPermissions
5562 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5563 mApp, subId, "getAllowedNetworkTypes");
5564
5565 final long identity = Binder.clearCallingIdentity();
5566 try {
5567 return SubscriptionManager.getLongSubscriptionProperty(
5568 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5569 } finally {
5570 Binder.restoreCallingIdentity(identity);
5571 }
5572 }
5573
5574 /**
5575 * Set the allowed network types.
5576 *
5577 * @param subId the id of the subscription.
5578 * @param allowedNetworkTypes the allowed network types.
5579 * @return true on success; false on any failure.
5580 */
5581 @Override
5582 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5583 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5584 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005585
calvinpan8ed33732020-03-12 14:17:55 +08005586 SubscriptionManager.setSubscriptionProperty(subId,
5587 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5588 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005589
calvinpan8ed33732020-03-12 14:17:55 +08005590 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5591 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5592 RILConstants.PREFERRED_NETWORK_MODE);
5593 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005594 }
5595
5596 /**
Sooraj Sasindranc46dfbd2020-06-03 01:06:00 -07005597 * Get the allowed network types for certain reason.
5598 *
5599 * @param subId the id of the subscription.
5600 * @param reason the reason the allowed network type change is taking place
5601 * @return the allowed network types.
5602 */
5603 @Override
5604 public long getAllowedNetworkTypesForReason(int subId,
5605 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5606 TelephonyPermissions
5607 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5608 mApp, subId, "getAllowedNetworkTypesForReason");
5609 final long identity = Binder.clearCallingIdentity();
5610 try {
5611 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5612 } finally {
5613 Binder.restoreCallingIdentity(identity);
5614 }
5615 }
5616
5617 /**
5618 * Get the effective allowed network types on the device.
5619 * This API will return an intersection of allowed network types for all reasons,
5620 * including the configuration done through setAllowedNetworkTypes
5621 *
5622 * @param subId the id of the subscription.
5623 * @return the allowed network types
5624 */
5625 @Override
5626 public long getEffectiveAllowedNetworkTypes(int subId) {
5627 TelephonyPermissions
5628 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5629 mApp, subId, "getEffectiveAllowedNetworkTypes");
5630 final long identity = Binder.clearCallingIdentity();
5631 try {
5632 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5633 } finally {
5634 Binder.restoreCallingIdentity(identity);
5635 }
5636 }
5637
5638 /**
5639 * Set the allowed network types of the device and
5640 * provide the reason triggering the allowed network change.
5641 *
5642 * @param subId the id of the subscription.
5643 * @param reason the reason the allowed network type change is taking place
5644 * @param allowedNetworkTypes the allowed network types.
5645 * @return true on success; false on any failure.
5646 */
5647 @Override
5648 public boolean setAllowedNetworkTypesForReason(int subId,
5649 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5650 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5651 mApp, subId, "setAllowedNetworkTypesForReason");
5652 final long identity = Binder.clearCallingIdentity();
5653 try {
5654 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5655 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5656 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5657 RILConstants.PREFERRED_NETWORK_MODE);
5658 return setPreferredNetworkType(subId, preferredNetworkMode);
5659 } finally {
5660 Binder.restoreCallingIdentity(identity);
5661 }
5662 }
5663
5664 /**
Miaoa84611c2019-03-15 09:21:10 +08005665 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005666 *
Miaoa84611c2019-03-15 09:21:10 +08005667 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005668 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005669 * @hide
5670 */
5671 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005672 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005673 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005674 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005675 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005676 try {
Miaoa84611c2019-03-15 09:21:10 +08005677 if (phone != null) {
5678 return phone.hasMatchedTetherApnSetting();
5679 } else {
5680 return false;
5681 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005682 } finally {
5683 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005684 }
Junda Liu475951f2014-11-07 16:45:03 -08005685 }
5686
5687 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005688 * Set mobile data enabled
5689 * Used by the user through settings etc to turn on/off mobile data
5690 *
5691 * @param enable {@code true} turn turn data on, else {@code false}
5692 */
5693 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005694 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005695 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5696 mApp, subId, "setUserDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005697
5698 final long identity = Binder.clearCallingIdentity();
5699 try {
5700 int phoneId = mSubscriptionController.getPhoneId(subId);
5701 if (DBG) log("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5702 Phone phone = PhoneFactory.getPhone(phoneId);
5703 if (phone != null) {
5704 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005705 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005706 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005707 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005708 }
5709 } finally {
5710 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005711 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005712 }
5713
5714 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005715 * Enable or disable always reporting signal strength changes from radio.
5716 *
5717 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5718 */
5719 @Override
5720 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5721 enforceModifyPermission();
5722 enforceSystemCaller();
5723
5724 final long identity = Binder.clearCallingIdentity();
5725 final Phone phone = getPhone(subId);
5726 try {
5727 if (phone != null) {
5728 if (DBG) {
5729 log("setAlwaysReportSignalStrength: subId=" + subId
5730 + " isEnable=" + isEnable);
5731 }
5732 phone.setAlwaysReportSignalStrength(isEnable);
5733 } else {
5734 loge("setAlwaysReportSignalStrength: no phone found for subId="
5735 + subId);
5736 }
5737 } finally {
5738 Binder.restoreCallingIdentity(identity);
5739 }
5740 }
5741
5742 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005743 * Get the user enabled state of Mobile Data.
5744 *
5745 * TODO: remove and use isUserDataEnabled.
5746 * This can't be removed now because some vendor codes
5747 * calls through ITelephony directly while they should
5748 * use TelephonyManager.
5749 *
5750 * @return true on enabled
5751 */
5752 @Override
5753 public boolean getDataEnabled(int subId) {
5754 return isUserDataEnabled(subId);
5755 }
5756
5757 /**
5758 * Get whether mobile data is enabled per user setting.
5759 *
5760 * There are other factors deciding whether mobile data is actually enabled, but they are
5761 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005762 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005763 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005764 *
5765 * @return {@code true} if data is enabled else {@code false}
5766 */
5767 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005768 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005769 try {
5770 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5771 null);
5772 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5774 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005775 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005776
5777 final long identity = Binder.clearCallingIdentity();
5778 try {
5779 int phoneId = mSubscriptionController.getPhoneId(subId);
5780 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5781 Phone phone = PhoneFactory.getPhone(phoneId);
5782 if (phone != null) {
5783 boolean retVal = phone.isUserDataEnabled();
5784 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5785 return retVal;
5786 } else {
5787 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5788 return false;
5789 }
5790 } finally {
5791 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005792 }
5793 }
5794
5795 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005796 * Checks if the device is capable of mobile data by considering whether whether the
5797 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5798 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005799 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005800 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005801 */
5802 @Override
5803 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005804 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005805
5806 final long identity = Binder.clearCallingIdentity();
5807 try {
5808 int phoneId = mSubscriptionController.getPhoneId(subId);
5809 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5810 Phone phone = PhoneFactory.getPhone(phoneId);
5811 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005812 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005813 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5814 return retVal;
5815 } else {
5816 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5817 return false;
5818 }
5819 } finally {
5820 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005821 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005822 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005823
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005824 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005825 Phone phone) {
Hall Liu54a2a0c2020-07-13 12:13:03 -07005826 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5827 // Skip the check if it's one of these special uids
5828 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5829 }
5830
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005831 //load access rules from carrier configs, and check those as well: b/139133814
5832 SubscriptionController subController = SubscriptionController.getInstance();
5833 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5834 || subController == null) return privilegeFromSim;
5835
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005836 PackageManager pkgMgr = phone.getContext().getPackageManager();
5837 String[] packages = pkgMgr.getPackagesForUid(uid);
5838
5839 final long identity = Binder.clearCallingIdentity();
5840 try {
5841 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5842 SubscriptionManager subManager = (SubscriptionManager)
5843 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5844 for (String pkg : packages) {
5845 if (subManager.canManageSubscription(subInfo, pkg)) {
5846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5847 }
5848 }
5849 return privilegeFromSim;
5850 } finally {
5851 Binder.restoreCallingIdentity(identity);
5852 }
5853 }
5854
5855 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5856 String pkgName) {
5857 //load access rules from carrier configs, and check those as well: b/139133814
5858 SubscriptionController subController = SubscriptionController.getInstance();
5859 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5860 || subController == null) return privilegeFromSim;
5861
5862 final long identity = Binder.clearCallingIdentity();
5863 try {
5864 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5865 SubscriptionManager subManager = (SubscriptionManager)
5866 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5867 return subManager.canManageSubscription(subInfo, pkgName)
5868 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5869 } finally {
5870 Binder.restoreCallingIdentity(identity);
5871 }
5872 }
5873
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005874 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005875 public int getCarrierPrivilegeStatus(int subId) {
5876 final Phone phone = getPhone(subId);
5877 if (phone == null) {
5878 loge("getCarrierPrivilegeStatus: Invalid subId");
5879 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5880 }
5881 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005882 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005883 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005884 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5885 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005886
5887 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5888 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005889 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005890 }
Junda Liu29340342014-07-10 15:23:27 -07005891
5892 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005893 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005894 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005895 final Phone phone = getPhone(subId);
5896 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005897 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005898 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5899 }
5900 UiccProfile profile =
5901 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5902 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005903 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005904 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5905 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005906 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005907 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chen6a13f2a2020-02-24 15:12:43 -08005908 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005909 }
5910
5911 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005912 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5913 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005914 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005915 }
5916
5917 int phoneId = SubscriptionManager.getPhoneId(subId);
5918 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005919 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005920 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005921 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5922 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005923 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5924 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5925 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005926 }
5927
5928 @Override
5929 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005930 if (TextUtils.isEmpty(pkgName))
5931 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005932 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5933 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5934 UiccCard card = UiccController.getInstance().getUiccCard(i);
5935 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005936 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005937 continue;
5938 }
5939
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005940 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5941 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5942 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005943 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5944 break;
5945 }
5946 }
5947
5948 return result;
Junda Liu29340342014-07-10 15:23:27 -07005949 }
Derek Tan89e89d42014-07-08 17:00:10 -07005950
5951 @Override
Junda Liue64de782015-04-16 17:19:16 -07005952 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5953 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5954 loge("phoneId " + phoneId + " is not valid.");
5955 return null;
5956 }
5957 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005958 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005959 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005960 return null ;
5961 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005962 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005963 }
5964
Amith Yamasani6e118872016-02-19 12:53:51 -08005965 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005966 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005967 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005968 List<String> privilegedPackages = new ArrayList<>();
5969 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005970 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5971 // has UICC in that slot.
5972 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005973 if (card.hasCarrierPrivilegeRules()) {
5974 if (packages == null) {
5975 // Only check packages in user 0 for now
5976 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005977 PackageManager.MATCH_DISABLED_COMPONENTS
5978 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005979 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005980 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005981 }
5982 for (int p = packages.size() - 1; p >= 0; p--) {
5983 PackageInfo pkgInfo = packages.get(p);
5984 if (pkgInfo != null && pkgInfo.packageName != null
5985 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005986 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005987 privilegedPackages.add(pkgInfo.packageName);
5988 }
5989 }
5990 }
5991 }
5992 return privilegedPackages;
5993 }
5994
chen xuf7e9fe82019-05-09 19:31:02 -07005995 @Override
5996 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005997 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5998
5999 final long identity = Binder.clearCallingIdentity();
6000
chen xuf7e9fe82019-05-09 19:31:02 -07006001 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00006002 try {
6003 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6004 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6005 }
6006 } finally {
6007 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006008 }
6009 return privilegedPackages;
6010 }
6011
Wink Savilleb564aae2014-10-23 10:18:09 -07006012 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006013 final Phone phone = getPhone(subId);
6014 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006015 if (card == null) {
6016 loge("getIccId: No UICC");
6017 return null;
6018 }
6019 String iccId = card.getIccId();
6020 if (TextUtils.isEmpty(iccId)) {
6021 loge("getIccId: ICC ID is null or empty.");
6022 return null;
6023 }
6024 return iccId;
6025 }
6026
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006027 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006028 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6029 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006030 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006031 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006032
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006033 final long identity = Binder.clearCallingIdentity();
6034 try {
6035 final String iccId = getIccId(subId);
6036 final Phone phone = getPhone(subId);
6037 if (phone == null) {
6038 return false;
6039 }
6040 final String subscriberId = phone.getSubscriberId();
6041
6042 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006043 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006044 + subscriberId + " to " + number);
6045 }
6046
6047 if (TextUtils.isEmpty(iccId)) {
6048 return false;
6049 }
6050
6051 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6052
6053 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6054 if (alphaTag == null) {
6055 editor.remove(alphaTagPrefKey);
6056 } else {
6057 editor.putString(alphaTagPrefKey, alphaTag);
6058 }
6059
6060 // Record both the line number and IMSI for this ICCID, since we need to
6061 // track all merged IMSIs based on line number
6062 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6063 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6064 if (number == null) {
6065 editor.remove(numberPrefKey);
6066 editor.remove(subscriberPrefKey);
6067 } else {
6068 editor.putString(numberPrefKey, number);
6069 editor.putString(subscriberPrefKey, subscriberId);
6070 }
6071
6072 editor.commit();
6073 return true;
6074 } finally {
6075 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006076 }
Derek Tan7226c842014-07-02 17:42:23 -07006077 }
6078
6079 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006080 public String getLine1NumberForDisplay(int subId, String callingPackage,
6081 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006082 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006083 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006084 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006085 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006086 return null;
6087 }
Derek Tan97ebb422014-09-05 16:55:38 -07006088
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006089 final long identity = Binder.clearCallingIdentity();
6090 try {
6091 String iccId = getIccId(subId);
6092 if (iccId != null) {
6093 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6094 if (DBG_MERGE) {
6095 log("getLine1NumberForDisplay returning "
6096 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6097 }
6098 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006099 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006100 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6101 return null;
6102 } finally {
6103 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006104 }
Derek Tan7226c842014-07-02 17:42:23 -07006105 }
6106
6107 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006108 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6109 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006110 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006111 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006112 return null;
6113 }
Derek Tan97ebb422014-09-05 16:55:38 -07006114
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006115 final long identity = Binder.clearCallingIdentity();
6116 try {
6117 String iccId = getIccId(subId);
6118 if (iccId != null) {
6119 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6120 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6121 }
6122 return null;
6123 } finally {
6124 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006125 }
Derek Tan7226c842014-07-02 17:42:23 -07006126 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006127
6128 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006129 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6130 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006131 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6132 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006133 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006134 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006135 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006136 return null;
6137 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006138
Jordan Liub49b04b2019-05-06 14:45:15 -07006139 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6140 // the process, where TelephonyManager was instantiated.
6141 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006142 final long identity = Binder.clearCallingIdentity();
6143 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006144 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006145 final TelephonyManager tele = TelephonyManager.from(context);
6146 final SubscriptionManager sub = SubscriptionManager.from(context);
6147
6148 // Figure out what subscribers are currently active
6149 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006150
Jordan Liub49b04b2019-05-06 14:45:15 -07006151 // Only consider subs which match the current subId
6152 // This logic can be simplified. See b/131189269 for progress.
6153 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006154 activeSubscriberIds.add(tele.getSubscriberId(subId));
6155 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006156
6157 // First pass, find a number override for an active subscriber
6158 String mergeNumber = null;
6159 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6160 for (String key : prefs.keySet()) {
6161 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6162 final String subscriberId = (String) prefs.get(key);
6163 if (activeSubscriberIds.contains(subscriberId)) {
6164 final String iccId = key.substring(
6165 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6166 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6167 mergeNumber = (String) prefs.get(numberKey);
6168 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006169 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006170 + " for active subscriber " + subscriberId);
6171 }
6172 if (!TextUtils.isEmpty(mergeNumber)) {
6173 break;
6174 }
6175 }
6176 }
6177 }
6178
6179 // Shortcut when no active merged subscribers
6180 if (TextUtils.isEmpty(mergeNumber)) {
6181 return null;
6182 }
6183
6184 // Second pass, find all subscribers under that line override
6185 final ArraySet<String> result = new ArraySet<>();
6186 for (String key : prefs.keySet()) {
6187 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6188 final String number = (String) prefs.get(key);
6189 if (mergeNumber.equals(number)) {
6190 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6191 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6192 final String subscriberId = (String) prefs.get(subscriberKey);
6193 if (!TextUtils.isEmpty(subscriberId)) {
6194 result.add(subscriberId);
6195 }
6196 }
6197 }
6198 }
6199
6200 final String[] resultArray = result.toArray(new String[result.size()]);
6201 Arrays.sort(resultArray);
6202 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006203 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006204 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6205 }
6206 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006207 } finally {
6208 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006209 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006210 }
6211
6212 @Override
zoey chen38003472019-12-13 17:16:31 +08006213 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6214 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006215
6216 final long identity = Binder.clearCallingIdentity();
6217 try {
6218 final TelephonyManager telephonyManager = mApp.getSystemService(
6219 TelephonyManager.class);
6220 String subscriberId = telephonyManager.getSubscriberId(subId);
6221 if (subscriberId == null) {
6222 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006223 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006224 + subId);
6225 }
6226 return null;
6227 }
6228
6229 final SubscriptionInfo info = SubscriptionController.getInstance()
6230 .getSubscriptionInfo(subId);
6231 final ParcelUuid groupUuid = info.getGroupUuid();
6232 // If it doesn't belong to any group, return just subscriberId of itself.
6233 if (groupUuid == null) {
6234 return new String[]{subscriberId};
6235 }
6236
6237 // Get all subscriberIds from the group.
6238 final List<String> mergedSubscriberIds = new ArrayList<>();
6239 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006240 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006241 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006242 for (SubscriptionInfo subInfo : groupInfos) {
6243 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6244 if (subscriberId != null) {
6245 mergedSubscriberIds.add(subscriberId);
6246 }
6247 }
6248
6249 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6250 } finally {
6251 Binder.restoreCallingIdentity(identity);
6252
6253 }
6254 }
6255
6256 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006257 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006258 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006259 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006260
6261 final long identity = Binder.clearCallingIdentity();
6262 try {
6263 final Phone phone = getPhone(subId);
6264 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6265 } finally {
6266 Binder.restoreCallingIdentity(identity);
6267 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006268 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006269
6270 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006271 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006272 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6273 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006274 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6275 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006276
6277 final long identity = Binder.clearCallingIdentity();
6278 try {
6279 final Phone phone = getPhone(subId);
6280 if (phone == null) {
6281 return false;
6282 }
6283 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6284 cdmaNonRoamingList);
6285 } finally {
6286 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006287 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006288 }
6289
6290 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006291 @Deprecated
6292 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6293 enforceModifyPermission();
6294
6295 int returnValue = 0;
6296 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006297 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006298 if(result.exception == null) {
6299 if (result.result != null) {
6300 byte[] responseData = (byte[])(result.result);
6301 if(responseData.length > oemResp.length) {
6302 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6303 responseData.length + "bytes. Buffer Size is " +
6304 oemResp.length + "bytes.");
6305 }
6306 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6307 returnValue = responseData.length;
6308 }
6309 } else {
6310 CommandException ex = (CommandException) result.exception;
6311 returnValue = ex.getCommandError().ordinal();
6312 if(returnValue > 0) returnValue *= -1;
6313 }
6314 } catch (RuntimeException e) {
6315 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6316 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6317 if(returnValue > 0) returnValue *= -1;
6318 }
6319
6320 return returnValue;
6321 }
6322
6323 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006324 public void setRadioCapability(RadioAccessFamily[] rafs) {
6325 try {
6326 ProxyController.getInstance().setRadioCapability(rafs);
6327 } catch (RuntimeException e) {
6328 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6329 }
6330 }
6331
6332 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006333 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006334 Phone phone = PhoneFactory.getPhone(phoneId);
Shuo Qiandee53402020-05-29 14:08:15 -07006335 try {
6336 TelephonyPermissions
6337 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6338 mApp, phone.getSubId(), "getRadioAccessFamily");
6339 } catch (SecurityException e) {
6340 EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission");
6341 throw e;
6342 }
chen xub97461a2018-10-26 14:17:57 -07006343 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006344 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006345 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006346 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006347 final long identity = Binder.clearCallingIdentity();
6348 try {
chen xub97461a2018-10-26 14:17:57 -07006349 TelephonyPermissions
6350 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6351 mApp, phone.getSubId(), "getRadioAccessFamily");
6352 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006353 } finally {
6354 Binder.restoreCallingIdentity(identity);
6355 }
chen xub97461a2018-10-26 14:17:57 -07006356 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006357 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006358
6359 @Override
6360 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006361 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006362 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363
6364 final long identity = Binder.clearCallingIdentity();
6365 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006366 ImsManager.getInstance(defaultPhone.getContext(),
6367 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006371 }
6372
6373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006374 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006375 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006376 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6377 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006378 return false;
6379 }
Svet Ganovb320e182015-04-16 12:30:10 -07006380
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006381 final long identity = Binder.clearCallingIdentity();
6382 try {
6383 // Check the user preference and the system-level IMS setting. Even if the user has
6384 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6385 // In the long run, we may instead need to check if there exists a connection service
6386 // which can support video calling.
6387 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006388 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006389 return imsManager.isVtEnabledByPlatform()
6390 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6391 && imsManager.isVtEnabledByUser();
6392 } finally {
6393 Binder.restoreCallingIdentity(identity);
6394 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006395 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006396
Andrew Leea1239f22015-03-02 17:44:07 -08006397 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006398 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6399 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006400 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006401 mApp, subId, callingPackage, callingFeatureId,
6402 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006403 return false;
6404 }
6405
6406 final long identity = Binder.clearCallingIdentity();
6407 try {
6408 CarrierConfigManager configManager =
6409 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006410 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006411 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6412 } finally {
6413 Binder.restoreCallingIdentity(identity);
6414 }
Andrew Leea1239f22015-03-02 17:44:07 -08006415 }
6416
6417 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006418 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006419 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006420 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 return false;
6422 }
6423
6424 final long identity = Binder.clearCallingIdentity();
6425 try {
6426 CarrierConfigManager configManager =
6427 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006428 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6430 } finally {
6431 Binder.restoreCallingIdentity(identity);
6432 }
Andrew Leea1239f22015-03-02 17:44:07 -08006433 }
6434
Andrew Lee9431b832015-03-09 18:46:45 -07006435 @Override
6436 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006437 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006438 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006439 }
6440
6441 @Override
6442 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006443 final long identity = Binder.clearCallingIdentity();
6444 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006445 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Andrew Lee9431b832015-03-09 18:46:45 -07006449 }
6450
Hall Liuf6668912018-10-31 17:05:23 -07006451 /**
6452 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6453 * support for the feature and device firmware support.
6454 *
6455 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6456 */
6457 @Override
6458 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006459 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006460 final Phone phone = getPhone(subscriptionId);
6461 if (phone == null) {
6462 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6463 return false;
6464 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006465 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006466 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006467 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6468 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006469 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006470 return isCarrierSupported && isDeviceSupported;
6471 } finally {
6472 Binder.restoreCallingIdentity(identity);
6473 }
Hall Liu98187582018-01-22 19:15:32 -08006474 }
6475
Hall Liuf6668912018-10-31 17:05:23 -07006476 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006477 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6478 * RTT setting, will return true if the device and carrier both support RTT.
6479 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006480 */
6481 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006482 final long identity = Binder.clearCallingIdentity();
6483 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006484 boolean isRttSupported = isRttSupported(subscriptionId);
6485 boolean isUserRttSettingOn = Settings.Secure.getInt(
6486 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6487 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6488 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6489 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006490 } finally {
6491 Binder.restoreCallingIdentity(identity);
6492 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006493 }
6494
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006495 @Deprecated
6496 @Override
6497 public String getDeviceId(String callingPackage) {
6498 return getDeviceIdWithFeature(callingPackage, null);
6499 }
6500
Sanket Padawe7310cc72015-01-14 09:53:20 -08006501 /**
6502 * Returns the unique device ID of phone, for example, the IMEI for
6503 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6504 *
6505 * <p>Requires Permission:
6506 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6507 */
6508 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006509 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006510 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006511 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006512 return null;
6513 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006514 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006515 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006516 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006517 return null;
6518 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006519
6520 final long identity = Binder.clearCallingIdentity();
6521 try {
6522 return phone.getDeviceId();
6523 } finally {
6524 Binder.restoreCallingIdentity(identity);
6525 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006526 }
6527
Ping Sunc67b7c22016-03-02 19:16:45 +08006528 /**
6529 * {@hide}
6530 * Returns the IMS Registration Status on a particular subid
6531 *
6532 * @param subId
6533 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006534 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006535 Phone phone = getPhone(subId);
6536 if (phone != null) {
6537 return phone.isImsRegistered();
6538 } else {
6539 return false;
6540 }
6541 }
6542
Santos Cordon7a1885b2015-02-03 11:15:19 -08006543 @Override
6544 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006545 final long identity = Binder.clearCallingIdentity();
6546 try {
6547 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6548 } finally {
6549 Binder.restoreCallingIdentity(identity);
6550 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006551 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006552
Tyler Gunnf70ed162019-04-03 15:28:53 -07006553 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006554 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006555 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006556 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006557 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006558 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6559 }
6560 final long identity = Binder.clearCallingIdentity();
6561 try {
6562 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6563 } finally {
6564 Binder.restoreCallingIdentity(identity);
6565 }
6566 }
6567
6568 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006569 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 Phone phone = getPhone(subscriptionId);
6573 if (phone == null) {
6574 return null;
6575 }
6576 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6577 } finally {
6578 Binder.restoreCallingIdentity(identity);
6579 }
6580 }
6581
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006582 /**
6583 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006584 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006585 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006586 final long identity = Binder.clearCallingIdentity();
6587 try {
6588 Phone phone = getPhone(subId);
6589 if (phone != null) {
6590 return phone.isWifiCallingEnabled();
6591 } else {
6592 return false;
6593 }
6594 } finally {
6595 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006596 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006597 }
6598
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006599 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006600 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006601 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006602 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006603 final long identity = Binder.clearCallingIdentity();
6604 try {
6605 Phone phone = getPhone(subId);
6606 if (phone != null) {
6607 return phone.isVideoEnabled();
6608 } else {
6609 return false;
6610 }
6611 } finally {
6612 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006613 }
6614 }
6615
6616 /**
6617 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6618 * defined in {@link ImsRegistrationImplBase}.
6619 */
6620 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006621 final long identity = Binder.clearCallingIdentity();
6622 try {
6623 Phone phone = getPhone(subId);
6624 if (phone != null) {
6625 return phone.getImsRegistrationTech();
6626 } else {
6627 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6628 }
6629 } finally {
6630 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006631 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006632 }
6633
Stuart Scott8eef64f2015-04-08 15:13:54 -07006634 @Override
6635 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006636 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006637 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6638 return;
6639 }
6640
Svet Ganovcc087f82015-05-12 20:35:54 -07006641 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006642
Svet Ganovcc087f82015-05-12 20:35:54 -07006643 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006644 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6645 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006646 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006647 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006648 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006649 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6650 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006651 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006652 // There has been issues when Sms raw table somehow stores orphan
6653 // fragments. They lead to garbled message when new fragments come
6654 // in and combined with those stale ones. In case this happens again,
6655 // user can reset all network settings which will clean up this table.
6656 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006657 // Clean up IMS settings as well here.
6658 int slotId = getSlotIndex(subId);
6659 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6660 ImsManager.getInstance(mApp, slotId).factoryReset();
6661 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006662
6663 // Erase modem config if erase modem on network setting is enabled.
6664 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6665 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6666 if (configValue != null && Boolean.parseBoolean(configValue)) {
6667 sendEraseModemConfig(getDefaultPhone());
6668 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006669 } finally {
6670 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006671 }
6672 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006673
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006674 private void cleanUpSmsRawTable(Context context) {
6675 ContentResolver resolver = context.getContentResolver();
6676 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6677 resolver.delete(uri, null, null);
6678 }
6679
Narayan Kamath1c496c22015-04-16 14:40:19 +01006680 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006681 public String getSimLocaleForSubscriber(int subId) {
6682 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6683 final Phone phone = getPhone(subId);
6684 if (phone == null) {
6685 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006686 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006687 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006688 final long identity = Binder.clearCallingIdentity();
6689 try {
chen xu5d3637b2019-01-21 23:31:38 -08006690 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006691 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006692 if (info == null) {
6693 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6694 return null;
6695 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006696 // Try and fetch the locale from the carrier properties or from the SIM language
6697 // preferences (EF-PL and EF-LI)...
6698 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006699 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006700 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6701 if (localeFromDefaultSim != null) {
6702 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6703 if (DBG) log("Using locale from subId: " + subId + " locale: "
6704 + localeFromDefaultSim);
6705 return localeFromDefaultSim.toLanguageTag();
6706 } else {
6707 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 }
6709 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006710
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 // The SIM language preferences only store a language (e.g. fr = French), not an
6712 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6713 // the SIM and carrier preferences does not include a country we add the country
6714 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006715 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006716 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006717 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006718 return mccLocale.toLanguageTag();
6719 }
6720
6721 if (DBG) log("No locale found - returning null");
6722 return null;
6723 } finally {
6724 Binder.restoreCallingIdentity(identity);
6725 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006726 }
6727
6728 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006729 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006730 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006731 }
6732
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006733 /**
6734 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6735 */
6736 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006737 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006738 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006739 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006740
Chenjie Yu1ba97252018-01-11 18:16:20 -08006741 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006742 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006743
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006744 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006745 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6746 * representing the state of the modem.
6747 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006748 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6749 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006750 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006751 */
6752 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006753 public void requestModemActivityInfo(ResultReceiver result) {
6754 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006755 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006756
6757 final long identity = Binder.clearCallingIdentity();
6758 try {
Shuo Qian1d931ee2020-02-20 17:12:10 -08006759 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006760 } finally {
6761 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006762 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006763 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006764
Siddharth Rayb8114062018-06-17 15:02:38 -07006765 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6766 // less than total activity duration.
6767 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6768 if (info == null) {
6769 return false;
6770 }
6771 int activityDurationMs =
6772 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6773 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006774 int[] txTimeMs = info.getTransmitTimeMillis();
6775 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6776 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006777 }
6778 return (info.isValid()
6779 && (info.getSleepTimeMillis() <= activityDurationMs)
6780 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006781 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006782 && (totalTxTimeMs <= activityDurationMs));
6783 }
6784
Jack Yu85bd38a2015-11-09 11:34:32 -08006785 /**
6786 * {@hide}
6787 * Returns the service state information on specified subscription.
6788 */
6789 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006790 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6791 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006793 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006794 return null;
6795 }
6796
Hall Liuf19c44f2018-11-27 14:38:17 -08006797 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6798 LocationAccessPolicy.checkLocationPermission(mApp,
6799 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6800 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006801 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006802 .setCallingPid(Binder.getCallingPid())
6803 .setCallingUid(Binder.getCallingUid())
6804 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006805 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006806 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6807 .build());
6808
6809 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6810 LocationAccessPolicy.checkLocationPermission(mApp,
6811 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6812 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006813 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006814 .setCallingPid(Binder.getCallingPid())
6815 .setCallingUid(Binder.getCallingUid())
6816 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006817 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006818 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6819 .build());
6820 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6821 boolean hasFinePermission =
6822 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6823 boolean hasCoarsePermission =
6824 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6825
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006826 final long identity = Binder.clearCallingIdentity();
6827 try {
Jordan Liuc437b192020-08-17 10:59:12 -07006828 // isActiveSubId requires READ_PHONE_STATE, which we already check for above
6829 if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) {
6830 Rlog.d(LOG_TAG,
6831 "getServiceStateForSubscriber returning null for inactive subId=" + subId);
6832 return null;
6833 }
6834
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006835 final Phone phone = getPhone(subId);
6836 if (phone == null) {
6837 return null;
6838 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006839
Hall Liuf19c44f2018-11-27 14:38:17 -08006840 ServiceState ss = phone.getServiceState();
6841
6842 // Scrub out the location info in ServiceState depending on what level of access
6843 // the caller has.
6844 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006845 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6846 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006847 } finally {
6848 Binder.restoreCallingIdentity(identity);
6849 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006850 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006851
6852 /**
6853 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6854 *
6855 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6856 * voicemail ringtone.
6857 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6858 * PhoneAccount.
6859 */
6860 @Override
6861 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006862 final long identity = Binder.clearCallingIdentity();
6863 try {
6864 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6865 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006866 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006868
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006869 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6870 } finally {
6871 Binder.restoreCallingIdentity(identity);
6872 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006873 }
6874
6875 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006876 * Sets the per-account voicemail ringtone.
6877 *
6878 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6879 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6880 *
6881 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6882 * voicemail ringtone.
6883 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6884 * PhoneAccount.
6885 */
6886 @Override
6887 public void setVoicemailRingtoneUri(String callingPackage,
6888 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006889 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006890 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006891 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6892 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6894 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6895 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006896 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006897
6898 final long identity = Binder.clearCallingIdentity();
6899 try {
6900 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6901 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006902 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006903 }
6904 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6905 } finally {
6906 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006907 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006908 }
6909
6910 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006911 * Returns whether vibration is set for voicemail notification in Phone settings.
6912 *
6913 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6914 * voicemail vibration setting.
6915 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6916 */
6917 @Override
6918 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006919 final long identity = Binder.clearCallingIdentity();
6920 try {
6921 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6922 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006923 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006925
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006926 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6927 } finally {
6928 Binder.restoreCallingIdentity(identity);
6929 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006930 }
6931
Youhan Wange64578a2016-05-02 15:32:42 -07006932 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006933 * Sets the per-account voicemail vibration.
6934 *
6935 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6936 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6937 *
6938 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6939 * voicemail vibration setting.
6940 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6941 * specific PhoneAccount.
6942 */
6943 @Override
6944 public void setVoicemailVibrationEnabled(String callingPackage,
6945 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006946 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006947 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006948 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6949 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006950 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6951 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6952 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006953 }
6954
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006955 final long identity = Binder.clearCallingIdentity();
6956 try {
6957 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6958 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006959 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 }
6961 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6962 } finally {
6963 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006964 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006965 }
6966
6967 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006968 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6969 *
6970 * @throws SecurityException if the caller does not have the required permission
6971 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006972 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006973 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006974 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006975 }
6976
6977 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006978 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6979 * permission.
6980 *
6981 * @throws SecurityException if the caller does not have the required permission
6982 */
6983 private void enforceSendSmsPermission() {
6984 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6985 }
6986
6987 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006988 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006989 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006990 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006991 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006992 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006993 final long identity = Binder.clearCallingIdentity();
6994 try {
6995 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006996 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006997 if (componentName == null) {
6998 throw new SecurityException(
6999 "Caller not current active visual voicemail package[null]");
7000 }
7001 String vvmPackage = componentName.getPackageName();
7002 if (!callingPackage.equals(vvmPackage)) {
7003 throw new SecurityException("Caller not current active visual voicemail package["
7004 + vvmPackage + "]");
7005 }
7006 } finally {
7007 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007008 }
7009 }
7010
7011 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007012 * Return the application ID for the app type.
7013 *
7014 * @param subId the subscription ID that this request applies to.
7015 * @param appType the uicc app type.
7016 * @return Application ID for specificied app type, or null if no uicc.
7017 */
7018 @Override
7019 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007020 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007021 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007022
7023 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007024 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007025 if (phone == null) {
7026 return null;
7027 }
7028 String aid = null;
7029 try {
7030 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7031 .getApplicationByType(appType).getAid();
7032 } catch (Exception e) {
7033 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7034 }
7035 return aid;
7036 } finally {
7037 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007038 }
Youhan Wange64578a2016-05-02 15:32:42 -07007039 }
7040
Youhan Wang4001d252016-05-11 10:29:41 -07007041 /**
7042 * Return the Electronic Serial Number.
7043 *
7044 * @param subId the subscription ID that this request applies to.
7045 * @return ESN or null if error.
7046 */
7047 @Override
7048 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007049 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007050 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007051
7052 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007053 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007054 if (phone == null) {
7055 return null;
7056 }
7057 String esn = null;
7058 try {
7059 esn = phone.getEsn();
7060 } catch (Exception e) {
7061 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7062 }
7063 return esn;
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007066 }
Youhan Wang4001d252016-05-11 10:29:41 -07007067 }
7068
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007069 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007070 * Return the Preferred Roaming List Version.
7071 *
7072 * @param subId the subscription ID that this request applies to.
7073 * @return PRLVersion or null if error.
7074 */
7075 @Override
7076 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007077 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007078 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007079
7080 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007081 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007082 if (phone == null) {
7083 return null;
7084 }
7085 String cdmaPrlVersion = null;
7086 try {
7087 cdmaPrlVersion = phone.getCdmaPrlVersion();
7088 } catch (Exception e) {
7089 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7090 }
7091 return cdmaPrlVersion;
7092 } finally {
7093 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007094 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007095 }
7096
7097 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007098 * Get snapshot of Telephony histograms
7099 * @return List of Telephony histograms
7100 * @hide
7101 */
7102 @Override
7103 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007104 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7105 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007106
7107 final long identity = Binder.clearCallingIdentity();
7108 try {
7109 return RIL.getTelephonyRILTimingHistograms();
7110 } finally {
7111 Binder.restoreCallingIdentity(identity);
7112 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007113 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007114
7115 /**
7116 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007117 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7118 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007119 * Require system privileges. In the future we may add this to carrier APIs.
7120 *
Michele Berionne482f8202018-11-27 18:57:59 -08007121 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007122 */
7123 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007124 @TelephonyManager.SetCarrierRestrictionResult
7125 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007126 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007127 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007128
Michele Berionne482f8202018-11-27 18:57:59 -08007129 if (carrierRestrictionRules == null) {
7130 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007131 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007133 final long identity = Binder.clearCallingIdentity();
7134 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007135 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007136 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007137 } finally {
7138 Binder.restoreCallingIdentity(identity);
7139 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007140 }
7141
7142 /**
7143 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007144 * Get the allowed carrier list and the excluded carrier list, including the priority between
7145 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007146 * Require system privileges. In the future we may add this to carrier APIs.
7147 *
Michele Berionne482f8202018-11-27 18:57:59 -08007148 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007149 */
7150 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007151 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007152 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007153 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007154
7155 final long identity = Binder.clearCallingIdentity();
7156 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007157 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7158 if (response instanceof CarrierRestrictionRules) {
7159 return (CarrierRestrictionRules) response;
7160 }
7161 // Response is an Exception of some kind,
7162 // which is signalled to the user as a NULL retval
7163 return null;
7164 } catch (Exception e) {
7165 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7166 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007167 } finally {
7168 Binder.restoreCallingIdentity(identity);
7169 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007170 }
7171
fionaxu59545b42016-05-25 15:53:37 -07007172 /**
7173 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7174 * @param subId the subscription ID that this action applies to.
7175 * @param enabled control enable or disable metered apns.
7176 * {@hide}
7177 */
7178 @Override
7179 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7180 enforceModifyPermission();
7181 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007182
7183 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007184 if (phone == null) {
7185 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7186 return;
7187 }
7188 try {
7189 phone.carrierActionSetMeteredApnsEnabled(enabled);
7190 } catch (Exception e) {
7191 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007192 } finally {
7193 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007194 }
7195 }
7196
7197 /**
7198 * Action set from carrier signalling broadcast receivers to enable/disable radio
7199 * @param subId the subscription ID that this action applies to.
7200 * @param enabled control enable or disable radio.
7201 * {@hide}
7202 */
7203 @Override
7204 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7205 enforceModifyPermission();
7206 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007207
7208 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007209 if (phone == null) {
7210 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7211 return;
7212 }
7213 try {
7214 phone.carrierActionSetRadioEnabled(enabled);
7215 } catch (Exception e) {
7216 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007217 } finally {
7218 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007219 }
7220 }
7221
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007222 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007223 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7224 * network status based on which carrier apps could apply actions accordingly,
7225 * enable/disable default url handler for example.
7226 *
7227 * @param subId the subscription ID that this action applies to.
7228 * @param report control start/stop reporting the default network status.
7229 * {@hide}
7230 */
7231 @Override
7232 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7233 enforceModifyPermission();
7234 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007235
7236 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007237 if (phone == null) {
7238 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7239 return;
7240 }
7241 try {
7242 phone.carrierActionReportDefaultNetworkStatus(report);
7243 } catch (Exception e) {
7244 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007245 } finally {
7246 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007247 }
7248 }
7249
7250 /**
fionaxud9622282017-07-17 17:51:30 -07007251 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7252 * @param subId the subscription ID that this action applies to.
7253 * {@hide}
7254 */
7255 @Override
7256 public void carrierActionResetAll(int subId) {
7257 enforceModifyPermission();
7258 final Phone phone = getPhone(subId);
7259 if (phone == null) {
7260 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7261 return;
7262 }
7263 try {
7264 phone.carrierActionResetAll();
7265 } catch (Exception e) {
7266 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7267 }
7268 }
7269
7270 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007271 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7272 * bug report is being generated.
7273 */
7274 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007275 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007276 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7277 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007278 writer.println("Permission Denial: can't dump Phone from pid="
7279 + Binder.getCallingPid()
7280 + ", uid=" + Binder.getCallingUid()
7281 + "without permission "
7282 + android.Manifest.permission.DUMP);
7283 return;
7284 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007285 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007286 }
Jack Yueb89b242016-06-22 13:27:47 -07007287
Brad Ebingerdac2f002018-04-03 15:17:52 -07007288 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007289 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7290 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7291 @NonNull String[] args) {
7292 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7293 this, in.getFileDescriptor(), out.getFileDescriptor(),
7294 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007295 }
7296
Jack Yueb89b242016-06-22 13:27:47 -07007297 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007298 * Policy control of data connection. Usually used when data limit is passed.
7299 * @param enabled True if enabling the data, otherwise disabling.
7300 * @param subId Subscription index
7301 * {@hide}
7302 */
7303 @Override
7304 public void setPolicyDataEnabled(boolean enabled, int subId) {
7305 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007306
7307 final long identity = Binder.clearCallingIdentity();
7308 try {
7309 Phone phone = getPhone(subId);
7310 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007311 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007312 }
7313 } finally {
7314 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007315 }
7316 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007317
7318 /**
7319 * Get Client request stats
7320 * @return List of Client Request Stats
7321 * @hide
7322 */
7323 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007324 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7325 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007327 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007328 return null;
7329 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007330 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007332 final long identity = Binder.clearCallingIdentity();
7333 try {
7334 if (phone != null) {
7335 return phone.getClientRequestStats();
7336 }
7337
7338 return null;
7339 } finally {
7340 Binder.restoreCallingIdentity(identity);
7341 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007342 }
7343
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007344 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007345 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007346 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007347 }
Jack Yueb4124c2017-02-16 15:32:43 -08007348
7349 /**
Grace Chen70990072017-03-24 17:21:30 -07007350 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007351 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007352 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007353 * @param state State of SIM (power down, power up, pass through)
7354 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7355 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7356 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007357 *
7358 **/
7359 @Override
Grace Chen70990072017-03-24 17:21:30 -07007360 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007361 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007362 Phone phone = PhoneFactory.getPhone(slotIndex);
7363
vagdeviaf9a5b92018-08-15 16:01:53 -07007364 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7365
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
7368 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007369 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007370 }
7371 } finally {
7372 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007373 }
7374 }
Shuo Qiandd210312017-04-12 22:11:33 +00007375
Tyler Gunn65d45c22017-06-05 11:22:26 -07007376 private boolean isUssdApiAllowed(int subId) {
7377 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007378 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007379 if (configManager == null) {
7380 return false;
7381 }
7382 PersistableBundle pb = configManager.getConfigForSubId(subId);
7383 if (pb == null) {
7384 return false;
7385 }
7386 return pb.getBoolean(
7387 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7388 }
7389
Shuo Qiandd210312017-04-12 22:11:33 +00007390 /**
7391 * Check if phone is in emergency callback mode
7392 * @return true if phone is in emergency callback mode
7393 * @param subId sub id
7394 */
goneil9c5f4872017-12-05 14:07:56 -08007395 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007396 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007397 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007398 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007399
7400 final long identity = Binder.clearCallingIdentity();
7401 try {
7402 if (phone != null) {
7403 return phone.isInEcm();
7404 } else {
7405 return false;
7406 }
7407 } finally {
7408 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007409 }
7410 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007411
7412 /**
7413 * Get the current signal strength information for the given subscription.
7414 * Because this information is not updated when the device is in a low power state
7415 * it should not be relied-upon to be current.
7416 * @param subId Subscription index
7417 * @return the most recent cached signal strength info from the modem
7418 */
7419 @Override
7420 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007421 final long identity = Binder.clearCallingIdentity();
7422 try {
7423 Phone p = getPhone(subId);
7424 if (p == null) {
7425 return null;
7426 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007427
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007428 return p.getSignalStrength();
7429 } finally {
7430 Binder.restoreCallingIdentity(identity);
7431 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007432 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007433
Pengquan Meng77b7f132018-08-22 14:49:57 -07007434 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007435 * Get the current modem radio state for the given slot.
7436 * @param slotIndex slot index.
7437 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007438 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007439 * @return the current radio power state from the modem
7440 */
7441 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007442 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007443 Phone phone = PhoneFactory.getPhone(slotIndex);
7444 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007445 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7446 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007447 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7448 }
7449
7450 final long identity = Binder.clearCallingIdentity();
7451 try {
7452 return phone.getRadioPowerState();
7453 } finally {
7454 Binder.restoreCallingIdentity(identity);
7455 }
7456 }
7457 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7458 }
7459
7460 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007461 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7462 *
7463 * <p>Requires one of the following permissions:
7464 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7465 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7466 * privileges.
7467 *
7468 * @param subId subscription id
7469 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7470 * {@code false}.
7471 */
7472 @Override
7473 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007474 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7475 null /* message */);
7476
Pengquan Menga1bb6272018-09-06 09:59:22 -07007477 boolean isEnabled = false;
7478 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007479 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007480 Phone phone = getPhone(subId);
7481 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007482 } catch (Exception e) {
7483 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7484 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007485 } finally {
7486 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007487 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007488 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007489 }
7490
7491
7492 /**
7493 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7494 *
7495 * <p> Requires permission:
7496 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7497 * privileges.
7498 *
7499 * @param subId subscription id
7500 * @param isEnabled {@code true} means enable, {@code false} means disable.
7501 */
7502 @Override
7503 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007504 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7505 mApp, subId, "setDataRoamingEnabled");
7506
Pengquan Menga1bb6272018-09-06 09:59:22 -07007507 final long identity = Binder.clearCallingIdentity();
7508 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007509 Phone phone = getPhone(subId);
7510 if (phone != null) {
7511 phone.setDataRoamingEnabled(isEnabled);
7512 }
7513 } finally {
7514 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007515 }
7516 }
7517
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007518 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007519 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007520 TelephonyPermissions
7521 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007522 mApp, subId, "isManualNetworkSelectionAllowed");
7523
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007524 boolean isAllowed = true;
7525 final long identity = Binder.clearCallingIdentity();
7526 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007527 Phone phone = getPhone(subId);
7528 if (phone != null) {
7529 isAllowed = phone.isCspPlmnEnabled();
7530 }
7531 } finally {
7532 Binder.restoreCallingIdentity(identity);
7533 }
7534 return isAllowed;
7535 }
7536
7537 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007538 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007539 // Verify that tha callingPackage belongs to the calling UID
7540 mApp.getSystemService(AppOpsManager.class)
7541 .checkPackage(Binder.getCallingUid(), callingPackage);
7542
Jordan Liu1e142fc2019-04-22 15:10:43 -07007543 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007544 try {
7545 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007546 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007547 } catch (SecurityException e) {
7548 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7549 // has carrier privileges on an active UICC
7550 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7551 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007552 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007553 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007554 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007555
7556 final long identity = Binder.clearCallingIdentity();
7557 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007558 UiccController uiccController = UiccController.getInstance();
7559 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007560 if (hasReadPermission) {
7561 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007562 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007563
7564 // Remove private info if the caller doesn't have access
7565 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7566 for (UiccCardInfo cardInfo : cardInfos) {
7567 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7568 // is available
7569 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7570 if (card == null || card.getUiccProfile() == null) {
7571 // assume no access if the card or profile is unavailable
7572 filteredInfos.add(cardInfo.getUnprivileged());
7573 continue;
7574 }
7575 UiccProfile profile = card.getUiccProfile();
7576 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7577 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7578 filteredInfos.add(cardInfo);
7579 } else {
7580 filteredInfos.add(cardInfo.getUnprivileged());
7581 }
7582 }
7583 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007584 } finally {
7585 Binder.restoreCallingIdentity(identity);
7586 }
7587 }
7588
7589 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007590 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007591 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007592
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007593 final long identity = Binder.clearCallingIdentity();
7594 try {
7595 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7596 if (slots == null) {
7597 Rlog.i(LOG_TAG, "slots is null.");
7598 return null;
7599 }
7600
7601 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7602 for (int i = 0; i < slots.length; i++) {
7603 UiccSlot slot = slots[i];
7604 if (slot == null) {
7605 continue;
7606 }
7607
Jordan Liu7be7e652019-05-06 18:55:02 +00007608 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007609 UiccCard card = slot.getUiccCard();
7610 if (card != null) {
7611 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007612 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007613 cardId = slot.getEid();
7614 if (TextUtils.isEmpty(cardId)) {
7615 cardId = slot.getIccId();
7616 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007617 }
7618
Jordan Liu857451f2019-05-09 16:35:35 -07007619 if (cardId != null) {
7620 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7621 // if cardId is an EID, it's all digits so this is fine
7622 cardId = IccUtils.stripTrailingFs(cardId);
7623 }
7624
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007625 int cardState = 0;
7626 switch (slot.getCardState()) {
7627 case CARDSTATE_ABSENT:
7628 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7629 break;
7630 case CARDSTATE_PRESENT:
7631 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7632 break;
7633 case CARDSTATE_ERROR:
7634 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7635 break;
7636 case CARDSTATE_RESTRICTED:
7637 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7638 break;
7639 default:
7640 break;
7641
7642 }
7643
7644 infos[i] = new UiccSlotInfo(
7645 slot.isActive(),
7646 slot.isEuicc(),
7647 cardId,
7648 cardState,
7649 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007650 slot.isExtendedApduSupported(),
7651 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007652 }
7653 return infos;
7654 } finally {
7655 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007656 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007657 }
7658
7659 @Override
7660 public boolean switchSlots(int[] physicalSlots) {
7661 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007662
7663 final long identity = Binder.clearCallingIdentity();
7664 try {
7665 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7666 } finally {
7667 Binder.restoreCallingIdentity(identity);
7668 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007669 }
Jack Yu4c988042018-02-27 15:30:01 -08007670
7671 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007672 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007673 final long identity = Binder.clearCallingIdentity();
7674 try {
7675 return UiccController.getInstance().getCardIdForDefaultEuicc();
7676 } finally {
7677 Binder.restoreCallingIdentity(identity);
7678 }
7679 }
7680
Pengquan Meng85728fb2018-03-12 16:31:21 -07007681 /**
goneil47ffb6e2018-04-06 15:40:58 -07007682 * A test API to reload the UICC profile.
7683 *
7684 * <p>Requires that the calling app has permission
7685 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7686 * @hide
7687 */
7688 @Override
7689 public void refreshUiccProfile(int subId) {
7690 enforceModifyPermission();
7691
7692 final long identity = Binder.clearCallingIdentity();
7693 try {
7694 Phone phone = getPhone(subId);
7695 if (phone == null) {
7696 return;
7697 }
7698 UiccCard uiccCard = phone.getUiccCard();
7699 if (uiccCard == null) {
7700 return;
7701 }
7702 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7703 if (uiccProfile == null) {
7704 return;
7705 }
7706 uiccProfile.refresh();
7707 } finally {
7708 Binder.restoreCallingIdentity(identity);
7709 }
7710 }
7711
7712 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007713 * Returns false if the mobile data is disabled by default, otherwise return true.
7714 */
7715 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007716 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007717 }
7718
7719 /**
7720 * Returns true if the data roaming is enabled by default, i.e the system property
7721 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7722 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7723 */
7724 private boolean getDefaultDataRoamingEnabled(int subId) {
7725 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007726 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qian1d84a0e2020-07-15 12:36:44 -07007727 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007728 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7729 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7730 return isDataRoamingEnabled;
7731 }
7732
7733 /**
7734 * Returns the default network type for the given {@code subId}, if the default network type is
7735 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7736 */
7737 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007738 List<Integer> list = TelephonyProperties.default_network();
7739 int phoneId = mSubscriptionController.getPhoneId(subId);
7740 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7741 return list.get(phoneId);
7742 }
7743 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007744 }
fionaxua13278b2018-03-21 00:08:13 -07007745
7746 @Override
7747 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007748 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007749 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007750
7751 final long identity = Binder.clearCallingIdentity();
7752 try {
7753 final Phone phone = getPhone(subId);
7754 if (phone == null) {
7755 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7756 return;
7757 }
chen xueaba88a2019-03-15 13:15:10 -07007758 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7759 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007760 } finally {
7761 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007762 }
fionaxua13278b2018-03-21 00:08:13 -07007763 }
7764
7765 @Override
7766 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007767 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007768
7769 final long identity = Binder.clearCallingIdentity();
7770 try {
7771 final Phone phone = getPhone(subId);
7772 if (phone == null) {
7773 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7774 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7775 }
7776 return phone.getCarrierIdListVersion();
7777 } finally {
7778 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007779 }
fionaxua13278b2018-03-21 00:08:13 -07007780 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007781
7782 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007783 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7784 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007785 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007786 mApp, subId, callingPackage, callingFeatureId,
7787 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007788 return -1;
7789 }
7790
7791 final long identity = Binder.clearCallingIdentity();
7792 try {
7793 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7794 } finally {
7795 Binder.restoreCallingIdentity(identity);
7796 }
7797 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007798
7799 @Override
7800 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007801 TelephonyPermissions
7802 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007803 mApp, subId, "getCdmaRoamingMode");
7804
7805 final long identity = Binder.clearCallingIdentity();
7806 try {
7807 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7808 } finally {
7809 Binder.restoreCallingIdentity(identity);
7810 }
7811 }
7812
7813 @Override
7814 public boolean setCdmaRoamingMode(int subId, int mode) {
7815 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7816 mApp, subId, "setCdmaRoamingMode");
7817
7818 final long identity = Binder.clearCallingIdentity();
7819 try {
7820 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7821 } finally {
7822 Binder.restoreCallingIdentity(identity);
7823 }
7824 }
7825
7826 @Override
7827 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7829 mApp, subId, "setCdmaSubscriptionMode");
7830
7831 final long identity = Binder.clearCallingIdentity();
7832 try {
7833 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
7837 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007838
sqianc5eccab2018-10-19 18:46:41 -07007839 @Override
sqian8c685422019-02-22 15:55:18 -08007840 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007841 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007842 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007843 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7844 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007845 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7846 }
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
sqian854d44b2018-12-12 16:48:18 -08007849 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7850 for (Phone phone: PhoneFactory.getPhones()) {
7851 if (phone.getEmergencyNumberTracker() != null
7852 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7853 emergencyNumberListInternal.put(
7854 phone.getSubId(),
7855 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7856 }
sqian11b7a0e2018-12-05 18:48:28 -08007857 }
sqian854d44b2018-12-12 16:48:18 -08007858 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007859 } finally {
7860 Binder.restoreCallingIdentity(identity);
7861 }
sqianc5eccab2018-10-19 18:46:41 -07007862 }
7863
7864 @Override
sqian8c685422019-02-22 15:55:18 -08007865 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007866 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007867 if (!exactMatch) {
7868 TelephonyPermissions
7869 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007870 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007871 }
7872 final long identity = Binder.clearCallingIdentity();
7873 try {
sqian854d44b2018-12-12 16:48:18 -08007874 for (Phone phone: PhoneFactory.getPhones()) {
7875 if (phone.getEmergencyNumberTracker() != null
7876 && phone.getEmergencyNumberTracker() != null) {
7877 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7878 number, exactMatch)) {
7879 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007880 }
7881 }
sqian11b7a0e2018-12-05 18:48:28 -08007882 }
7883 return false;
7884 } finally {
7885 Binder.restoreCallingIdentity(identity);
7886 }
7887 }
7888
sqianf4ca7ed2019-01-15 18:32:07 -08007889 /**
Shuo Qian02dc2152021-02-22 18:32:21 -08007890 * Start emergency callback mode for GsmCdmaPhone for testing.
7891 */
7892 @Override
7893 public void startEmergencyCallbackMode() {
7894 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7895 "startEmergencyCallbackMode");
7896 enforceModifyPermission();
7897 final long identity = Binder.clearCallingIdentity();
7898 try {
7899 for (Phone phone : PhoneFactory.getPhones()) {
7900 Rlog.d(LOG_TAG, "startEmergencyCallbackMode phone type: " + phone.getPhoneType());
7901 if (phone != null && ((phone.getPhoneType() == PHONE_TYPE_GSM)
7902 || (phone.getPhoneType() == PHONE_TYPE_CDMA))) {
7903 GsmCdmaPhone gsmCdmaPhone = (GsmCdmaPhone) phone;
7904 gsmCdmaPhone.obtainMessage(
7905 GsmCdmaPhone.EVENT_EMERGENCY_CALLBACK_MODE_ENTER).sendToTarget();
7906 Rlog.d(LOG_TAG, "startEmergencyCallbackMode: triggered");
7907 }
7908 }
7909 } finally {
7910 Binder.restoreCallingIdentity(identity);
7911 }
7912 }
7913
7914 /**
sqianf4ca7ed2019-01-15 18:32:07 -08007915 * Update emergency number list for test mode.
7916 */
7917 @Override
7918 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7919 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7920 "updateEmergencyNumberListTestMode");
7921
7922 final long identity = Binder.clearCallingIdentity();
7923 try {
7924 for (Phone phone: PhoneFactory.getPhones()) {
7925 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7926 if (tracker != null) {
7927 tracker.executeEmergencyNumberTestModeCommand(action, num);
7928 }
7929 }
7930 } finally {
7931 Binder.restoreCallingIdentity(identity);
7932 }
7933 }
7934
7935 /**
7936 * Get the full emergency number list for test mode.
7937 */
7938 @Override
7939 public List<String> getEmergencyNumberListTestMode() {
7940 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7941 "getEmergencyNumberListTestMode");
7942
7943 final long identity = Binder.clearCallingIdentity();
7944 try {
7945 Set<String> emergencyNumbers = new HashSet<>();
7946 for (Phone phone: PhoneFactory.getPhones()) {
7947 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7948 if (tracker != null) {
7949 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7950 emergencyNumbers.add(num.getNumber());
7951 }
7952 }
7953 }
7954 return new ArrayList<>(emergencyNumbers);
7955 } finally {
7956 Binder.restoreCallingIdentity(identity);
7957 }
7958 }
7959
chen xud6b45bd2018-10-30 22:27:10 -07007960 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007961 public int getEmergencyNumberDbVersion(int subId) {
7962 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7963
7964 final long identity = Binder.clearCallingIdentity();
7965 try {
7966 final Phone phone = getPhone(subId);
7967 if (phone == null) {
7968 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7969 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7970 }
7971 return phone.getEmergencyNumberDbVersion();
7972 } finally {
7973 Binder.restoreCallingIdentity(identity);
7974 }
7975 }
7976
7977 @Override
7978 public void notifyOtaEmergencyNumberDbInstalled() {
7979 enforceModifyPermission();
7980
7981 final long identity = Binder.clearCallingIdentity();
7982 try {
7983 for (Phone phone: PhoneFactory.getPhones()) {
7984 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7985 if (tracker != null) {
7986 tracker.updateOtaEmergencyNumberDatabase();
7987 }
7988 }
7989 } finally {
7990 Binder.restoreCallingIdentity(identity);
7991 }
7992 }
7993
7994 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007995 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007996 enforceActiveEmergencySessionPermission();
7997
7998 final long identity = Binder.clearCallingIdentity();
7999 try {
8000 for (Phone phone: PhoneFactory.getPhones()) {
8001 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8002 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08008003 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
8004 }
8005 }
8006 } finally {
8007 Binder.restoreCallingIdentity(identity);
8008 }
8009 }
8010
8011 @Override
8012 public void resetOtaEmergencyNumberDbFilePath() {
8013 enforceActiveEmergencySessionPermission();
8014
8015 final long identity = Binder.clearCallingIdentity();
8016 try {
8017 for (Phone phone: PhoneFactory.getPhones()) {
8018 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8019 if (tracker != null) {
8020 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08008021 }
8022 }
8023 } finally {
8024 Binder.restoreCallingIdentity(identity);
8025 }
8026 }
8027
8028 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008029 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8030 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8031 Phone phone = getPhone(subId);
8032 if (phone == null) {
8033 return null;
8034 }
8035 final long identity = Binder.clearCallingIdentity();
8036 try {
8037 UiccProfile profile = UiccController.getInstance()
8038 .getUiccProfileForPhone(phone.getPhoneId());
8039 if (profile != null) {
8040 return profile.getCertsFromCarrierPrivilegeAccessRules();
8041 }
8042 } finally {
8043 Binder.restoreCallingIdentity(identity);
8044 }
8045 return null;
8046 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008047
8048 /**
8049 * Enable or disable a modem stack.
8050 */
8051 @Override
8052 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8053 enforceModifyPermission();
8054
8055 final long identity = Binder.clearCallingIdentity();
8056 try {
8057 Phone phone = PhoneFactory.getPhone(slotIndex);
8058 if (phone == null) {
8059 return false;
8060 } else {
8061 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8062 }
8063 } finally {
8064 Binder.restoreCallingIdentity(identity);
8065 }
8066 }
Michelecea4cf22018-12-21 15:00:11 -08008067
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008068 /**
8069 * Whether a modem stack is enabled or not.
8070 */
8071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008072 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8073 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008074 Phone phone = PhoneFactory.getPhone(slotIndex);
8075 if (phone == null) return false;
8076
8077 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008078 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8079 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008080 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8081 }
8082
8083 final long identity = Binder.clearCallingIdentity();
8084 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008085 try {
8086 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8087 } catch (NoSuchElementException ex) {
8088 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8089 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008090 } finally {
8091 Binder.restoreCallingIdentity(identity);
8092 }
8093 }
8094
Michelecea4cf22018-12-21 15:00:11 -08008095 @Override
Michele0ea7d782019-03-19 14:58:42 -07008096 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008097 enforceModifyPermission();
8098
8099 final long identity = Binder.clearCallingIdentity();
8100 try {
8101 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008102 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008103 .commit();
8104 } finally {
8105 Binder.restoreCallingIdentity(identity);
8106 }
8107 }
8108
8109 @Override
Michele0ea7d782019-03-19 14:58:42 -07008110 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008111 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008112 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008113 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8114 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008115 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008116 }
Michelecea4cf22018-12-21 15:00:11 -08008117
8118 final long identity = Binder.clearCallingIdentity();
8119 try {
Michele0ea7d782019-03-19 14:58:42 -07008120 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008121 } finally {
8122 Binder.restoreCallingIdentity(identity);
8123 }
8124 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008125
Michele0ea7d782019-03-19 14:58:42 -07008126 @TelephonyManager.IsMultiSimSupportedResult
8127 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008128 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8129 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8130 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008131 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8132 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008133 }
8134 // Check if the hardware supports multisim functionality. If usage of multisim is not
8135 // supported by the modem, indicate that it is restricted.
8136 PhoneCapability staticCapability =
8137 mPhoneConfigurationManager.getStaticPhoneCapability();
8138 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008139 loge("isMultiSimSupportedInternal: no static configuration available");
8140 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008141 }
Sarah Chin7caee492020-02-18 20:49:02 +00008142 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008143 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8144 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008145 }
8146 // Check if support of multiple SIMs is restricted by carrier
8147 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008148 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008149 }
8150
Michele0ea7d782019-03-19 14:58:42 -07008151 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008152 }
8153
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008154 /**
8155 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008156 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8157 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8158 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008159 * @param numOfSims number of active sims we want to switch to
8160 */
8161 @Override
8162 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008163 if (numOfSims == 1) {
8164 enforceModifyPermission();
8165 } else {
8166 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8167 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8168 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008169 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008170
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008171 try {
Michele30b57b22019-03-01 12:01:14 -08008172 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008173 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008174 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8175 return;
8176 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008177 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8178 } finally {
8179 Binder.restoreCallingIdentity(identity);
8180 }
8181 }
8182
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008183 @Override
8184 public boolean isApplicationOnUicc(int subId, int appType) {
8185 enforceReadPrivilegedPermission("isApplicationOnUicc");
8186 Phone phone = getPhone(subId);
8187 if (phone == null) {
8188 return false;
8189 }
8190 final long identity = Binder.clearCallingIdentity();
8191 try {
8192 UiccCard uiccCard = phone.getUiccCard();
8193 if (uiccCard == null) {
8194 return false;
8195 }
8196 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8197 if (uiccProfile == null) {
8198 return false;
8199 }
8200 if (TelephonyManager.APPTYPE_SIM <= appType
8201 && appType <= TelephonyManager.APPTYPE_ISIM) {
8202 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8203 }
8204 return false;
8205 } finally {
8206 Binder.restoreCallingIdentity(identity);
8207 }
8208 }
8209
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008210 /**
chen xub4baa772019-04-03 10:23:41 -07008211 * Get whether making changes to modem configurations will trigger reboot.
8212 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008213 */
8214 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008215 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8216 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008217 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008218 mApp, subId, callingPackage, callingFeatureId,
8219 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008220 return false;
8221 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008222 final long identity = Binder.clearCallingIdentity();
8223 try {
8224 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8225 } finally {
8226 Binder.restoreCallingIdentity(identity);
8227 }
8228 }
8229
Nathan Harold29f5f052019-02-15 13:41:57 -08008230 private void updateModemStateMetrics() {
8231 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8232 // TODO: check the state for each modem if the api is ready.
8233 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8234 }
8235
Pengquan Meng3889a572019-01-23 11:16:29 -08008236 @Override
8237 public int[] getSlotsMapping() {
8238 enforceReadPrivilegedPermission("getSlotsMapping");
8239
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8243 // All logical slots should have a mapping to a physical slot.
8244 int[] logicalSlotsMapping = new int[phoneCount];
8245 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8246 for (int i = 0; i < slotInfos.length; i++) {
8247 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8248 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8249 }
8250 }
8251 return logicalSlotsMapping;
8252 } finally {
8253 Binder.restoreCallingIdentity(identity);
8254 }
8255 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008256
8257 /**
8258 * Get the IRadio HAL Version
8259 */
8260 @Override
8261 public int getRadioHalVersion() {
8262 Phone phone = getDefaultPhone();
8263 if (phone == null) return -1;
8264 HalVersion hv = phone.getHalVersion();
8265 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8266 return hv.major * 100 + hv.minor;
8267 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008268
8269 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008270 * Get the current calling package name.
8271 * @return the current calling package name
8272 */
8273 @Override
8274 public String getCurrentPackageName() {
8275 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8276 }
8277
8278 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008279 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8280 * corresponding network requests on a subId.
8281 *
8282 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008283 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008284 * 2) APN is un-metered for this subscription, or
8285 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008286 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008287 *
8288 * @return whether data is allowed for a apn type.
8289 *
8290 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008291 */
8292 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008293 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008294 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8295 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008296
8297 // Now that all security checks passes, perform the operation as ourselves.
8298 final long identity = Binder.clearCallingIdentity();
8299 try {
8300 Phone phone = getPhone(subId);
8301 if (phone == null) return false;
8302
Jack Yu41407ee2019-05-13 16:54:09 -07008303 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008304 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8305 } finally {
8306 Binder.restoreCallingIdentity(identity);
8307 }
8308 }
8309
8310 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008311 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008312 enforceReadPrivilegedPermission("isApnMetered");
8313
8314 // Now that all security checks passes, perform the operation as ourselves.
8315 final long identity = Binder.clearCallingIdentity();
8316 try {
8317 Phone phone = getPhone(subId);
8318 if (phone == null) return true; // By default return true.
8319
Jack Yu41407ee2019-05-13 16:54:09 -07008320 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008321 } finally {
8322 Binder.restoreCallingIdentity(identity);
8323 }
8324 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008325
8326 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008327 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8328 int subscriptionId, IBooleanConsumer resultCallback) {
8329 enforceModifyPermission();
8330 long token = Binder.clearCallingIdentity();
8331 try {
8332 Phone phone = getPhone(subscriptionId);
8333 if (phone == null) {
8334 try {
8335 if (resultCallback != null) {
8336 resultCallback.accept(false);
8337 }
8338 } catch (RemoteException e) {
8339 // ignore
8340 }
8341 return;
8342 }
8343 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8344 Pair.create(specifiers, (x) -> {
8345 try {
8346 if (resultCallback != null) {
8347 resultCallback.accept(x);
8348 }
8349 } catch (RemoteException e) {
8350 // ignore
8351 }
8352 });
8353 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8354 } finally {
8355 Binder.restoreCallingIdentity(token);
8356 }
8357 }
8358
8359 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008360 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008361 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008362 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8363 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8364 if (iccRecords == null) {
8365 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8366 return false;
8367 }
8368 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8369 }
8370
8371 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008372 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8373 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008374 if (callingPackage == null) {
8375 callingPackage = getCurrentPackageName();
8376 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008377 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8378 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008379 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8380 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008381 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8382 }
8383 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8384 Intent intent = new Intent();
8385 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8386 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8387 // Bring up choose default SMS subscription dialog right now
8388 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8389 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8390 mApp.startActivity(intent);
8391 }
chen xud5ca2d52019-05-28 15:20:57 -07008392
8393 @Override
8394 public String getMmsUAProfUrl(int subId) {
8395 //TODO investigate if this API should require proper permission check in R b/133791609
8396 final long identity = Binder.clearCallingIdentity();
8397 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008398 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8399 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008400 } finally {
8401 Binder.restoreCallingIdentity(identity);
8402 }
8403 }
8404
8405 @Override
8406 public String getMmsUserAgent(int subId) {
8407 //TODO investigate if this API should require proper permission check in R b/133791609
8408 final long identity = Binder.clearCallingIdentity();
8409 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008410 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8411 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008412 } finally {
8413 Binder.restoreCallingIdentity(identity);
8414 }
8415 }
Jack Yub07d4972019-05-28 16:12:25 -07008416
8417 @Override
8418 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8419 enforceModifyPermission();
8420
8421 // Now that all security checks passes, perform the operation as ourselves.
8422 final long identity = Binder.clearCallingIdentity();
8423 try {
8424 Phone phone = getPhone(subId);
8425 if (phone == null) return false;
8426
8427 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8428 } finally {
8429 Binder.restoreCallingIdentity(identity);
8430 }
8431 }
8432
8433 @Override
8434 public boolean isDataAllowedInVoiceCall(int subId) {
8435 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8436
8437 // Now that all security checks passes, perform the operation as ourselves.
8438 final long identity = Binder.clearCallingIdentity();
8439 try {
8440 Phone phone = getPhone(subId);
8441 if (phone == null) return false;
8442
8443 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8444 } finally {
8445 Binder.restoreCallingIdentity(identity);
8446 }
8447 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008448
changbettyd5c246e2019-12-24 15:40:37 +08008449 @Override
8450 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8451 enforceModifyPermission();
8452
8453 // Now that all security checks passes, perform the operation as ourselves.
8454 final long identity = Binder.clearCallingIdentity();
8455 try {
8456 Phone phone = getPhone(subId);
8457 if (phone == null) return false;
8458
8459 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8460 } finally {
8461 Binder.restoreCallingIdentity(identity);
8462 }
8463 }
8464
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008465 /**
8466 * Updates whether conference event pacakge handling is enabled.
8467 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8468 * otherwise.
8469 */
8470 @Override
8471 public void setCepEnabled(boolean isCepEnabled) {
8472 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8473
8474 final long identity = Binder.clearCallingIdentity();
8475 try {
8476 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8477 for (Phone phone : PhoneFactory.getPhones()) {
8478 Phone defaultPhone = phone.getImsPhone();
8479 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8480 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8481 ImsPhoneCallTracker imsPhoneCallTracker =
8482 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8483 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8484 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8485 + imsPhone.getMsisdn());
8486 }
8487 }
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 }
allenwtsu46dcc572020-01-08 18:24:03 +08008492
8493 /**
8494 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8495 *
8496 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8497 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8498 * before being read.
8499 */
8500 @Override
8501 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8502 isCompressed) {
8503 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8504 mApp, subId, "notifyRcsAutoConfigurationReceived");
8505 try {
8506 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8507 if (configBinder == null) {
8508 Rlog.e(LOG_TAG, "null result for getImsConfig");
8509 } else {
8510 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8511 }
8512 } catch (RemoteException e) {
8513 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8514 }
8515 }
zoey chene02881a2019-12-30 16:11:23 +08008516
8517 @Override
8518 public boolean isIccLockEnabled(int subId) {
8519 enforceReadPrivilegedPermission("isIccLockEnabled");
8520
8521 // Now that all security checks passes, perform the operation as ourselves.
8522 final long identity = Binder.clearCallingIdentity();
8523 try {
8524 Phone phone = getPhone(subId);
8525 if (phone != null && phone.getIccCard() != null) {
8526 return phone.getIccCard().getIccLockEnabled();
8527 } else {
8528 return false;
8529 }
8530 } finally {
8531 Binder.restoreCallingIdentity(identity);
8532 }
8533 }
8534
8535 /**
8536 * Set the ICC pin lock enabled or disabled.
8537 *
8538 * @return an integer representing the status of IccLock enabled or disabled in the following
8539 * three cases:
8540 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8541 * successfully.
8542 * - Positive number and zero for remaining password attempts.
8543 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8544 *
8545 */
8546 @Override
8547 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8548 enforceModifyPermission();
8549
8550 Phone phone = getPhone(subId);
8551 if (phone == null) {
8552 return 0;
8553 }
8554 // Now that all security checks passes, perform the operation as ourselves.
8555 final long identity = Binder.clearCallingIdentity();
8556 try {
8557 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8558 new Pair<Boolean, String>(enabled, password), phone, null);
8559 return attemptsRemaining;
8560
8561 } catch (Exception e) {
8562 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8563 } finally {
8564 Binder.restoreCallingIdentity(identity);
8565 }
8566 return 0;
8567 }
8568
8569 /**
8570 * Change the ICC password used in ICC pin lock.
8571 *
8572 * @return an integer representing the status of IccLock changed in the following three cases:
8573 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8574 * - Positive number and zero for remaining password attempts.
8575 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8576 *
8577 */
8578 @Override
8579 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8580 enforceModifyPermission();
8581
8582 Phone phone = getPhone(subId);
8583 if (phone == null) {
8584 return 0;
8585 }
8586 // Now that all security checks passes, perform the operation as ourselves.
8587 final long identity = Binder.clearCallingIdentity();
8588 try {
8589 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8590 new Pair<String, String>(oldPassword, newPassword), phone, null);
8591 return attemptsRemaining;
8592
8593 } catch (Exception e) {
8594 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8595 } finally {
8596 Binder.restoreCallingIdentity(identity);
8597 }
8598 return 0;
8599 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008600
8601 /**
8602 * Request for receiving user activity notification
8603 */
8604 @Override
8605 public void requestUserActivityNotification() {
8606 if (!mNotifyUserActivity.get()
8607 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8608 mNotifyUserActivity.set(true);
8609 }
8610 }
8611
8612 /**
8613 * Called when userActivity is signalled in the power manager.
8614 * This is safe to call from any thread, with any window manager locks held or not.
8615 */
8616 @Override
8617 public void userActivity() {
8618 // ***************************************
8619 // * Inherited from PhoneWindowManager *
8620 // ***************************************
8621 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8622 // WITH ITS LOCKS HELD.
8623 //
8624 // This code must be VERY careful about the locks
8625 // it acquires.
8626 // In fact, the current code acquires way too many,
8627 // and probably has lurking deadlocks.
8628
8629 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8630 throw new SecurityException("Only the OS may call notifyUserActivity()");
8631 }
8632
8633 if (mNotifyUserActivity.getAndSet(false)) {
8634 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8635 USER_ACTIVITY_NOTIFICATION_DELAY);
8636 }
8637 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008638
8639 @Override
8640 public boolean canConnectTo5GInDsdsMode() {
8641 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8642 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008643}