blob: 6d0c4d28a671b1db522bf84c5c36e6f41dfaa7c6 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
Hall Liua1548bd2019-12-24 14:14:12 -080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Hall Liua1548bd2019-12-24 14:14:12 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qiancd19c462020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nallurid63128d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim14bb3d02018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xu227e06f2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
Shuo Qian4a594052020-01-23 11:59:30 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhao2737e882019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wanga10e89e2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebingera34a6c22019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.IImsMmTelFeature;
108import android.telephony.ims.aidl.IImsRcsFeature;
109import android.telephony.ims.aidl.IImsRegistration;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700110import android.telephony.ims.aidl.IImsRegistrationCallback;
Brad Ebingerbc7dd582019-10-17 17:03:22 -0700111import android.telephony.ims.feature.ImsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800112import android.telephony.ims.feature.MmTelFeature;
allenwtsu99c623b2020-01-03 18:24:23 +0800113import android.telephony.ims.feature.RcsFeature;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800114import android.telephony.ims.stub.ImsConfigImplBase;
Brad Ebinger1f2b5082018-02-08 16:11:32 -0800115import android.telephony.ims.stub.ImsRegistrationImplBase;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700116import android.text.TextUtils;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800117import android.util.ArraySet;
Hall Liud60acc92020-05-21 17:09:35 -0700118import android.util.EventLog;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700119import android.util.Log;
Jake Hambye994d462014-02-03 13:10:13 -0800120import android.util.Pair;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800121
Andrew Lee312e8172014-10-23 17:01:36 -0700122import com.android.ims.ImsManager;
Brad Ebinger34bef922017-11-09 10:27:08 -0800123import com.android.ims.internal.IImsServiceFeatureCallback;
Shuo Qian4a594052020-01-23 11:59:30 -0800124import com.android.internal.telephony.CallForwardInfo;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700125import com.android.internal.telephony.CallManager;
Tyler Gunn52dcf772017-04-26 11:30:31 -0700126import com.android.internal.telephony.CallStateException;
pkanwar79ec0542017-07-31 14:10:01 -0700127import com.android.internal.telephony.CarrierInfoManager;
chen xu651eec72018-11-11 19:03:44 -0800128import com.android.internal.telephony.CarrierResolver;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700129import com.android.internal.telephony.CellNetworkScanResult;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700130import com.android.internal.telephony.CommandException;
Shuo Qian4a594052020-01-23 11:59:30 -0800131import com.android.internal.telephony.CommandsInterface;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700132import com.android.internal.telephony.DefaultPhoneNotifier;
Nathan Harold48d6fd52019-02-06 19:01:40 -0800133import com.android.internal.telephony.HalVersion;
Hall Liu73f5d362020-01-20 13:42:00 -0800134import com.android.internal.telephony.IBooleanConsumer;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700135import com.android.internal.telephony.IIntegerConsumer;
Hall Liud892bec2018-11-30 14:51:45 -0800136import com.android.internal.telephony.INumberVerificationCallback;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700137import com.android.internal.telephony.ITelephony;
Jake Hambye994d462014-02-03 13:10:13 -0800138import com.android.internal.telephony.IccCard;
Jack Yu5f7092c2018-04-13 14:05:37 -0700139import com.android.internal.telephony.LocaleTracker;
yinxub1bed742017-04-17 11:45:04 -0700140import com.android.internal.telephony.NetworkScanRequestTracker;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700141import com.android.internal.telephony.OperatorInfo;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700142import com.android.internal.telephony.Phone;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700143import com.android.internal.telephony.PhoneConfigurationManager;
Nathan Harolda667c152016-12-14 11:27:20 -0800144import com.android.internal.telephony.PhoneConstantConversions;
Ta-wei Yen87c49842016-05-13 21:19:52 -0700145import com.android.internal.telephony.PhoneConstants;
Wink Saville36469e72014-06-11 15:17:00 -0700146import com.android.internal.telephony.PhoneFactory;
Wink Saville5d475dd2014-10-17 15:00:58 -0700147import com.android.internal.telephony.ProxyController;
Sanket Padawe99ef1e32016-05-18 16:12:33 -0700148import com.android.internal.telephony.RIL;
Svet Ganovb320e182015-04-16 12:30:10 -0700149import com.android.internal.telephony.RILConstants;
Jack Yu5f7092c2018-04-13 14:05:37 -0700150import com.android.internal.telephony.ServiceStateTracker;
Amit Mahajandccb3f12019-05-13 13:48:32 -0700151import com.android.internal.telephony.SmsController;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700152import com.android.internal.telephony.SmsPermissions;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800153import com.android.internal.telephony.SubscriptionController;
Peter Wang59571be2020-01-27 12:35:15 +0800154import com.android.internal.telephony.TelephonyIntents;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800155import com.android.internal.telephony.TelephonyPermissions;
Malcolm Chendc8c10e2019-04-10 18:25:07 -0700156import com.android.internal.telephony.dataconnection.ApnSettingUtils;
sqianf4ca7ed2019-01-15 18:32:07 -0800157import com.android.internal.telephony.emergency.EmergencyNumberTracker;
Derek Tan740e1672017-06-27 14:56:27 -0700158import com.android.internal.telephony.euicc.EuiccConnector;
Brad Ebinger9c0eb502019-01-23 15:06:19 -0800159import com.android.internal.telephony.ims.ImsResolver;
Tyler Gunn7bcdc742019-10-04 15:56:59 -0700160import com.android.internal.telephony.imsphone.ImsPhone;
161import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
Pengquan Meng6c2dc9f2019-02-06 11:12:53 -0800162import com.android.internal.telephony.metrics.TelephonyMetrics;
Meng Wangafbc5852019-09-19 17:37:13 -0700163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty7157e9e2019-12-06 18:16:37 +0800165import com.android.internal.telephony.uicc.IccRecords;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700166import com.android.internal.telephony.uicc.IccUtils;
Nathan Haroldb3014052017-01-25 15:57:32 -0800167import com.android.internal.telephony.uicc.SIMRecords;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700168import com.android.internal.telephony.uicc.UiccCard;
Nathan Haroldb3014052017-01-25 15:57:32 -0800169import com.android.internal.telephony.uicc.UiccCardApplication;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700170import com.android.internal.telephony.uicc.UiccController;
Jeff Davidson7e17e312018-02-13 18:17:36 -0800171import com.android.internal.telephony.uicc.UiccProfile;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000172import com.android.internal.telephony.uicc.UiccSlot;
zoey chenc730df82019-12-18 17:07:20 +0800173import com.android.internal.telephony.util.LocaleUtils;
fionaxu7ed723d2017-05-30 18:58:54 -0700174import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil;
Jake Hambye994d462014-02-03 13:10:13 -0800175import com.android.internal.util.HexDump;
Brad Ebingera63db5f2019-04-23 16:31:13 -0700176import com.android.phone.settings.PickSmsSubscriptionActivity;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700177import com.android.phone.vvm.PhoneAccountHandleConverter;
Ta-wei Yen527a9c02017-01-06 15:29:25 -0800178import com.android.phone.vvm.RemoteVvmTaskManager;
Ta-wei Yenc9df0432017-04-17 17:09:07 -0700179import com.android.phone.vvm.VisualVoicemailSettingsUtil;
Ta-wei Yenc8905312017-03-28 11:14:45 -0700180import com.android.phone.vvm.VisualVoicemailSmsFilterConfig;
Peter Wang44b186e2020-01-13 23:33:09 -0800181import com.android.telephony.Rlog;
Ta-wei Yen30a69c82016-12-27 14:52:32 -0800182
Ta-wei Yenc236d6b2016-06-21 13:33:12 -0700183import java.io.FileDescriptor;
184import java.io.PrintWriter;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700185import java.util.ArrayList;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800186import java.util.Arrays;
sqian11b7a0e2018-12-05 18:48:28 -0800187import java.util.HashMap;
sqianf4ca7ed2019-01-15 18:32:07 -0800188import java.util.HashSet;
Jake Hambye994d462014-02-03 13:10:13 -0800189import java.util.List;
Narayan Kamath1c496c22015-04-16 14:40:19 +0100190import java.util.Locale;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800191import java.util.Map;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700192import java.util.NoSuchElementException;
sqianf4ca7ed2019-01-15 18:32:07 -0800193import java.util.Set;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800194import java.util.concurrent.atomic.AtomicBoolean;
Hall Liu73f5d362020-01-20 13:42:00 -0800195import java.util.function.Consumer;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700196
197/**
198 * Implementation of the ITelephony interface.
199 */
Santos Cordon117fee72014-05-16 17:56:12 -0700200public class PhoneInterfaceManager extends ITelephony.Stub {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700201 private static final String LOG_TAG = "PhoneInterfaceManager";
202 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
203 private static final boolean DBG_LOC = false;
Jeff Sharkey85190e62014-12-05 09:40:12 -0800204 private static final boolean DBG_MERGE = false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700205
206 // Message codes used with mMainThreadHandler
207 private static final int CMD_HANDLE_PIN_MMI = 1;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700208 private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7;
209 private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700210 private static final int CMD_OPEN_CHANNEL = 9;
211 private static final int EVENT_OPEN_CHANNEL_DONE = 10;
212 private static final int CMD_CLOSE_CHANNEL = 11;
213 private static final int EVENT_CLOSE_CHANNEL_DONE = 12;
Jake Hambye994d462014-02-03 13:10:13 -0800214 private static final int CMD_NV_READ_ITEM = 13;
215 private static final int EVENT_NV_READ_ITEM_DONE = 14;
216 private static final int CMD_NV_WRITE_ITEM = 15;
217 private static final int EVENT_NV_WRITE_ITEM_DONE = 16;
218 private static final int CMD_NV_WRITE_CDMA_PRL = 17;
219 private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18;
chen xu6dac5ab2018-10-26 17:39:23 -0700220 private static final int CMD_RESET_MODEM_CONFIG = 19;
221 private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20;
Jake Hamby7c27be32014-03-03 13:25:59 -0800222 private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21;
223 private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22;
224 private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23;
225 private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24;
Sailesh Nepal35b59452014-03-06 09:26:56 -0800226 private static final int CMD_SEND_ENVELOPE = 25;
227 private static final int EVENT_SEND_ENVELOPE_DONE = 26;
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000228 private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27;
229 private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28;
Derek Tan6b088ee2014-09-05 14:15:18 -0700230 private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29;
231 private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30;
232 private static final int CMD_EXCHANGE_SIM_IO = 31;
233 private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800234 private static final int CMD_SET_VOICEMAIL_NUMBER = 33;
235 private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34;
Stuart Scott54788802015-03-30 13:18:01 -0700236 private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35;
237 private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36;
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -0700238 private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37;
239 private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38;
Shishir Agrawal302c8692015-06-19 13:49:39 -0700240 private static final int CMD_PERFORM_NETWORK_SCAN = 39;
241 private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40;
242 private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41;
243 private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42;
Meng Wang1a7c35a2016-05-05 20:56:15 -0700244 private static final int CMD_SET_ALLOWED_CARRIERS = 43;
245 private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44;
246 private static final int CMD_GET_ALLOWED_CARRIERS = 45;
247 private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46;
pkanwar32d516d2016-10-14 19:37:38 -0700248 private static final int CMD_HANDLE_USSD_REQUEST = 47;
Nathan Haroldb3014052017-01-25 15:57:32 -0800249 private static final int CMD_GET_FORBIDDEN_PLMNS = 48;
250 private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +0000251 private static final int CMD_SWITCH_SLOTS = 50;
252 private static final int EVENT_SWITCH_SLOTS_DONE = 51;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700253 private static final int CMD_GET_NETWORK_SELECTION_MODE = 52;
254 private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53;
255 private static final int CMD_GET_CDMA_ROAMING_MODE = 54;
256 private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55;
257 private static final int CMD_SET_CDMA_ROAMING_MODE = 56;
258 private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57;
259 private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58;
260 private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59;
Nathan Harold3ff88932018-08-14 10:19:49 -0700261 private static final int CMD_GET_ALL_CELL_INFO = 60;
262 private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61;
263 private static final int CMD_GET_CELL_LOCATION = 62;
264 private static final int EVENT_GET_CELL_LOCATION_DONE = 63;
chen xu6dac5ab2018-10-26 17:39:23 -0700265 private static final int CMD_MODEM_REBOOT = 64;
266 private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -0700267 private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66;
268 private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67;
Malcolm Chen8e4ed912019-01-15 20:22:16 -0800269 private static final int CMD_REQUEST_ENABLE_MODEM = 68;
270 private static final int EVENT_ENABLE_MODEM_DONE = 69;
Nazanin Bakhshif71371d2019-04-29 17:29:44 -0700271 private static final int CMD_GET_MODEM_STATUS = 70;
272 private static final int EVENT_GET_MODEM_STATUS_DONE = 71;
yincheng zhao2737e882019-09-06 17:06:54 -0700273 private static final int CMD_SET_FORBIDDEN_PLMNS = 72;
274 private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73;
Naina Nallurid63128d2019-09-17 14:10:30 -0700275 private static final int CMD_ERASE_MODEM_CONFIG = 74;
276 private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75;
zoey chene02881a2019-12-30 16:11:23 +0800277 private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76;
278 private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77;
279 private static final int CMD_SET_ICC_LOCK_ENABLED = 78;
280 private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79;
Hall Liu73f5d362020-01-20 13:42:00 -0800281 private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80;
282 private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800283 private static final int MSG_NOTIFY_USER_ACTIVITY = 82;
Shuo Qian4a594052020-01-23 11:59:30 -0800284 private static final int CMD_GET_CALL_FORWARDING = 83;
285 private static final int EVENT_GET_CALL_FORWARDING_DONE = 84;
286 private static final int CMD_SET_CALL_FORWARDING = 85;
287 private static final int EVENT_SET_CALL_FORWARDING_DONE = 86;
288 private static final int CMD_GET_CALL_WAITING = 87;
289 private static final int EVENT_GET_CALL_WAITING_DONE = 88;
290 private static final int CMD_SET_CALL_WAITING = 89;
291 private static final int EVENT_SET_CALL_WAITING_DONE = 90;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700292
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -0800293 // Parameters of select command.
294 private static final int SELECT_COMMAND = 0xA4;
295 private static final int SELECT_P1 = 0x04;
296 private static final int SELECT_P2 = 0;
297 private static final int SELECT_P3 = 0x10;
298
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700299 /** The singleton instance. */
300 private static PhoneInterfaceManager sInstance;
301
Wink Saville3ab207e2014-11-20 13:07:20 -0800302 private PhoneGlobals mApp;
Wink Saville3ab207e2014-11-20 13:07:20 -0800303 private CallManager mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -0800304 private ImsResolver mImsResolver;
Stuart Scott981d8582015-04-21 14:09:50 -0700305 private UserManager mUserManager;
Wink Saville3ab207e2014-11-20 13:07:20 -0800306 private AppOpsManager mAppOps;
307 private MainThreadHandler mMainThreadHandler;
Wink Savilleac1bdfd2014-11-20 23:04:44 -0800308 private SubscriptionController mSubscriptionController;
Wink Saville3ab207e2014-11-20 13:07:20 -0800309 private SharedPreferences mTelephonySharedPreferences;
Malcolm Chen2c63d402018-08-14 16:00:53 -0700310 private PhoneConfigurationManager mPhoneConfigurationManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700311
Peter Wangdafb9ac2020-01-15 14:13:38 -0800312 /** User Activity */
313 private AtomicBoolean mNotifyUserActivity;
Peter Wangdafb9ac2020-01-15 14:13:38 -0800314 private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200;
315
Jeff Davidson8ab02b22020-03-28 12:24:40 -0700316 private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>();
317
Derek Tan97ebb422014-09-05 16:55:38 -0700318 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
319 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800320 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800321 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700322
Michelecea4cf22018-12-21 15:00:11 -0800323 // String to store multi SIM allowed
324 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
325
Derek Tan740e1672017-06-27 14:56:27 -0700326 // The AID of ISD-R.
327 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
328
yinxub1bed742017-04-17 11:45:04 -0700329 private NetworkScanRequestTracker mNetworkScanRequestTracker;
330
David Kelly5e06a7f2018-03-12 14:10:59 +0000331 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
332 private static final int MANUFACTURER_CODE_LENGTH = 8;
333
Derek Tan89e89d42014-07-08 17:00:10 -0700334 /**
Naina Nallurid63128d2019-09-17 14:10:30 -0700335 * Experiment flag to enable erase modem config on reset network, default value is false
336 */
337 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
338 "reset_network_erase_modem_config_enabled";
339
340 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700341 * A request object to use for transmitting data to an ICC.
342 */
343 private static final class IccAPDUArgument {
344 public int channel, cla, command, p1, p2, p3;
345 public String data;
346
347 public IccAPDUArgument(int channel, int cla, int command,
348 int p1, int p2, int p3, String data) {
349 this.channel = channel;
350 this.cla = cla;
351 this.command = command;
352 this.p1 = p1;
353 this.p2 = p2;
354 this.p3 = p3;
355 this.data = data;
356 }
357 }
358
359 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700360 * A request object to use for transmitting data to an ICC.
361 */
362 private static final class ManualNetworkSelectionArgument {
363 public OperatorInfo operatorInfo;
364 public boolean persistSelection;
365
366 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
367 this.operatorInfo = operatorInfo;
368 this.persistSelection = persistSelection;
369 }
370 }
371
372 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700373 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
374 * request after sending. The main thread will notify the request when it is complete.
375 */
376 private static final class MainThreadRequest {
377 /** The argument to use for the request */
378 public Object argument;
379 /** The result of the request that is run on the main thread */
380 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800381 // The subscriber id that this request applies to. Defaults to
382 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
383 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700384
Nathan Harold92bed182018-10-12 18:16:49 -0700385 // In cases where subId is unavailable, the caller needs to specify the phone.
386 public Phone phone;
387
vagdeviaf9a5b92018-08-15 16:01:53 -0700388 public WorkSource workSource;
389
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700390 public MainThreadRequest(Object argument) {
391 this.argument = argument;
392 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800393
Nathan Harold92bed182018-10-12 18:16:49 -0700394 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
395 this.argument = argument;
396 if (phone != null) {
397 this.phone = phone;
398 }
399 this.workSource = workSource;
400 }
401
vagdeviaf9a5b92018-08-15 16:01:53 -0700402 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800403 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800404 if (subId != null) {
405 this.subId = subId;
406 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700407 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800408 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700409 }
410
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800411 private static final class IncomingThirdPartyCallArgs {
412 public final ComponentName component;
413 public final String callId;
414 public final String callerDisplayName;
415
416 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
417 String callerDisplayName) {
418 this.component = component;
419 this.callId = callId;
420 this.callerDisplayName = callerDisplayName;
421 }
422 }
423
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700424 /**
425 * A handler that processes messages on the main thread in the phone process. Since many
426 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
427 * inbound binder threads to the main thread in the phone process. The Binder thread
428 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
429 * on, which will be notified when the operation completes and will contain the result of the
430 * request.
431 *
432 * <p>If a MainThreadRequest object is provided in the msg.obj field,
433 * note that request.result must be set to something non-null for the calling thread to
434 * unblock.
435 */
436 private final class MainThreadHandler extends Handler {
437 @Override
438 public void handleMessage(Message msg) {
439 MainThreadRequest request;
440 Message onCompleted;
441 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800442 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700443 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800444 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700445
446 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700447 case CMD_HANDLE_USSD_REQUEST: {
448 request = (MainThreadRequest) msg.obj;
449 final Phone phone = getPhoneFromRequest(request);
450 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
451 String ussdRequest = ussdObject.first;
452 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700453
Pengquan Menga1bb6272018-09-06 09:59:22 -0700454 if (!isUssdApiAllowed(request.subId)) {
455 // Carrier does not support use of this API, return failure.
456 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
457 UssdResponse response = new UssdResponse(ussdRequest, null);
458 Bundle returnData = new Bundle();
459 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
460 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700461
Pengquan Menga1bb6272018-09-06 09:59:22 -0700462 request.result = true;
463 notifyRequester(request);
464 return;
465 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700466
Pengquan Menga1bb6272018-09-06 09:59:22 -0700467 try {
468 request.result = phone != null
469 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
470 } catch (CallStateException cse) {
471 request.result = false;
472 }
473 // Wake up the requesting thread
474 notifyRequester(request);
475 break;
pkanwar32d516d2016-10-14 19:37:38 -0700476 }
477
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700479 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700480 final Phone phone = getPhoneFromRequest(request);
481 request.result = phone != null ?
482 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
483 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700485 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700487 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700488
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700490 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700491 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800492 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700493 if (uiccCard == null) {
494 loge("iccTransmitApduLogicalChannel: No UICC");
495 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700496 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700497 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700498 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
499 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700500 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700501 iccArgument.channel, iccArgument.cla, iccArgument.command,
502 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700504 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700505 break;
506
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700507 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700508 ar = (AsyncResult) msg.obj;
509 request = (MainThreadRequest) ar.userObj;
510 if (ar.exception == null && ar.result != null) {
511 request.result = ar.result;
512 } else {
513 request.result = new IccIoResult(0x6F, 0, (byte[])null);
514 if (ar.result == null) {
515 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800516 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800518 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700519 } else {
520 loge("iccTransmitApduLogicalChannel: Unknown exception");
521 }
522 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700523 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700524 break;
525
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700526 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
527 request = (MainThreadRequest) msg.obj;
528 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800529 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700530 if (uiccCard == null) {
531 loge("iccTransmitApduBasicChannel: No UICC");
532 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700533 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700534 } else {
535 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
536 request);
537 uiccCard.iccTransmitApduBasicChannel(
538 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
539 iccArgument.p3, iccArgument.data, onCompleted);
540 }
541 break;
542
543 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
544 ar = (AsyncResult) msg.obj;
545 request = (MainThreadRequest) ar.userObj;
546 if (ar.exception == null && ar.result != null) {
547 request.result = ar.result;
548 } else {
549 request.result = new IccIoResult(0x6F, 0, (byte[])null);
550 if (ar.result == null) {
551 loge("iccTransmitApduBasicChannel: Empty response");
552 } else if (ar.exception instanceof CommandException) {
553 loge("iccTransmitApduBasicChannel: CommandException: " +
554 ar.exception);
555 } else {
556 loge("iccTransmitApduBasicChannel: Unknown exception");
557 }
558 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700559 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700560 break;
561
562 case CMD_EXCHANGE_SIM_IO:
563 request = (MainThreadRequest) msg.obj;
564 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800565 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700566 if (uiccCard == null) {
567 loge("iccExchangeSimIO: No UICC");
568 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700569 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700570 } else {
571 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
572 request);
573 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
574 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
575 iccArgument.data, onCompleted);
576 }
577 break;
578
579 case EVENT_EXCHANGE_SIM_IO_DONE:
580 ar = (AsyncResult) msg.obj;
581 request = (MainThreadRequest) ar.userObj;
582 if (ar.exception == null && ar.result != null) {
583 request.result = ar.result;
584 } else {
585 request.result = new IccIoResult(0x6f, 0, (byte[])null);
586 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700587 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700588 break;
589
Derek Tan4d5e5c12014-02-04 11:54:58 -0800590 case CMD_SEND_ENVELOPE:
591 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800592 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700593 if (uiccCard == null) {
594 loge("sendEnvelopeWithStatus: No UICC");
595 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700596 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700597 } else {
598 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
599 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
600 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800601 break;
602
603 case EVENT_SEND_ENVELOPE_DONE:
604 ar = (AsyncResult) msg.obj;
605 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700606 if (ar.exception == null && ar.result != null) {
607 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800608 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700609 request.result = new IccIoResult(0x6F, 0, (byte[])null);
610 if (ar.result == null) {
611 loge("sendEnvelopeWithStatus: Empty response");
612 } else if (ar.exception instanceof CommandException) {
613 loge("sendEnvelopeWithStatus: CommandException: " +
614 ar.exception);
615 } else {
616 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
617 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700619 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800620 break;
621
Shishir Agrawal566b7612013-10-28 14:41:00 -0700622 case CMD_OPEN_CHANNEL:
623 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800624 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800625 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700626 if (uiccCard == null) {
627 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800628 request.result = new IccOpenLogicalChannelResponse(-1,
629 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700630 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700631 } else {
632 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800633 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
634 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700635 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700636 break;
637
638 case EVENT_OPEN_CHANNEL_DONE:
639 ar = (AsyncResult) msg.obj;
640 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700642 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700643 int[] result = (int[]) ar.result;
644 int channelId = result[0];
645 byte[] selectResponse = null;
646 if (result.length > 1) {
647 selectResponse = new byte[result.length - 1];
648 for (int i = 1; i < result.length; ++i) {
649 selectResponse[i - 1] = (byte) result[i];
650 }
651 }
652 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700653 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700654 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 if (ar.result == null) {
656 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700657 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700658 if (ar.exception != null) {
659 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
660 }
661
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700662 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700663 if (ar.exception instanceof CommandException) {
664 CommandException.Error error =
665 ((CommandException) (ar.exception)).getCommandError();
666 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700668 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700669 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700670 }
671 }
672 openChannelResp = new IccOpenLogicalChannelResponse(
673 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700674 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700675 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700676 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700677 break;
678
679 case CMD_CLOSE_CHANNEL:
680 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800681 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700682 if (uiccCard == null) {
683 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900684 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700685 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700686 } else {
687 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
688 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
689 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700690 break;
691
692 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800693 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
694 break;
695
696 case CMD_NV_READ_ITEM:
697 request = (MainThreadRequest) msg.obj;
698 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800699 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
700 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800701 break;
702
703 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700704 ar = (AsyncResult) msg.obj;
705 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800706 if (ar.exception == null && ar.result != null) {
707 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700708 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800709 request.result = "";
710 if (ar.result == null) {
711 loge("nvReadItem: Empty response");
712 } else if (ar.exception instanceof CommandException) {
713 loge("nvReadItem: CommandException: " +
714 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800716 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700717 }
718 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700719 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700720 break;
721
Jake Hambye994d462014-02-03 13:10:13 -0800722 case CMD_NV_WRITE_ITEM:
723 request = (MainThreadRequest) msg.obj;
724 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
725 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800726 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700727 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800728 break;
729
730 case EVENT_NV_WRITE_ITEM_DONE:
731 handleNullReturnEvent(msg, "nvWriteItem");
732 break;
733
734 case CMD_NV_WRITE_CDMA_PRL:
735 request = (MainThreadRequest) msg.obj;
736 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800737 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800738 break;
739
740 case EVENT_NV_WRITE_CDMA_PRL_DONE:
741 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
742 break;
743
chen xu6dac5ab2018-10-26 17:39:23 -0700744 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800745 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700746 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800747 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800748 break;
749
chen xu6dac5ab2018-10-26 17:39:23 -0700750 case EVENT_RESET_MODEM_CONFIG_DONE:
751 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800752 break;
753
Jake Hamby7c27be32014-03-03 13:25:59 -0800754 case CMD_GET_PREFERRED_NETWORK_TYPE:
755 request = (MainThreadRequest) msg.obj;
756 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700757 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800758 break;
759
760 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
761 ar = (AsyncResult) msg.obj;
762 request = (MainThreadRequest) ar.userObj;
763 if (ar.exception == null && ar.result != null) {
764 request.result = ar.result; // Integer
765 } else {
Sanket Padawecfc2d352016-01-05 19:52:14 -0800766 request.result = null;
Jake Hamby7c27be32014-03-03 13:25:59 -0800767 if (ar.result == null) {
768 loge("getPreferredNetworkType: Empty response");
769 } else if (ar.exception instanceof CommandException) {
770 loge("getPreferredNetworkType: CommandException: " +
771 ar.exception);
772 } else {
773 loge("getPreferredNetworkType: Unknown exception");
774 }
775 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700776 notifyRequester(request);
Jake Hamby7c27be32014-03-03 13:25:59 -0800777 break;
778
779 case CMD_SET_PREFERRED_NETWORK_TYPE:
780 request = (MainThreadRequest) msg.obj;
781 onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request);
782 int networkType = (Integer) request.argument;
Stuart Scott54788802015-03-30 13:18:01 -0700783 getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800784 break;
785
786 case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE:
787 handleNullReturnEvent(msg, "setPreferredNetworkType");
788 break;
789
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000790 case CMD_INVOKE_OEM_RIL_REQUEST_RAW:
791 request = (MainThreadRequest)msg.obj;
792 onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800793 defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000794 break;
795
796 case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE:
797 ar = (AsyncResult)msg.obj;
798 request = (MainThreadRequest)ar.userObj;
799 request.result = ar;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700800 notifyRequester(request);
Shuo Qian850e4d6a2018-04-25 21:02:08 +0000801 break;
802
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800803 case CMD_SET_VOICEMAIL_NUMBER:
804 request = (MainThreadRequest) msg.obj;
805 onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request);
806 Pair<String, String> tagNum = (Pair<String, String>) request.argument;
Stuart Scott584921c2015-01-15 17:10:34 -0800807 getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second,
808 onCompleted);
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800809 break;
810
811 case EVENT_SET_VOICEMAIL_NUMBER_DONE:
812 handleNullReturnEvent(msg, "setVoicemailNumber");
813 break;
814
Stuart Scott54788802015-03-30 13:18:01 -0700815 case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC:
816 request = (MainThreadRequest) msg.obj;
817 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE,
818 request);
819 getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted);
820 break;
821
822 case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE:
823 handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic");
824 break;
825
Shishir Agrawal302c8692015-06-19 13:49:39 -0700826 case CMD_PERFORM_NETWORK_SCAN:
827 request = (MainThreadRequest) msg.obj;
828 onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request);
829 getPhoneFromRequest(request).getAvailableNetworks(onCompleted);
830 break;
831
Shuo Qian4a594052020-01-23 11:59:30 -0800832 case CMD_GET_CALL_FORWARDING:
833 request = (MainThreadRequest) msg.obj;
834 onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request);
835 int callForwardingReason = (Integer) request.argument;
836 getPhoneFromRequest(request).getCallForwardingOption(
837 callForwardingReason, onCompleted);
838 break;
839
840 case EVENT_GET_CALL_FORWARDING_DONE:
841 ar = (AsyncResult) msg.obj;
842 request = (MainThreadRequest) ar.userObj;
843 CallForwardingInfo callForwardingInfo = null;
844 if (ar.exception == null && ar.result != null) {
845 CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result;
846 for (CallForwardInfo callForwardInfo : callForwardInfos) {
847 // Service Class is a bit mask per 3gpp 27.007. Search for
848 // any service for voice call.
849 if ((callForwardInfo.serviceClass
850 & CommandsInterface.SERVICE_CLASS_VOICE) > 0) {
851 callForwardingInfo = new CallForwardingInfo(
852 callForwardInfo.serviceClass, callForwardInfo.reason,
853 callForwardInfo.number,
854 callForwardInfo.timeSeconds);
855 break;
856 }
857 }
858 // Didn't find a call forward info for voice call.
859 if (callForwardingInfo == null) {
860 callForwardingInfo = new CallForwardingInfo(
861 CallForwardingInfo.STATUS_UNKNOWN_ERROR,
862 0 /* reason */, null /* number */, 0 /* timeout */);
863 }
864 } else {
865 if (ar.result == null) {
866 loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response");
867 }
868 if (ar.exception != null) {
869 loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception);
870 }
871 int errorCode = CallForwardingInfo.STATUS_UNKNOWN_ERROR;
872 if (ar.exception instanceof CommandException) {
873 CommandException.Error error =
874 ((CommandException) (ar.exception)).getCommandError();
875 if (error == CommandException.Error.FDN_CHECK_FAILURE) {
876 errorCode = CallForwardingInfo.STATUS_FDN_CHECK_FAILURE;
877 } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
878 errorCode = CallForwardingInfo.STATUS_NOT_SUPPORTED;
879 }
880 }
881 callForwardingInfo = new CallForwardingInfo(
882 errorCode, 0 /* reason */, null /* number */, 0 /* timeout */);
883 }
884 request.result = callForwardingInfo;
885 notifyRequester(request);
886 break;
887
888 case CMD_SET_CALL_FORWARDING:
889 request = (MainThreadRequest) msg.obj;
890 onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request);
891 CallForwardingInfo callForwardingInfoToSet =
892 (CallForwardingInfo) request.argument;
893 getPhoneFromRequest(request).setCallForwardingOption(
894 callForwardingInfoToSet.getStatus(),
895 callForwardingInfoToSet.getReason(),
896 callForwardingInfoToSet.getNumber(),
897 callForwardingInfoToSet.getTimeoutSeconds(), onCompleted);
898 break;
899
900 case EVENT_SET_CALL_FORWARDING_DONE:
901 ar = (AsyncResult) msg.obj;
902 request = (MainThreadRequest) ar.userObj;
903 if (ar.exception == null) {
904 request.result = true;
905 } else {
906 request.result = false;
907 loge("setCallForwarding exception: " + ar.exception);
908 }
909 notifyRequester(request);
910 break;
911
912 case CMD_GET_CALL_WAITING:
913 request = (MainThreadRequest) msg.obj;
914 onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request);
915 getPhoneFromRequest(request).getCallWaiting(onCompleted);
916 break;
917
918 case EVENT_GET_CALL_WAITING_DONE:
919 ar = (AsyncResult) msg.obj;
920 request = (MainThreadRequest) ar.userObj;
921 int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
922 if (ar.exception == null && ar.result != null) {
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800923 int[] callForwardResults = (int[]) ar.result;
Shuo Qian4a594052020-01-23 11:59:30 -0800924 // Service Class is a bit mask per 3gpp 27.007.
925 // Search for any service for voice call.
Shuo Qiand6a0dba2020-02-18 18:13:49 -0800926 if (callForwardResults.length > 1
927 && ((callForwardResults[1]
928 & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) {
929 callForwardingStatus = callForwardResults[0] == 0
Shuo Qian4a594052020-01-23 11:59:30 -0800930 ? TelephonyManager.CALL_WAITING_STATUS_INACTIVE
931 : TelephonyManager.CALL_WAITING_STATUS_ACTIVE;
932 } else {
933 callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_INACTIVE;
934 }
935 } else {
936 if (ar.result == null) {
937 loge("EVENT_GET_CALL_WAITING_DONE: Empty response");
938 }
939 if (ar.exception != null) {
940 loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception);
941 }
942 if (ar.exception instanceof CommandException) {
943 CommandException.Error error =
944 ((CommandException) (ar.exception)).getCommandError();
945 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
946 callForwardingStatus =
947 TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED;
948 }
949 }
950 }
951 request.result = callForwardingStatus;
952 notifyRequester(request);
953 break;
954
955 case CMD_SET_CALL_WAITING:
956 request = (MainThreadRequest) msg.obj;
957 onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request);
958 boolean isEnable = (Boolean) request.argument;
959 getPhoneFromRequest(request).setCallWaiting(isEnable, onCompleted);
960 break;
961
962 case EVENT_SET_CALL_WAITING_DONE:
963 ar = (AsyncResult) msg.obj;
964 request = (MainThreadRequest) ar.userObj;
965 if (ar.exception == null) {
966 request.result = true;
967 } else {
968 request.result = false;
969 loge("setCallWaiting exception: " + ar.exception);
970 }
971 notifyRequester(request);
972 break;
973
Shishir Agrawal302c8692015-06-19 13:49:39 -0700974 case EVENT_PERFORM_NETWORK_SCAN_DONE:
975 ar = (AsyncResult) msg.obj;
976 request = (MainThreadRequest) ar.userObj;
977 CellNetworkScanResult cellScanResult;
978 if (ar.exception == null && ar.result != null) {
979 cellScanResult = new CellNetworkScanResult(
980 CellNetworkScanResult.STATUS_SUCCESS,
981 (List<OperatorInfo>) ar.result);
982 } else {
983 if (ar.result == null) {
984 loge("getCellNetworkScanResults: Empty response");
985 }
986 if (ar.exception != null) {
987 loge("getCellNetworkScanResults: Exception: " + ar.exception);
988 }
989 int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR;
990 if (ar.exception instanceof CommandException) {
991 CommandException.Error error =
992 ((CommandException) (ar.exception)).getCommandError();
993 if (error == CommandException.Error.RADIO_NOT_AVAILABLE) {
994 errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE;
995 } else if (error == CommandException.Error.GENERIC_FAILURE) {
996 errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE;
997 }
998 }
999 cellScanResult = new CellNetworkScanResult(errorCode, null);
1000 }
1001 request.result = cellScanResult;
Pengquan Menga1bb6272018-09-06 09:59:22 -07001002 notifyRequester(request);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001003 break;
1004
1005 case CMD_SET_NETWORK_SELECTION_MODE_MANUAL:
1006 request = (MainThreadRequest) msg.obj;
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001007 ManualNetworkSelectionArgument selArg =
1008 (ManualNetworkSelectionArgument) request.argument;
Shishir Agrawal302c8692015-06-19 13:49:39 -07001009 onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE,
1010 request);
Shishir Agrawal77ba3172015-09-10 14:50:19 -07001011 getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo,
1012 selArg.persistSelection, onCompleted);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001013 break;
1014
1015 case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE:
Pengquan Menge3d01e22018-09-20 15:25:35 -07001016 ar = (AsyncResult) msg.obj;
1017 request = (MainThreadRequest) ar.userObj;
1018 if (ar.exception == null) {
1019 request.result = true;
1020 } else {
1021 request.result = false;
1022 loge("setNetworkSelectionModeManual " + ar.exception);
1023 }
1024 notifyRequester(request);
1025 mApp.onNetworkSelectionChanged(request.subId);
Shishir Agrawal302c8692015-06-19 13:49:39 -07001026 break;
1027
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001028 case CMD_GET_MODEM_ACTIVITY_INFO:
1029 request = (MainThreadRequest) msg.obj;
1030 onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request);
James Mattisab947702019-04-03 14:18:34 -07001031 if (defaultPhone != null) {
1032 defaultPhone.getModemActivityInfo(onCompleted, request.workSource);
Shuo Qian8f4750a2020-02-20 17:12:10 -08001033 } else {
1034 ResultReceiver result = (ResultReceiver) request.argument;
1035 Bundle bundle = new Bundle();
1036 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY,
1037 new ModemActivityInfo(0, 0, 0, new int[0], 0));
1038 result.send(0, bundle);
James Mattisab947702019-04-03 14:18:34 -07001039 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001040 break;
1041
1042 case EVENT_GET_MODEM_ACTIVITY_INFO_DONE:
1043 ar = (AsyncResult) msg.obj;
1044 request = (MainThreadRequest) ar.userObj;
Shuo Qian8f4750a2020-02-20 17:12:10 -08001045 ResultReceiver result = (ResultReceiver) request.argument;
1046
1047 ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001048 if (ar.exception == null && ar.result != null) {
Shuo Qian8f4750a2020-02-20 17:12:10 -08001049 // Update the last modem activity info and the result of the request.
1050 ModemActivityInfo info = (ModemActivityInfo) ar.result;
1051 if (isModemActivityInfoValid(info)) {
1052 int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS];
1053 int[] txTimeMs = info.getTransmitTimeMillis();
1054 int[] lastModemTxTimeMs = mLastModemActivityInfo
1055 .getTransmitTimeMillis();
1056 for (int i = 0; i < mergedTxTimeMs.length; i++) {
1057 mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i];
1058 }
1059 mLastModemActivityInfo.setTimestamp(info.getTimestamp());
1060 mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis()
1061 + mLastModemActivityInfo.getSleepTimeMillis());
1062 mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis()
1063 + mLastModemActivityInfo.getIdleTimeMillis());
1064 mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs);
1065 mLastModemActivityInfo.setReceiveTimeMillis(
1066 info.getReceiveTimeMillis()
1067 + mLastModemActivityInfo.getReceiveTimeMillis());
1068 }
1069 ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(),
1070 mLastModemActivityInfo.getSleepTimeMillis(),
1071 mLastModemActivityInfo.getIdleTimeMillis(),
1072 mLastModemActivityInfo.getTransmitTimeMillis(),
1073 mLastModemActivityInfo.getReceiveTimeMillis());
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001074 } else {
1075 if (ar.result == null) {
1076 loge("queryModemActivityInfo: Empty response");
1077 } else if (ar.exception instanceof CommandException) {
1078 loge("queryModemActivityInfo: CommandException: " +
1079 ar.exception);
1080 } else {
1081 loge("queryModemActivityInfo: Unknown exception");
1082 }
1083 }
Shuo Qian8f4750a2020-02-20 17:12:10 -08001084 Bundle bundle = new Bundle();
1085 bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret);
1086 result.send(0, bundle);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001087 notifyRequester(request);
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07001088 break;
1089
Meng Wang1a7c35a2016-05-05 20:56:15 -07001090 case CMD_SET_ALLOWED_CARRIERS:
1091 request = (MainThreadRequest) msg.obj;
Michele Berionne482f8202018-11-27 18:57:59 -08001092 CarrierRestrictionRules argument =
1093 (CarrierRestrictionRules) request.argument;
Meng Wang1a7c35a2016-05-05 20:56:15 -07001094 onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request);
Michele Berionne482f8202018-11-27 18:57:59 -08001095 defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001096 break;
1097
1098 case EVENT_SET_ALLOWED_CARRIERS_DONE:
1099 ar = (AsyncResult) msg.obj;
1100 request = (MainThreadRequest) ar.userObj;
1101 if (ar.exception == null && ar.result != null) {
1102 request.result = ar.result;
1103 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001104 request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR;
1105 if (ar.exception instanceof CommandException) {
1106 loge("setAllowedCarriers: CommandException: " + ar.exception);
1107 CommandException.Error error =
1108 ((CommandException) (ar.exception)).getCommandError();
1109 if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) {
1110 request.result =
1111 TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED;
1112 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07001113 } else {
1114 loge("setAllowedCarriers: Unknown exception");
1115 }
1116 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001117 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001118 break;
1119
1120 case CMD_GET_ALLOWED_CARRIERS:
1121 request = (MainThreadRequest) msg.obj;
1122 onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001123 defaultPhone.getAllowedCarriers(onCompleted, request.workSource);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001124 break;
1125
1126 case EVENT_GET_ALLOWED_CARRIERS_DONE:
1127 ar = (AsyncResult) msg.obj;
1128 request = (MainThreadRequest) ar.userObj;
1129 if (ar.exception == null && ar.result != null) {
1130 request.result = ar.result;
1131 } else {
Michele Berionne482f8202018-11-27 18:57:59 -08001132 request.result = new IllegalStateException(
1133 "Failed to get carrier restrictions");
Meng Wang1a7c35a2016-05-05 20:56:15 -07001134 if (ar.result == null) {
1135 loge("getAllowedCarriers: Empty response");
1136 } else if (ar.exception instanceof CommandException) {
1137 loge("getAllowedCarriers: CommandException: " +
1138 ar.exception);
1139 } else {
1140 loge("getAllowedCarriers: Unknown exception");
1141 }
1142 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001143 notifyRequester(request);
Meng Wang1a7c35a2016-05-05 20:56:15 -07001144 break;
1145
Nathan Haroldb3014052017-01-25 15:57:32 -08001146 case EVENT_GET_FORBIDDEN_PLMNS_DONE:
1147 ar = (AsyncResult) msg.obj;
1148 request = (MainThreadRequest) ar.userObj;
1149 if (ar.exception == null && ar.result != null) {
1150 request.result = ar.result;
1151 } else {
1152 request.result = new IllegalArgumentException(
1153 "Failed to retrieve Forbidden Plmns");
1154 if (ar.result == null) {
1155 loge("getForbiddenPlmns: Empty response");
1156 } else {
1157 loge("getForbiddenPlmns: Unknown exception");
1158 }
1159 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001160 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001161 break;
1162
1163 case CMD_GET_FORBIDDEN_PLMNS:
1164 request = (MainThreadRequest) msg.obj;
1165 uiccCard = getUiccCardFromRequest(request);
1166 if (uiccCard == null) {
1167 loge("getForbiddenPlmns() UiccCard is null");
1168 request.result = new IllegalArgumentException(
1169 "getForbiddenPlmns() UiccCard is null");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001170 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001171 break;
1172 }
1173 Integer appType = (Integer) request.argument;
1174 UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType);
1175 if (uiccApp == null) {
1176 loge("getForbiddenPlmns() no app with specified type -- "
1177 + appType);
1178 request.result = new IllegalArgumentException("Failed to get UICC App");
Pengquan Menga1bb6272018-09-06 09:59:22 -07001179 notifyRequester(request);
Nathan Haroldb3014052017-01-25 15:57:32 -08001180 break;
1181 } else {
1182 if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid()
1183 + " specified type -- " + appType);
1184 }
1185 onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request);
1186 ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns(
1187 onCompleted);
1188 break;
1189
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001190 case CMD_SWITCH_SLOTS:
1191 request = (MainThreadRequest) msg.obj;
1192 int[] physicalSlots = (int[]) request.argument;
1193 onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request);
1194 UiccController.getInstance().switchSlots(physicalSlots, onCompleted);
1195 break;
1196
1197 case EVENT_SWITCH_SLOTS_DONE:
1198 ar = (AsyncResult) msg.obj;
1199 request = (MainThreadRequest) ar.userObj;
1200 request.result = (ar.exception == null);
Pengquan Menga1bb6272018-09-06 09:59:22 -07001201 notifyRequester(request);
1202 break;
1203 case CMD_GET_NETWORK_SELECTION_MODE:
1204 request = (MainThreadRequest) msg.obj;
1205 onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request);
1206 getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted);
1207 break;
1208
1209 case EVENT_GET_NETWORK_SELECTION_MODE_DONE:
1210 ar = (AsyncResult) msg.obj;
1211 request = (MainThreadRequest) ar.userObj;
1212 if (ar.exception != null) {
1213 request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
1214 } else {
1215 int mode = ((int[]) ar.result)[0];
1216 if (mode == 0) {
1217 request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO;
1218 } else {
1219 request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL;
1220 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001221 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001222 notifyRequester(request);
1223 break;
1224 case CMD_GET_CDMA_ROAMING_MODE:
1225 request = (MainThreadRequest) msg.obj;
1226 onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request);
1227 getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted);
1228 break;
1229 case EVENT_GET_CDMA_ROAMING_MODE_DONE:
1230 ar = (AsyncResult) msg.obj;
1231 request = (MainThreadRequest) ar.userObj;
1232 if (ar.exception != null) {
1233 request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT;
1234 } else {
1235 request.result = ((int[]) ar.result)[0];
1236 }
1237 notifyRequester(request);
1238 break;
1239 case CMD_SET_CDMA_ROAMING_MODE:
1240 request = (MainThreadRequest) msg.obj;
1241 onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request);
1242 int mode = (int) request.argument;
1243 getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted);
1244 break;
1245 case EVENT_SET_CDMA_ROAMING_MODE_DONE:
1246 ar = (AsyncResult) msg.obj;
1247 request = (MainThreadRequest) ar.userObj;
1248 request.result = ar.exception == null;
1249 notifyRequester(request);
1250 break;
1251 case CMD_SET_CDMA_SUBSCRIPTION_MODE:
1252 request = (MainThreadRequest) msg.obj;
1253 onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request);
1254 int subscriptionMode = (int) request.argument;
1255 getPhoneFromRequest(request).setCdmaSubscription(subscriptionMode, onCompleted);
1256 break;
1257 case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE:
1258 ar = (AsyncResult) msg.obj;
1259 request = (MainThreadRequest) ar.userObj;
1260 request.result = ar.exception == null;
1261 notifyRequester(request);
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00001262 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001263 case CMD_GET_ALL_CELL_INFO:
1264 request = (MainThreadRequest) msg.obj;
Nathan Harold3ff88932018-08-14 10:19:49 -07001265 onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request);
Nathan Harold92bed182018-10-12 18:16:49 -07001266 request.phone.requestCellInfoUpdate(request.workSource, onCompleted);
Nathan Harold3ff88932018-08-14 10:19:49 -07001267 break;
Nathan Harold3ff88932018-08-14 10:19:49 -07001268 case EVENT_GET_ALL_CELL_INFO_DONE:
1269 ar = (AsyncResult) msg.obj;
1270 request = (MainThreadRequest) ar.userObj;
Nathan Harold8d0f1742018-10-02 12:14:47 -07001271 // If a timeout occurs, the response will be null
1272 request.result = (ar.exception == null && ar.result != null)
1273 ? ar.result : new ArrayList<CellInfo>();
Nathan Harold3ff88932018-08-14 10:19:49 -07001274 synchronized (request) {
1275 request.notifyAll();
1276 }
1277 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001278 case CMD_REQUEST_CELL_INFO_UPDATE:
1279 request = (MainThreadRequest) msg.obj;
1280 request.phone.requestCellInfoUpdate(request.workSource,
1281 obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request));
1282 break;
1283 case EVENT_REQUEST_CELL_INFO_UPDATE_DONE:
1284 ar = (AsyncResult) msg.obj;
1285 request = (MainThreadRequest) ar.userObj;
1286 ICellInfoCallback cb = (ICellInfoCallback) request.argument;
1287 try {
1288 if (ar.exception != null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001289 Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception);
Meng Wangd8921f42019-09-30 17:13:54 -07001290 cb.onError(
1291 TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR,
1292 ar.exception.getClass().getName(),
1293 ar.exception.toString());
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001294 } else if (ar.result == null) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001295 Log.w(LOG_TAG, "Timeout Waiting for CellInfo!");
Meng Wangd8921f42019-09-30 17:13:54 -07001296 cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001297 } else {
1298 // use the result as returned
1299 cb.onCellInfo((List<CellInfo>) ar.result);
1300 }
1301 } catch (RemoteException re) {
1302 Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException");
1303 }
1304 break;
1305 case CMD_GET_CELL_LOCATION:
Nathan Harold3ff88932018-08-14 10:19:49 -07001306 request = (MainThreadRequest) msg.obj;
1307 WorkSource ws = (WorkSource) request.argument;
1308 Phone phone = getPhoneFromRequest(request);
Meng Wanga10e89e2019-12-09 13:13:01 -08001309 phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request));
Nathan Harold3ff88932018-08-14 10:19:49 -07001310 break;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001311 case EVENT_GET_CELL_LOCATION_DONE:
Nathan Harold3ff88932018-08-14 10:19:49 -07001312 ar = (AsyncResult) msg.obj;
1313 request = (MainThreadRequest) ar.userObj;
1314 if (ar.exception == null) {
1315 request.result = ar.result;
1316 } else {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001317 phone = getPhoneFromRequest(request);
Nathan Harold3ff88932018-08-14 10:19:49 -07001318 request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
Meng Wanga10e89e2019-12-09 13:13:01 -08001319 ? new CellIdentityCdma() : new CellIdentityGsm();
Nathan Harold3ff88932018-08-14 10:19:49 -07001320 }
1321
1322 synchronized (request) {
1323 request.notifyAll();
1324 }
1325 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001326 case CMD_MODEM_REBOOT:
1327 request = (MainThreadRequest) msg.obj;
1328 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001329 defaultPhone.rebootModem(onCompleted);
chen xu6dac5ab2018-10-26 17:39:23 -07001330 break;
chen xu6dac5ab2018-10-26 17:39:23 -07001331 case EVENT_CMD_MODEM_REBOOT_DONE:
1332 handleNullReturnEvent(msg, "rebootModem");
1333 break;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001334 case CMD_REQUEST_ENABLE_MODEM:
1335 request = (MainThreadRequest) msg.obj;
1336 boolean enable = (boolean) request.argument;
1337 onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request);
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001338 onCompleted.arg1 = enable ? 1 : 0;
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001339 PhoneConfigurationManager.getInstance()
1340 .enablePhone(request.phone, enable, onCompleted);
1341 break;
1342 case EVENT_ENABLE_MODEM_DONE:
1343 ar = (AsyncResult) msg.obj;
1344 request = (MainThreadRequest) ar.userObj;
1345 request.result = (ar.exception == null);
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001346 int phoneId = request.phone.getPhoneId();
Nazanin Bakhshi33d584b2019-02-27 10:44:32 -08001347 //update the cache as modem status has changed
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07001348 if ((boolean) request.result) {
1349 mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1);
1350 updateModemStateMetrics();
1351 } else {
1352 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1353 + ar.exception);
1354 }
1355 notifyRequester(request);
1356 break;
1357 case CMD_GET_MODEM_STATUS:
1358 request = (MainThreadRequest) msg.obj;
1359 onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request);
1360 PhoneConfigurationManager.getInstance()
1361 .getPhoneStatusFromModem(request.phone, onCompleted);
1362 break;
1363 case EVENT_GET_MODEM_STATUS_DONE:
1364 ar = (AsyncResult) msg.obj;
1365 request = (MainThreadRequest) ar.userObj;
1366 int id = request.phone.getPhoneId();
1367 if (ar.exception == null && ar.result != null) {
1368 request.result = ar.result;
1369 //update the cache as modem status has changed
1370 mPhoneConfigurationManager.addToPhoneStatusCache(id,
1371 (boolean) request.result);
1372 } else {
1373 // Return true if modem status cannot be retrieved. For most cases,
1374 // modem status is on. And for older version modems, GET_MODEM_STATUS
1375 // and disable modem are not supported. Modem is always on.
1376 // TODO: this should be fixed in R to support a third
1377 // status UNKNOWN b/131631629
1378 request.result = true;
1379 Log.e(LOG_TAG, msg.what + " failure. Not updating modem status."
1380 + ar.exception);
1381 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08001382 notifyRequester(request);
1383 break;
Hall Liu73f5d362020-01-20 13:42:00 -08001384 case CMD_SET_SYSTEM_SELECTION_CHANNELS: {
1385 request = (MainThreadRequest) msg.obj;
1386 onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request);
1387 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1388 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1389 request.phone.setSystemSelectionChannels(args.first, onCompleted);
1390 break;
1391 }
1392 case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: {
1393 ar = (AsyncResult) msg.obj;
1394 request = (MainThreadRequest) ar.userObj;
1395 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args =
1396 (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument;
1397 args.second.accept(ar.exception == null);
1398 notifyRequester(request);
1399 break;
1400 }
yincheng zhao2737e882019-09-06 17:06:54 -07001401 case EVENT_SET_FORBIDDEN_PLMNS_DONE:
1402 ar = (AsyncResult) msg.obj;
1403 request = (MainThreadRequest) ar.userObj;
1404 if (ar.exception == null && ar.result != null) {
1405 request.result = ar.result;
1406 } else {
1407 request.result = -1;
1408 loge("Failed to set Forbidden Plmns");
1409 if (ar.result == null) {
1410 loge("setForbidenPlmns: Empty response");
1411 } else if (ar.exception != null) {
1412 loge("setForbiddenPlmns: Exception: " + ar.exception);
1413 request.result = -1;
1414 } else {
1415 loge("setForbiddenPlmns: Unknown exception");
1416 }
1417 }
1418 notifyRequester(request);
1419 break;
1420 case CMD_SET_FORBIDDEN_PLMNS:
1421 request = (MainThreadRequest) msg.obj;
1422 uiccCard = getUiccCardFromRequest(request);
1423 if (uiccCard == null) {
1424 loge("setForbiddenPlmns: UiccCard is null");
1425 request.result = -1;
1426 notifyRequester(request);
1427 break;
1428 }
1429 Pair<Integer, List<String>> setFplmnsArgs =
1430 (Pair<Integer, List<String>>) request.argument;
1431 appType = setFplmnsArgs.first;
1432 List<String> fplmns = setFplmnsArgs.second;
1433 uiccApp = uiccCard.getApplicationByType(appType);
1434 if (uiccApp == null) {
1435 loge("setForbiddenPlmns: no app with specified type -- " + appType);
1436 request.result = -1;
1437 loge("Failed to get UICC App");
1438 notifyRequester(request);
1439 } else {
1440 onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request);
1441 ((SIMRecords) uiccApp.getIccRecords())
1442 .setForbiddenPlmns(onCompleted, fplmns);
1443 }
yinchengzhao4d163c02019-12-12 15:21:47 -08001444 break;
Naina Nallurid63128d2019-09-17 14:10:30 -07001445 case CMD_ERASE_MODEM_CONFIG:
1446 request = (MainThreadRequest) msg.obj;
1447 onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request);
1448 defaultPhone.eraseModemConfig(onCompleted);
1449 break;
1450 case EVENT_ERASE_MODEM_CONFIG_DONE:
1451 handleNullReturnEvent(msg, "eraseModemConfig");
yincheng zhao2737e882019-09-06 17:06:54 -07001452 break;
zoey chene02881a2019-12-30 16:11:23 +08001453
1454 case CMD_CHANGE_ICC_LOCK_PASSWORD:
1455 request = (MainThreadRequest) msg.obj;
1456 onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request);
1457 Pair<String, String> changed = (Pair<String, String>) request.argument;
1458 getPhoneFromRequest(request).getIccCard().changeIccLockPassword(
1459 changed.first, changed.second, onCompleted);
1460 break;
1461 case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE:
1462 ar = (AsyncResult) msg.obj;
1463 request = (MainThreadRequest) ar.userObj;
1464 if (ar.exception == null) {
1465 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1466 } else {
1467 request.result = msg.arg1;
1468 }
1469 notifyRequester(request);
1470 break;
1471
1472 case CMD_SET_ICC_LOCK_ENABLED:
1473 request = (MainThreadRequest) msg.obj;
1474 onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request);
1475 Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument;
1476 getPhoneFromRequest(request).getIccCard().setIccLockEnabled(
1477 enabled.first, enabled.second, onCompleted);
1478 break;
1479 case EVENT_SET_ICC_LOCK_ENABLED_DONE:
1480 ar = (AsyncResult) msg.obj;
1481 request = (MainThreadRequest) ar.userObj;
1482 if (ar.exception == null) {
1483 request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS;
1484 } else {
1485 request.result = msg.arg1;
1486 }
1487 notifyRequester(request);
1488 break;
1489
Peter Wangdafb9ac2020-01-15 14:13:38 -08001490 case MSG_NOTIFY_USER_ACTIVITY:
1491 removeMessages(MSG_NOTIFY_USER_ACTIVITY);
Peter Wang59571be2020-01-27 12:35:15 +08001492 Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION);
Peter Wangdafb9ac2020-01-15 14:13:38 -08001493 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
1494 getDefaultPhone().getContext().sendBroadcastAsUser(
1495 intent, UserHandle.ALL, permission.USER_ACTIVITY);
1496 break;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001497 default:
1498 Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what);
1499 break;
1500 }
1501 }
Jake Hambye994d462014-02-03 13:10:13 -08001502
Pengquan Menga1bb6272018-09-06 09:59:22 -07001503 private void notifyRequester(MainThreadRequest request) {
1504 synchronized (request) {
1505 request.notifyAll();
1506 }
1507 }
1508
Jake Hambye994d462014-02-03 13:10:13 -08001509 private void handleNullReturnEvent(Message msg, String command) {
1510 AsyncResult ar = (AsyncResult) msg.obj;
1511 MainThreadRequest request = (MainThreadRequest) ar.userObj;
1512 if (ar.exception == null) {
1513 request.result = true;
1514 } else {
1515 request.result = false;
1516 if (ar.exception instanceof CommandException) {
1517 loge(command + ": CommandException: " + ar.exception);
1518 } else {
1519 loge(command + ": Unknown exception");
1520 }
1521 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07001522 notifyRequester(request);
Jake Hambye994d462014-02-03 13:10:13 -08001523 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001524 }
1525
1526 /**
1527 * Posts the specified command to be executed on the main thread,
1528 * waits for the request to complete, and returns the result.
1529 * @see #sendRequestAsync
1530 */
1531 private Object sendRequest(int command, Object argument) {
Nathan Harold92bed182018-10-12 18:16:49 -07001532 return sendRequest(
1533 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001534 }
1535
1536 /**
1537 * Posts the specified command to be executed on the main thread,
1538 * waits for the request to complete, and returns the result.
1539 * @see #sendRequestAsync
1540 */
1541 private Object sendRequest(int command, Object argument, WorkSource workSource) {
1542 return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID,
Nathan Harold92bed182018-10-12 18:16:49 -07001543 null, workSource);
Wink Saville36469e72014-06-11 15:17:00 -07001544 }
1545
1546 /**
1547 * Posts the specified command to be executed on the main thread,
1548 * waits for the request to complete, and returns the result.
1549 * @see #sendRequestAsync
1550 */
Shishir Agrawal76d5da92014-11-09 16:17:25 -08001551 private Object sendRequest(int command, Object argument, Integer subId) {
Nathan Harold92bed182018-10-12 18:16:49 -07001552 return sendRequest(command, argument, subId, null, null);
vagdeviaf9a5b92018-08-15 16:01:53 -07001553 }
1554
1555 /**
1556 * Posts the specified command to be executed on the main thread,
1557 * waits for the request to complete, and returns the result.
1558 * @see #sendRequestAsync
1559 */
Nathan Harold92bed182018-10-12 18:16:49 -07001560 private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) {
1561 return sendRequest(command, argument, subId, null, workSource);
1562 }
1563
1564 /**
1565 * Posts the specified command to be executed on the main thread,
1566 * waits for the request to complete, and returns the result.
1567 * @see #sendRequestAsync
1568 */
1569 private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) {
1570 return sendRequest(
1571 command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource);
1572 }
1573
1574 /**
1575 * Posts the specified command to be executed on the main thread,
1576 * waits for the request to complete, and returns the result.
1577 * @see #sendRequestAsync
1578 */
1579 private Object sendRequest(
1580 int command, Object argument, Integer subId, Phone phone, WorkSource workSource) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001581 if (Looper.myLooper() == mMainThreadHandler.getLooper()) {
1582 throw new RuntimeException("This method will deadlock if called from the main thread.");
1583 }
1584
Nathan Harold92bed182018-10-12 18:16:49 -07001585 MainThreadRequest request = null;
1586 if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) {
1587 throw new IllegalArgumentException("subId and phone cannot both be specified!");
1588 } else if (phone != null) {
1589 request = new MainThreadRequest(argument, phone, workSource);
1590 } else {
1591 request = new MainThreadRequest(argument, subId, workSource);
1592 }
1593
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001594 Message msg = mMainThreadHandler.obtainMessage(command, request);
1595 msg.sendToTarget();
1596
1597 // Wait for the request to complete
1598 synchronized (request) {
1599 while (request.result == null) {
1600 try {
1601 request.wait();
1602 } catch (InterruptedException e) {
1603 // Do nothing, go back and wait until the request is complete
1604 }
1605 }
1606 }
1607 return request.result;
1608 }
1609
1610 /**
1611 * Asynchronous ("fire and forget") version of sendRequest():
1612 * Posts the specified command to be executed on the main thread, and
1613 * returns immediately.
1614 * @see #sendRequest
1615 */
1616 private void sendRequestAsync(int command) {
1617 mMainThreadHandler.sendEmptyMessage(command);
1618 }
1619
1620 /**
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001621 * Same as {@link #sendRequestAsync(int)} except it takes an argument.
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001622 * @see {@link #sendRequest(int)}
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001623 */
1624 private void sendRequestAsync(int command, Object argument) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07001625 sendRequestAsync(command, argument, null, null);
1626 }
1627
1628 /**
1629 * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource.
1630 * @see {@link #sendRequest(int,Object)}
1631 */
1632 private void sendRequestAsync(
1633 int command, Object argument, Phone phone, WorkSource workSource) {
1634 MainThreadRequest request = new MainThreadRequest(argument, phone, workSource);
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07001635 Message msg = mMainThreadHandler.obtainMessage(command, request);
1636 msg.sendToTarget();
1637 }
1638
1639 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001640 * Initialize the singleton PhoneInterfaceManager instance.
1641 * This is only done once, at startup, from PhoneApp.onCreate().
1642 */
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001643 /* package */ static PhoneInterfaceManager init(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001644 synchronized (PhoneInterfaceManager.class) {
1645 if (sInstance == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001646 sInstance = new PhoneInterfaceManager(app);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001647 } else {
1648 Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance);
1649 }
1650 return sInstance;
1651 }
1652 }
1653
1654 /** Private constructor; @see init() */
Jordan Liu1979a042020-03-20 21:39:35 +00001655 private PhoneInterfaceManager(PhoneGlobals app) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001656 mApp = app;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001657 mCM = PhoneGlobals.getInstance().mCM;
Brad Ebinger24c29992019-12-05 13:03:21 -08001658 mImsResolver = PhoneGlobals.getInstance().getImsResolver();
Stuart Scott981d8582015-04-21 14:09:50 -07001659 mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001660 mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE);
1661 mMainThreadHandler = new MainThreadHandler();
Tobias Thiererb19e1f12018-12-11 17:54:03 +00001662 mSubscriptionController = SubscriptionController.getInstance();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001663 mTelephonySharedPreferences =
1664 PreferenceManager.getDefaultSharedPreferences(mApp);
yinxub1bed742017-04-17 11:45:04 -07001665 mNetworkScanRequestTracker = new NetworkScanRequestTracker();
Malcolm Chen2c63d402018-08-14 16:00:53 -07001666 mPhoneConfigurationManager = PhoneConfigurationManager.getInstance();
Peter Wanga3cf4ac2020-01-27 09:39:46 +08001667 mNotifyUserActivity = new AtomicBoolean(false);
Wink Saville3ab207e2014-11-20 13:07:20 -08001668
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001669 publish();
1670 }
1671
Nazanin Bakhshif782e562018-12-11 15:15:39 -08001672 private Phone getDefaultPhone() {
1673 Phone thePhone = getPhone(getDefaultSubscription());
1674 return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone();
1675 }
1676
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001677 private void publish() {
1678 if (DBG) log("publish: " + this);
1679
Peter Wangc035ce42020-01-08 21:00:22 -08001680 TelephonyFrameworkInitializer
1681 .getTelephonyServiceManager()
1682 .getTelephonyServiceRegisterer()
1683 .register(this);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001684 }
1685
Stuart Scott584921c2015-01-15 17:10:34 -08001686 private Phone getPhoneFromRequest(MainThreadRequest request) {
Jordan Liu4c733742019-02-28 12:03:40 -08001687 if (request.phone != null) {
1688 return request.phone;
1689 } else {
1690 return getPhoneFromSubId(request.subId);
1691 }
1692 }
1693
1694 private Phone getPhoneFromSubId(int subId) {
1695 return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID)
1696 ? getDefaultPhone() : getPhone(subId);
Stuart Scott584921c2015-01-15 17:10:34 -08001697 }
1698
Shishir Agrawalc04d9752016-02-19 10:41:00 -08001699 private UiccCard getUiccCardFromRequest(MainThreadRequest request) {
1700 Phone phone = getPhoneFromRequest(request);
1701 return phone == null ? null :
1702 UiccController.getInstance().getUiccCard(phone.getPhoneId());
1703 }
1704
Wink Saville36469e72014-06-11 15:17:00 -07001705 // returns phone associated with the subId.
Wink Savilleb564aae2014-10-23 10:18:09 -07001706 private Phone getPhone(int subId) {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08001707 return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId));
Wink Saville36469e72014-06-11 15:17:00 -07001708 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001709
Naina Nallurid63128d2019-09-17 14:10:30 -07001710 private void sendEraseModemConfig(Phone phone) {
1711 if (phone != null) {
1712 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
1713 mApp, phone.getSubId(), "eraseModemConfig");
1714 final long identity = Binder.clearCallingIdentity();
1715 try {
1716 Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null);
1717 if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail"));
1718 } finally {
1719 Binder.restoreCallingIdentity(identity);
1720 }
1721 }
1722 }
1723
Peter Wang44b186e2020-01-13 23:33:09 -08001724 private boolean isImsAvailableOnDevice() {
1725 PackageManager pm = getDefaultPhone().getContext().getPackageManager();
1726 if (pm == null) {
1727 // For some reason package manger is not available.. This will fail internally anyway,
1728 // so do not throw error and allow.
1729 return true;
1730 }
1731 return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0);
1732 }
1733
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001734 public void dial(String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001735 dialForSubscriber(getPreferredVoiceSubscription(), number);
Wink Saville36469e72014-06-11 15:17:00 -07001736 }
1737
Wink Savilleb564aae2014-10-23 10:18:09 -07001738 public void dialForSubscriber(int subId, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001739 if (DBG) log("dial: " + number);
1740 // No permission check needed here: This is just a wrapper around the
1741 // ACTION_DIAL intent, which is available to any app since it puts up
1742 // the UI before it does anything.
1743
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001744 final long identity = Binder.clearCallingIdentity();
1745 try {
1746 String url = createTelUrl(number);
1747 if (url == null) {
1748 return;
1749 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001750
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001751 // PENDING: should we just silently fail if phone is offhook or ringing?
1752 PhoneConstants.State state = mCM.getState(subId);
1753 if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) {
1754 Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
1755 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1756 mApp.startActivity(intent);
1757 }
1758 } finally {
1759 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001760 }
1761 }
1762
1763 public void call(String callingPackage, String number) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001764 callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number);
Wink Saville36469e72014-06-11 15:17:00 -07001765 }
1766
Wink Savilleb564aae2014-10-23 10:18:09 -07001767 public void callForSubscriber(int subId, String callingPackage, String number) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001768 if (DBG) log("call: " + number);
1769
1770 // This is just a wrapper around the ACTION_CALL intent, but we still
1771 // need to do a permission check since we're calling startActivity()
1772 // from the context of the phone app.
1773 enforceCallPermission();
1774
Jordan Liu1617b712019-07-10 15:06:26 -07001775 if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage)
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001776 != AppOpsManager.MODE_ALLOWED) {
1777 return;
1778 }
1779
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001780 final long identity = Binder.clearCallingIdentity();
1781 try {
1782 String url = createTelUrl(number);
1783 if (url == null) {
1784 return;
1785 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001787 boolean isValid = false;
1788 final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged();
1789 if (slist != null) {
1790 for (SubscriptionInfo subInfoRecord : slist) {
1791 if (subInfoRecord.getSubscriptionId() == subId) {
1792 isValid = true;
1793 break;
1794 }
Wink Saville3ab207e2014-11-20 13:07:20 -08001795 }
Wink Saville08874612014-08-31 19:19:58 -07001796 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001797 if (!isValid) {
1798 return;
1799 }
Wink Saville08874612014-08-31 19:19:58 -07001800
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001801 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url));
1802 intent.putExtra(SUBSCRIPTION_KEY, subId);
1803 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1804 mApp.startActivity(intent);
1805 } finally {
1806 Binder.restoreCallingIdentity(identity);
1807 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001808 }
1809
Wink Savilleb564aae2014-10-23 10:18:09 -07001810 public boolean supplyPinForSubscriber(int subId, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001811 int [] resultArray = supplyPinReportResultForSubscriber(subId, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001812 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1813 }
1814
Wink Savilleb564aae2014-10-23 10:18:09 -07001815 public boolean supplyPukForSubscriber(int subId, String puk, String pin) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001816 int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin);
Wink Saville9de0f752013-10-22 19:04:03 -07001817 return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false;
1818 }
1819
Wink Savilleb564aae2014-10-23 10:18:09 -07001820 public int[] supplyPinReportResultForSubscriber(int subId, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001821 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001822
1823 final long identity = Binder.clearCallingIdentity();
1824 try {
1825 final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard());
1826 checkSimPin.start();
1827 return checkSimPin.unlockSim(null, pin);
1828 } finally {
1829 Binder.restoreCallingIdentity(identity);
1830 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001831 }
1832
Wink Savilleb564aae2014-10-23 10:18:09 -07001833 public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001834 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001835
1836 final long identity = Binder.clearCallingIdentity();
1837 try {
1838 final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard());
1839 checkSimPuk.start();
1840 return checkSimPuk.unlockSim(puk, pin);
1841 } finally {
1842 Binder.restoreCallingIdentity(identity);
1843 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001844 }
1845
1846 /**
Wink Saville9de0f752013-10-22 19:04:03 -07001847 * Helper thread to turn async call to SimCard#supplyPin into
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001848 * a synchronous one.
1849 */
1850 private static class UnlockSim extends Thread {
1851
1852 private final IccCard mSimCard;
1853
1854 private boolean mDone = false;
Wink Saville9de0f752013-10-22 19:04:03 -07001855 private int mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1856 private int mRetryCount = -1;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001857
1858 // For replies from SimCard interface
1859 private Handler mHandler;
1860
1861 // For async handler to identify request type
1862 private static final int SUPPLY_PIN_COMPLETE = 100;
1863
1864 public UnlockSim(IccCard simCard) {
1865 mSimCard = simCard;
1866 }
1867
1868 @Override
1869 public void run() {
1870 Looper.prepare();
1871 synchronized (UnlockSim.this) {
1872 mHandler = new Handler() {
1873 @Override
1874 public void handleMessage(Message msg) {
1875 AsyncResult ar = (AsyncResult) msg.obj;
1876 switch (msg.what) {
1877 case SUPPLY_PIN_COMPLETE:
1878 Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE");
1879 synchronized (UnlockSim.this) {
Wink Saville9de0f752013-10-22 19:04:03 -07001880 mRetryCount = msg.arg1;
1881 if (ar.exception != null) {
1882 if (ar.exception instanceof CommandException &&
1883 ((CommandException)(ar.exception)).getCommandError()
1884 == CommandException.Error.PASSWORD_INCORRECT) {
1885 mResult = PhoneConstants.PIN_PASSWORD_INCORRECT;
vivi.lib5e9ada2019-09-12 16:04:24 +08001886 } //When UiccCardApp dispose,handle message and return exception
1887 else if (ar.exception instanceof CommandException &&
1888 ((CommandException) (ar.exception)).getCommandError()
1889 == CommandException.Error.ABORTED) {
1890 mResult = PhoneConstants.PIN_OPERATION_ABORTED;
Wink Saville9de0f752013-10-22 19:04:03 -07001891 } else {
1892 mResult = PhoneConstants.PIN_GENERAL_FAILURE;
1893 }
1894 } else {
1895 mResult = PhoneConstants.PIN_RESULT_SUCCESS;
1896 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001897 mDone = true;
1898 UnlockSim.this.notifyAll();
1899 }
1900 break;
1901 }
1902 }
1903 };
1904 UnlockSim.this.notifyAll();
1905 }
1906 Looper.loop();
1907 }
1908
1909 /*
1910 * Use PIN or PUK to unlock SIM card
1911 *
1912 * If PUK is null, unlock SIM card with PIN
1913 *
1914 * If PUK is not null, unlock SIM card with PUK and set PIN code
1915 */
Wink Saville9de0f752013-10-22 19:04:03 -07001916 synchronized int[] unlockSim(String puk, String pin) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001917
1918 while (mHandler == null) {
1919 try {
1920 wait();
1921 } catch (InterruptedException e) {
1922 Thread.currentThread().interrupt();
1923 }
1924 }
1925 Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE);
1926
1927 if (puk == null) {
1928 mSimCard.supplyPin(pin, callback);
1929 } else {
1930 mSimCard.supplyPuk(puk, pin, callback);
1931 }
1932
1933 while (!mDone) {
1934 try {
1935 Log.d(LOG_TAG, "wait for done");
1936 wait();
1937 } catch (InterruptedException e) {
1938 // Restore the interrupted status
1939 Thread.currentThread().interrupt();
1940 }
1941 }
1942 Log.d(LOG_TAG, "done");
Wink Saville9de0f752013-10-22 19:04:03 -07001943 int[] resultArray = new int[2];
1944 resultArray[0] = mResult;
1945 resultArray[1] = mRetryCount;
1946 return resultArray;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001947 }
1948 }
1949
1950 public void updateServiceLocation() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07001951 updateServiceLocationForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07001952
1953 }
1954
Wink Savilleb564aae2014-10-23 10:18:09 -07001955 public void updateServiceLocationForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001956 // No permission check needed here: this call is harmless, and it's
1957 // needed for the ServiceState.requestStateUpdate() call (which is
1958 // already intentionally exposed to 3rd parties.)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001959 final long identity = Binder.clearCallingIdentity();
1960 try {
1961 final Phone phone = getPhone(subId);
1962 if (phone != null) {
1963 phone.updateServiceLocation();
1964 }
1965 } finally {
1966 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001967 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001968 }
1969
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001970 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001971 @Override
1972 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001973 return isRadioOnWithFeature(callingPackage, null);
1974 }
1975
1976
1977 @Override
1978 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
1979 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
1980 callingFeatureId);
1981 }
1982
1983 @Deprecated
1984 @Override
1985 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
1986 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07001987 }
1988
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001989 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001990 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
1991 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08001992 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07001993 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07001994 return false;
1995 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996
1997 final long identity = Binder.clearCallingIdentity();
1998 try {
1999 return isRadioOnForSubscriber(subId);
2000 } finally {
2001 Binder.restoreCallingIdentity(identity);
2002 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002003 }
2004
2005 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002006 final long identity = Binder.clearCallingIdentity();
2007 try {
2008 final Phone phone = getPhone(subId);
2009 if (phone != null) {
2010 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2011 } else {
2012 return false;
2013 }
2014 } finally {
2015 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002016 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002017 }
2018
2019 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002020 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002021 }
Wink Saville36469e72014-06-11 15:17:00 -07002022
Wink Savilleb564aae2014-10-23 10:18:09 -07002023 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002024 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002025
2026 final long identity = Binder.clearCallingIdentity();
2027 try {
2028 final Phone phone = getPhone(subId);
2029 if (phone != null) {
2030 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2031 }
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002034 }
Wink Saville36469e72014-06-11 15:17:00 -07002035 }
2036
2037 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002038 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002039 }
2040
Wink Savilleb564aae2014-10-23 10:18:09 -07002041 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002042 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002043
2044 final long identity = Binder.clearCallingIdentity();
2045 try {
2046 final Phone phone = getPhone(subId);
2047 if (phone == null) {
2048 return false;
2049 }
2050 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2051 toggleRadioOnOffForSubscriber(subId);
2052 }
2053 return true;
2054 } finally {
2055 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002056 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002057 }
Wink Saville36469e72014-06-11 15:17:00 -07002058
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002059 public boolean needMobileRadioShutdown() {
Shuo Qianfa7b6b32019-12-10 10:40:38 -08002060 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002061 /*
2062 * If any of the Radios are available, it will need to be
2063 * shutdown. So return true if any Radio is available.
2064 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002065 final long identity = Binder.clearCallingIdentity();
2066 try {
2067 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2068 Phone phone = PhoneFactory.getPhone(i);
2069 if (phone != null && phone.isRadioAvailable()) return true;
2070 }
2071 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2072 return false;
2073 } finally {
2074 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002075 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002076 }
2077
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002078 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002079 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002080 enforceModifyPermission();
2081
2082 final long identity = Binder.clearCallingIdentity();
2083 try {
2084 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2085 logv("Shutting down Phone " + i);
2086 shutdownRadioUsingPhoneId(i);
2087 }
2088 } finally {
2089 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002090 }
2091 }
2092
2093 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002094 Phone phone = PhoneFactory.getPhone(phoneId);
2095 if (phone != null && phone.isRadioAvailable()) {
2096 phone.shutdownRadio();
2097 }
2098 }
2099
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002100 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002101 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002102
2103 final long identity = Binder.clearCallingIdentity();
2104 try {
2105 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2106 if (defaultPhone != null) {
2107 defaultPhone.setRadioPower(turnOn);
2108 return true;
2109 } else {
2110 loge("There's no default phone.");
2111 return false;
2112 }
2113 } finally {
2114 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002115 }
Wink Saville36469e72014-06-11 15:17:00 -07002116 }
2117
Wink Savilleb564aae2014-10-23 10:18:09 -07002118 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002119 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002120
2121 final long identity = Binder.clearCallingIdentity();
2122 try {
2123 final Phone phone = getPhone(subId);
2124 if (phone != null) {
2125 phone.setRadioPower(turnOn);
2126 return true;
2127 } else {
2128 return false;
2129 }
2130 } finally {
2131 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002132 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002133 }
2134
Wink Saville36469e72014-06-11 15:17:00 -07002135 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002136 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002137 public boolean enableDataConnectivity() {
2138 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002139
2140 final long identity = Binder.clearCallingIdentity();
2141 try {
2142 int subId = mSubscriptionController.getDefaultDataSubId();
2143 final Phone phone = getPhone(subId);
2144 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002145 phone.getDataEnabledSettings().setDataEnabled(
2146 TelephonyManager.DATA_ENABLED_REASON_USER, true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002147 return true;
2148 } else {
2149 return false;
2150 }
2151 } finally {
2152 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002153 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002154 }
2155
Wink Saville36469e72014-06-11 15:17:00 -07002156 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002157 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002158 public boolean disableDataConnectivity() {
2159 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002160
2161 final long identity = Binder.clearCallingIdentity();
2162 try {
2163 int subId = mSubscriptionController.getDefaultDataSubId();
2164 final Phone phone = getPhone(subId);
2165 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00002166 phone.getDataEnabledSettings().setDataEnabled(
2167 TelephonyManager.DATA_ENABLED_REASON_USER, false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002168 return true;
2169 } else {
2170 return false;
2171 }
2172 } finally {
2173 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002174 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002175 }
2176
Sanket Padawe356d7632015-06-22 14:03:32 -07002177 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002178 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002179 final long identity = Binder.clearCallingIdentity();
2180 try {
2181 final Phone phone = getPhone(subId);
2182 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002183 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002184 } else {
2185 return false;
2186 }
2187 } finally {
2188 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002189 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002190 }
2191
2192 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002193 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002194 }
2195
pkanwarae03a6b2016-11-06 20:37:09 -08002196 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002197 enforceCallPermission();
2198
2199 final long identity = Binder.clearCallingIdentity();
2200 try {
2201 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2202 return;
2203 }
2204 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2205 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2206 } finally {
2207 Binder.restoreCallingIdentity(identity);
2208 }
pkanwar32d516d2016-10-14 19:37:38 -07002209 };
2210
Wink Savilleb564aae2014-10-23 10:18:09 -07002211 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002212 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002213
2214 final long identity = Binder.clearCallingIdentity();
2215 try {
2216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2217 return false;
2218 }
2219 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2220 } finally {
2221 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002222 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002223 }
2224
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002225 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002226 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002227 }
2228
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002229 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002230 final long identity = Binder.clearCallingIdentity();
2231 try {
2232 Phone phone = PhoneFactory.getPhone(slotIndex);
2233 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2234 PhoneConstantConversions.convertCallState(phone.getState());
2235 } finally {
2236 Binder.restoreCallingIdentity(identity);
2237 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002238 }
2239
Sanket Padawe356d7632015-06-22 14:03:32 -07002240 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002241 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002242 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2243 }
2244
2245 @Override
2246 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002247 final long identity = Binder.clearCallingIdentity();
2248 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002249 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002250 if (phone != null) {
2251 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2252 } else {
2253 return PhoneConstantConversions.convertDataState(
2254 PhoneConstants.DataState.DISCONNECTED);
2255 }
2256 } finally {
2257 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002258 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002259 }
2260
Sanket Padawe356d7632015-06-22 14:03:32 -07002261 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002262 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002263 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2264 }
2265
2266 @Override
2267 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002268 final long identity = Binder.clearCallingIdentity();
2269 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002270 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002271 if (phone != null) {
2272 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2273 } else {
2274 return TelephonyManager.DATA_ACTIVITY_NONE;
2275 }
2276 } finally {
2277 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002278 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002279 }
2280
2281 @Override
Meng Wanga10e89e2019-12-09 13:13:01 -08002282 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002283 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002284 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002285
2286 LocationAccessPolicy.LocationPermissionResult locationResult =
2287 LocationAccessPolicy.checkLocationPermission(mApp,
2288 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2289 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002290 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002291 .setCallingPid(Binder.getCallingPid())
2292 .setCallingUid(Binder.getCallingUid())
2293 .setMethod("getCellLocation")
Hall Liu773ba022020-01-24 18:07:12 -08002294 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002295 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2296 .build());
2297 switch (locationResult) {
2298 case DENIED_HARD:
2299 throw new SecurityException("Not allowed to access cell location");
2300 case DENIED_SOFT:
Meng Wanga10e89e2019-12-09 13:13:01 -08002301 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2302 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002303 }
2304
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002305 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002306 final long identity = Binder.clearCallingIdentity();
2307 try {
2308 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002309 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wanga10e89e2019-12-09 13:13:01 -08002310 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002311 } finally {
2312 Binder.restoreCallingIdentity(identity);
2313 }
Svetoslav64fad262015-04-14 14:35:21 -07002314 }
2315
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002316 @Override
Jack Yueb1e7fe2020-02-22 19:38:58 -08002317 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002318 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2319 // registered cell info, so return a NULL country instead.
2320 final long identity = Binder.clearCallingIdentity();
2321 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002322 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2323 // Get default phone in this case.
2324 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2325 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002326 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002327 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Harold532f51c2020-04-21 19:31:10 -07002328 if (phone == null) return "";
2329 ServiceStateTracker sst = phone.getServiceStateTracker();
2330 if (sst == null) return "";
2331 LocaleTracker lt = sst.getLocaleTracker();
2332 if (lt == null) return "";
2333 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2334 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2335 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002336 } finally {
2337 Binder.restoreCallingIdentity(identity);
2338 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002339 }
2340
2341 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002342 public void enableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002343 enableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002344 }
2345
Sanket Padawe356d7632015-06-22 14:03:32 -07002346 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002347 public void enableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002348 mApp.enforceCallingOrSelfPermission(
2349 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002350
2351 final long identity = Binder.clearCallingIdentity();
2352 try {
2353 final Phone phone = getPhone(subId);
2354 if (phone != null) {
2355 phone.enableLocationUpdates();
2356 }
2357 } finally {
2358 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002359 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002360 }
2361
2362 @Override
2363 public void disableLocationUpdates() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002364 disableLocationUpdatesForSubscriber(getDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002365 }
2366
Sanket Padawe356d7632015-06-22 14:03:32 -07002367 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002368 public void disableLocationUpdatesForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002369 mApp.enforceCallingOrSelfPermission(
2370 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002371
2372 final long identity = Binder.clearCallingIdentity();
2373 try {
2374 final Phone phone = getPhone(subId);
2375 if (phone != null) {
2376 phone.disableLocationUpdates();
2377 }
2378 } finally {
2379 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002380 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002381 }
2382
Nathan Harold31d7ff32018-10-15 20:20:30 -07002383 /**
2384 * Returns the target SDK version number for a given package name.
2385 *
Nathan Haroldec184742019-07-10 17:04:16 -07002386 * This call MUST be invoked before clearing the calling UID.
2387 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002388 * @return target SDK if the package is found or INT_MAX.
2389 */
2390 private int getTargetSdk(String packageName) {
2391 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002392 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu0150f0e2019-07-30 15:12:06 -07002393 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002394 if (ai != null) return ai.targetSdkVersion;
2395 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002396 loge("Failed to get package info for pkg="
2397 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002398 }
2399 return Integer.MAX_VALUE;
2400 }
2401
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002402 @Override
2403 @SuppressWarnings("unchecked")
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002404 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2405 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002406 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002407 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2408 throw new SecurityException(
2409 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2410 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002411
Jordan Liu1617b712019-07-10 15:06:26 -07002412 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002413 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2414 return null;
2415 }
Svetoslav64fad262015-04-14 14:35:21 -07002416
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002417 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002418
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002419 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002420 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002421
Nathan Haroldf180aac2018-06-01 18:43:55 -07002422 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2423 for (CellInfo ci : info) {
2424 if (ci instanceof CellInfoGsm) {
2425 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2426 } else if (ci instanceof CellInfoWcdma) {
2427 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2428 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002429 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002430 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002431 }
2432
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002433 private List<CellInfo> getCachedCellInfo() {
2434 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2435 for (Phone phone : PhoneFactory.getPhones()) {
2436 List<CellInfo> info = phone.getAllCellInfo();
2437 if (info != null) cellInfos.addAll(info);
2438 }
2439 return cellInfos;
2440 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002441
2442 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002443 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002444 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002445 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002446
2447 LocationAccessPolicy.LocationPermissionResult locationResult =
2448 LocationAccessPolicy.checkLocationPermission(mApp,
2449 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2450 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002451 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002452 .setCallingPid(Binder.getCallingPid())
2453 .setCallingUid(Binder.getCallingUid())
2454 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002455 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002456 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2457 .build());
2458 switch (locationResult) {
2459 case DENIED_HARD:
2460 throw new SecurityException("Not allowed to access cell info");
2461 case DENIED_SOFT:
2462 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002463 }
2464
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002465 final int targetSdk = getTargetSdk(callingPackage);
2466 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2467 return getCachedCellInfo();
2468 }
2469
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002470 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002471 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002472 final long identity = Binder.clearCallingIdentity();
2473 try {
2474 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2475 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002476 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002477 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002478 if (info != null) cellInfos.addAll(info);
2479 }
2480 return cellInfos;
2481 } finally {
2482 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002483 }
2484 }
2485
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002486 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002487 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2488 String callingFeatureId) {
2489 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2490 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002491 }
2492
2493 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002494 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2495 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002496 enforceModifyPermission();
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002497 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002498 }
2499
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002500 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2501 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002502 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002503 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002504
2505 LocationAccessPolicy.LocationPermissionResult locationResult =
2506 LocationAccessPolicy.checkLocationPermission(mApp,
2507 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2508 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07002509 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002510 .setCallingPid(Binder.getCallingPid())
2511 .setCallingUid(Binder.getCallingUid())
2512 .setMethod("requestCellInfoUpdate")
Hall Liud60acc92020-05-21 17:09:35 -07002513 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2514 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002515 .build());
2516 switch (locationResult) {
2517 case DENIED_HARD:
Hall Liud60acc92020-05-21 17:09:35 -07002518 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2519 // Safetynet logging for b/154934934
2520 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2521 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002522 throw new SecurityException("Not allowed to access cell info");
2523 case DENIED_SOFT:
Hall Liud60acc92020-05-21 17:09:35 -07002524 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2525 // Safetynet logging for b/154934934
2526 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2527 }
Nathan Harold5320c422019-05-09 10:26:08 -07002528 try {
2529 cb.onCellInfo(new ArrayList<CellInfo>());
2530 } catch (RemoteException re) {
2531 // Drop without consequences
2532 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002533 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002534 }
2535
Nathan Harolda939a962019-05-09 10:13:47 -07002536
2537 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002538 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2539
2540 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2541 }
2542
2543 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002544 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002545 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002546 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002547
2548 final long identity = Binder.clearCallingIdentity();
2549 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002550 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002551 } finally {
2552 Binder.restoreCallingIdentity(identity);
2553 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002554 }
2555
Shishir Agrawala9f32182016-04-12 12:00:16 -07002556 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002557 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002558 Phone phone = PhoneFactory.getPhone(slotIndex);
2559 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002560 return null;
2561 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002562 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002563 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002564 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002565 return null;
2566 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002567
2568 final long identity = Binder.clearCallingIdentity();
2569 try {
2570 return phone.getImei();
2571 } finally {
2572 Binder.restoreCallingIdentity(identity);
2573 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002574 }
2575
2576 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002577 public String getTypeAllocationCodeForSlot(int slotIndex) {
2578 Phone phone = PhoneFactory.getPhone(slotIndex);
2579 String tac = null;
2580 if (phone != null) {
2581 String imei = phone.getImei();
2582 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2583 }
2584 return tac;
2585 }
2586
2587 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002588 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002589 Phone phone = PhoneFactory.getPhone(slotIndex);
2590 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002591 return null;
2592 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002593
Jeff Davidson913390f2018-02-23 17:11:49 -08002594 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002595 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002596 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002597 return null;
2598 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002599
2600 final long identity = Binder.clearCallingIdentity();
2601 try {
2602 return phone.getMeid();
2603 } finally {
2604 Binder.restoreCallingIdentity(identity);
2605 }
Jack Yu2af8d712017-03-15 17:14:14 -07002606 }
2607
2608 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002609 public String getManufacturerCodeForSlot(int slotIndex) {
2610 Phone phone = PhoneFactory.getPhone(slotIndex);
2611 String manufacturerCode = null;
2612 if (phone != null) {
2613 String meid = phone.getMeid();
2614 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2615 }
2616 return manufacturerCode;
2617 }
2618
2619 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002620 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2621 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002622 Phone phone = PhoneFactory.getPhone(slotIndex);
2623 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002624 return null;
2625 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002626 int subId = phone.getSubId();
2627 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002628 mApp, subId, callingPackage, callingFeatureId,
2629 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002630 return null;
2631 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002632
2633 final long identity = Binder.clearCallingIdentity();
2634 try {
2635 return phone.getDeviceSvn();
2636 } finally {
2637 Binder.restoreCallingIdentity(identity);
2638 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002639 }
2640
fionaxu43304da2017-11-27 22:51:16 -08002641 @Override
2642 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002643 final long identity = Binder.clearCallingIdentity();
2644 try {
2645 final Phone phone = getPhone(subId);
2646 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2647 } finally {
2648 Binder.restoreCallingIdentity(identity);
2649 }
fionaxu43304da2017-11-27 22:51:16 -08002650 }
2651
2652 @Override
2653 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002654 final long identity = Binder.clearCallingIdentity();
2655 try {
2656 final Phone phone = getPhone(subId);
2657 return phone == null ? null : phone.getCarrierName();
2658 } finally {
2659 Binder.restoreCallingIdentity(identity);
2660 }
fionaxu43304da2017-11-27 22:51:16 -08002661 }
2662
calvinpanffe225e2018-11-01 19:43:06 +08002663 @Override
chen xu0026ca62019-03-06 15:28:50 -08002664 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002665 final long identity = Binder.clearCallingIdentity();
2666 try {
2667 final Phone phone = getPhone(subId);
2668 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002669 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002670 } finally {
2671 Binder.restoreCallingIdentity(identity);
2672 }
2673 }
2674
2675 @Override
chen xu0026ca62019-03-06 15:28:50 -08002676 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002677 final long identity = Binder.clearCallingIdentity();
2678 try {
2679 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002680 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002681 } finally {
2682 Binder.restoreCallingIdentity(identity);
2683 }
2684 }
2685
chen xu651eec72018-11-11 19:03:44 -08002686 @Override
chen xu864e11c2018-12-06 22:10:03 -08002687 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2688 if (!isSubscriptionMccMnc) {
2689 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2690 }
chen xu651eec72018-11-11 19:03:44 -08002691 final Phone phone = PhoneFactory.getPhone(slotIndex);
2692 if (phone == null) {
2693 return TelephonyManager.UNKNOWN_CARRIER_ID;
2694 }
2695 final long identity = Binder.clearCallingIdentity();
2696 try {
2697 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2698 } finally {
2699 Binder.restoreCallingIdentity(identity);
2700 }
2701 }
2702
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002703 //
2704 // Internal helper methods.
2705 //
2706
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002707 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002708 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2709 *
2710 * @throws SecurityException if the caller does not have the required permission
2711 */
2712 private void enforceModifyPermission() {
2713 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2714 }
2715
Shuo Qiancd19c462020-01-16 20:51:11 -08002716 /**
2717 * Make sure the caller is system.
2718 *
2719 * @throws SecurityException if the caller is not system.
2720 */
2721 private void enforceSystemCaller() {
2722 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2723 throw new SecurityException("Caller must be system");
2724 }
2725 }
2726
Shuo Qian3b6ee772019-11-13 17:43:31 -08002727 private void enforceActiveEmergencySessionPermission() {
2728 mApp.enforceCallingOrSelfPermission(
2729 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2730 }
2731
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002732 /**
2733 * Make sure the caller has the CALL_PHONE permission.
2734 *
2735 * @throws SecurityException if the caller does not have the required permission
2736 */
2737 private void enforceCallPermission() {
2738 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2739 }
2740
paulhu5a773602019-08-23 19:17:33 +08002741 private void enforceSettingsPermission() {
2742 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002743 }
2744
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002745 private String createTelUrl(String number) {
2746 if (TextUtils.isEmpty(number)) {
2747 return null;
2748 }
2749
Jake Hambye994d462014-02-03 13:10:13 -08002750 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002751 }
2752
Ihab Awadf9e92732013-12-05 18:02:52 -08002753 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002754 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2755 }
2756
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002757 private static void logv(String msg) {
2758 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2759 }
2760
Ihab Awadf9e92732013-12-05 18:02:52 -08002761 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002762 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2763 }
2764
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002765 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002766 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002767 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002768 }
2769
Sanket Padawe356d7632015-06-22 14:03:32 -07002770 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002771 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002772 final long identity = Binder.clearCallingIdentity();
2773 try {
2774 final Phone phone = PhoneFactory.getPhone(slotIndex);
2775 if (phone == null) {
2776 return PhoneConstants.PHONE_TYPE_NONE;
2777 } else {
2778 return phone.getPhoneType();
2779 }
2780 } finally {
2781 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002782 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002783 }
2784
2785 /**
2786 * Returns the CDMA ERI icon index to display
2787 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002788 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002789 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2790 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2791 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002792 }
2793
Sanket Padawe356d7632015-06-22 14:03:32 -07002794 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002795 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2796 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002797 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002798 mApp, subId, callingPackage, callingFeatureId,
2799 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002800 return -1;
2801 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002802
2803 final long identity = Binder.clearCallingIdentity();
2804 try {
2805 final Phone phone = getPhone(subId);
2806 if (phone != null) {
2807 return phone.getCdmaEriIconIndex();
2808 } else {
2809 return -1;
2810 }
2811 } finally {
2812 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002813 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002814 }
2815
2816 /**
2817 * Returns the CDMA ERI icon mode,
2818 * 0 - ON
2819 * 1 - FLASHING
2820 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002821 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002822 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2823 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2824 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002825 }
2826
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002828 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2829 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002830 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002831 mApp, subId, callingPackage, callingFeatureId,
2832 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002833 return -1;
2834 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002835
2836 final long identity = Binder.clearCallingIdentity();
2837 try {
2838 final Phone phone = getPhone(subId);
2839 if (phone != null) {
2840 return phone.getCdmaEriIconMode();
2841 } else {
2842 return -1;
2843 }
2844 } finally {
2845 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002846 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002847 }
2848
2849 /**
2850 * Returns the CDMA ERI text,
2851 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002852 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002853 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2854 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2855 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002856 }
2857
Sanket Padawe356d7632015-06-22 14:03:32 -07002858 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002859 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2860 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002861 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002862 mApp, subId, callingPackage, callingFeatureId,
2863 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002864 return null;
2865 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002866
2867 final long identity = Binder.clearCallingIdentity();
2868 try {
2869 final Phone phone = getPhone(subId);
2870 if (phone != null) {
2871 return phone.getCdmaEriText();
2872 } else {
2873 return null;
2874 }
2875 } finally {
2876 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002877 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002878 }
2879
2880 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002881 * Returns the CDMA MDN.
2882 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002883 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002884 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002885 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2886 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002887
2888 final long identity = Binder.clearCallingIdentity();
2889 try {
2890 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002891 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002892 return phone.getLine1Number();
2893 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002894 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002895 return null;
2896 }
2897 } finally {
2898 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002899 }
2900 }
2901
2902 /**
2903 * Returns the CDMA MIN.
2904 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002905 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002906 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002907 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2908 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909
2910 final long identity = Binder.clearCallingIdentity();
2911 try {
2912 final Phone phone = getPhone(subId);
2913 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2914 return phone.getCdmaMin();
2915 } else {
2916 return null;
2917 }
2918 } finally {
2919 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002920 }
2921 }
2922
Hall Liud892bec2018-11-30 14:51:45 -08002923 @Override
2924 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2925 INumberVerificationCallback callback, String callingPackage) {
2926 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2927 != PERMISSION_GRANTED) {
2928 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2929 }
2930 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2931
2932 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2933 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2934 throw new SecurityException("Calling package must be configured in the device config");
2935 }
2936
2937 if (range == null) {
2938 throw new NullPointerException("Range must be non-null");
2939 }
2940
2941 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002942 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002943
2944 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2945 }
2946
Junda Liuca05d5d2014-08-14 22:36:34 -07002947 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002948 * Returns true if CDMA provisioning needs to run.
2949 */
2950 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002951 final long identity = Binder.clearCallingIdentity();
2952 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002953 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002954 } finally {
2955 Binder.restoreCallingIdentity(identity);
2956 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002957 }
2958
2959 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002960 * Sets the voice mail number of a given subId.
2961 */
2962 @Override
2963 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08002964 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2965 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002966
2967 final long identity = Binder.clearCallingIdentity();
2968 try {
2969 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2970 new Pair<String, String>(alphaTag, number), new Integer(subId));
2971 return success;
2972 } finally {
2973 Binder.restoreCallingIdentity(identity);
2974 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002975 }
2976
Ta-wei Yen87c49842016-05-13 21:19:52 -07002977 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002978 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2979 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07002980 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2981 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002982 if (!TextUtils.equals(callingPackage, systemDialer)) {
2983 throw new SecurityException("caller must be system dialer");
2984 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002985
2986 final long identity = Binder.clearCallingIdentity();
2987 try {
2988 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
2989 if (phoneAccountHandle == null) {
2990 return null;
2991 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002992 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002993 } finally {
2994 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002995 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002996 }
2997
2998 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002999 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3000 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003001 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003003 mApp, subId, callingPackage, callingFeatureId,
3004 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003005 return null;
3006 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003008 final long identity = Binder.clearCallingIdentity();
3009 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003010 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003011 } finally {
3012 Binder.restoreCallingIdentity(identity);
3013 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003014 }
3015
3016 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003017 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3018 VisualVoicemailSmsFilterSettings settings) {
3019 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003020
3021 final long identity = Binder.clearCallingIdentity();
3022 try {
3023 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003028 }
3029
3030 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003031 public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) {
3032 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003033
3034 final long identity = Binder.clearCallingIdentity();
3035 try {
3036 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003037 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003038 } finally {
3039 Binder.restoreCallingIdentity(identity);
3040 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003041 }
3042
3043 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003044 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3045 String callingPackage, int subId) {
3046 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003047
3048 final long identity = Binder.clearCallingIdentity();
3049 try {
3050 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003051 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003052 } finally {
3053 Binder.restoreCallingIdentity(identity);
3054 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003055 }
3056
3057 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003058 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003059 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003060
3061 final long identity = Binder.clearCallingIdentity();
3062 try {
3063 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003064 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003065 } finally {
3066 Binder.restoreCallingIdentity(identity);
3067 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003068 }
3069
3070 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003071 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3072 String callingAttributionTag, int subId, String number, int port, String text,
3073 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003074 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003075 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003076 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003077 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003078 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3079 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003080 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003081
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003082 /**
fionaxu0152e512016-11-14 13:36:14 -08003083 * Sets the voice activation state of a given subId.
3084 */
3085 @Override
3086 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003087 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3088 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003089
3090 final long identity = Binder.clearCallingIdentity();
3091 try {
3092 final Phone phone = getPhone(subId);
3093 if (phone != null) {
3094 phone.setVoiceActivationState(activationState);
3095 } else {
3096 loge("setVoiceActivationState fails with invalid subId: " + subId);
3097 }
3098 } finally {
3099 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003100 }
3101 }
3102
3103 /**
3104 * Sets the data activation state of a given subId.
3105 */
3106 @Override
3107 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003108 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3109 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003110
3111 final long identity = Binder.clearCallingIdentity();
3112 try {
3113 final Phone phone = getPhone(subId);
3114 if (phone != null) {
3115 phone.setDataActivationState(activationState);
3116 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003117 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003118 }
3119 } finally {
3120 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003121 }
3122 }
3123
3124 /**
3125 * Returns the voice activation state of a given subId.
3126 */
3127 @Override
3128 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003129 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003130
fionaxu0152e512016-11-14 13:36:14 -08003131 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 final long identity = Binder.clearCallingIdentity();
3133 try {
3134 if (phone != null) {
3135 return phone.getVoiceActivationState();
3136 } else {
3137 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3138 }
3139 } finally {
3140 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003141 }
3142 }
3143
3144 /**
3145 * Returns the data activation state of a given subId.
3146 */
3147 @Override
3148 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003149 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003150
fionaxu0152e512016-11-14 13:36:14 -08003151 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003152 final long identity = Binder.clearCallingIdentity();
3153 try {
3154 if (phone != null) {
3155 return phone.getDataActivationState();
3156 } else {
3157 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3158 }
3159 } finally {
3160 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003161 }
3162 }
3163
3164 /**
Wink Saville36469e72014-06-11 15:17:00 -07003165 * Returns the unread count of voicemails for a subId
3166 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003167 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003168 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3169 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003170 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07003171 mApp, subId, callingPackage, callingFeatureId,
3172 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003173 return 0;
3174 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003175 final long identity = Binder.clearCallingIdentity();
3176 try {
3177 final Phone phone = getPhone(subId);
3178 if (phone != null) {
3179 return phone.getVoiceMessageCount();
3180 } else {
3181 return 0;
3182 }
3183 } finally {
3184 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003185 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003186 }
3187
3188 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003189 * returns true, if the device is in a state where both voice and data
3190 * are supported simultaneously. This can change based on location or network condition.
3191 */
3192 @Override
3193 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003194 final long identity = Binder.clearCallingIdentity();
3195 try {
3196 final Phone phone = getPhone(subId);
3197 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3198 } finally {
3199 Binder.restoreCallingIdentity(identity);
3200 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003201 }
3202
3203 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003204 * Send the dialer code if called from the current default dialer or the caller has
3205 * carrier privilege.
3206 * @param inputCode The dialer code to send
3207 */
3208 @Override
3209 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003210 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003211 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07003212 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3213 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003214 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08003215 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003216 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003217 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003218
3219 final long identity = Binder.clearCallingIdentity();
3220 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003221 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003222 } finally {
3223 Binder.restoreCallingIdentity(identity);
3224 }
fionaxu235cc5e2017-03-06 22:25:57 -08003225 }
3226
Pengquan Menga1bb6272018-09-06 09:59:22 -07003227 @Override
3228 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003229 TelephonyPermissions
3230 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3231 mApp, subId, "getNetworkSelectionMode");
3232 final long identity = Binder.clearCallingIdentity();
3233 try {
3234 if (!isActiveSubscription(subId)) {
3235 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3236 }
3237 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3238 } finally {
3239 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003240 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003241 }
3242
Brad Ebinger35c841c2018-10-01 10:40:55 -07003243 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003244 public boolean isInEmergencySmsMode() {
3245 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 for (Phone phone : PhoneFactory.getPhones()) {
3249 if (phone.isInEmergencySmsMode()) {
3250 return true;
3251 }
3252 }
3253 } finally {
3254 Binder.restoreCallingIdentity(identity);
3255 }
3256 return false;
3257 }
3258
shilu366312e2019-12-17 09:28:10 -08003259 /**
3260 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3261 * @param subId The subscription to use to check the configuration.
3262 * @param c The callback that will be used to send the result.
3263 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003264 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003265 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3266 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003267 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3268 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003269
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003270 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3271 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3272 "IMS not available on device.");
3273 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003274 final long token = Binder.clearCallingIdentity();
3275 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003276 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003277 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003278 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003279 } catch (ImsException e) {
3280 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003281 } finally {
3282 Binder.restoreCallingIdentity(token);
3283 }
3284 }
3285
shilu366312e2019-12-17 09:28:10 -08003286 /**
3287 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3288 * @param subId The subscription to use to check the configuration.
3289 * @param c The callback that will be used to send the result.
3290 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003291 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003292 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003293 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3294 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003295 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3296 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3297 }
Meng Wangafbc5852019-09-19 17:37:13 -07003298 final long token = Binder.clearCallingIdentity();
3299 try {
3300 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3301 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3302 .removeRegistrationCallbackForSubscription(c, subId);
3303 } catch (ImsException e) {
3304 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3305 + "is inactive, ignoring unregister.");
3306 // If the subscription is no longer active, just return, since the callback
3307 // will already have been removed internally.
3308 } finally {
3309 Binder.restoreCallingIdentity(token);
3310 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003311 }
3312
Brad Ebingera34a6c22019-10-22 17:36:18 -07003313 /**
3314 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3315 */
3316 @Override
3317 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3318 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3319 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3320 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3321 "IMS not available on device.");
3322 }
3323 final long token = Binder.clearCallingIdentity();
3324 try {
3325 Phone phone = getPhone(subId);
3326 if (phone == null) {
3327 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3328 + subId + "'");
3329 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3330 }
3331 phone.getImsRegistrationState(regState -> {
3332 try {
3333 consumer.accept((regState == null)
3334 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3335 } catch (RemoteException e) {
3336 // Ignore if the remote process is no longer available to call back.
3337 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3338 }
3339 });
3340 } finally {
3341 Binder.restoreCallingIdentity(token);
3342 }
3343 }
3344
3345 /**
3346 * Get the transport type for the IMS service registration state.
3347 */
3348 @Override
3349 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003350 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3351 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebingera34a6c22019-10-22 17:36:18 -07003352 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3353 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3354 "IMS not available on device.");
3355 }
3356 final long token = Binder.clearCallingIdentity();
3357 try {
3358 Phone phone = getPhone(subId);
3359 if (phone == null) {
3360 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3361 + subId + "'");
3362 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3363 }
3364 phone.getImsRegistrationTech(regTech -> {
3365 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3366 int regTechConverted = (regTech == null)
3367 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3368 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3369 regTechConverted);
3370 try {
3371 consumer.accept(regTechConverted);
3372 } catch (RemoteException e) {
3373 // Ignore if the remote process is no longer available to call back.
3374 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3375 }
3376 });
3377 } finally {
3378 Binder.restoreCallingIdentity(token);
3379 }
3380 }
3381
shilu366312e2019-12-17 09:28:10 -08003382 /**
3383 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3384 * @param subId The subscription to use to check the configuration.
3385 * @param c The callback that will be used to send the result.
3386 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003387 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003388 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3389 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003390 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3391 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003392 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3393 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3394 "IMS not available on device.");
3395 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003396 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3397 final long token = Binder.clearCallingIdentity();
3398 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003399 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003400 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003401 } catch (ImsException e) {
3402 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003403 } finally {
3404 Binder.restoreCallingIdentity(token);
3405 }
3406 }
3407
shilu366312e2019-12-17 09:28:10 -08003408 /**
3409 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3410 * @param subId The subscription to use to check the configuration.
3411 * @param c The callback that will be used to send the result.
3412 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003413 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003414 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003415 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3416 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003417 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3418 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3419 }
Meng Wangafbc5852019-09-19 17:37:13 -07003420
3421 final long token = Binder.clearCallingIdentity();
3422 try {
3423 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3424 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003425 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangafbc5852019-09-19 17:37:13 -07003426 } catch (ImsException e) {
3427 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3428 + "is inactive, ignoring unregister.");
3429 // If the subscription is no longer active, just return, since the callback
3430 // will already have been removed internally.
3431 } finally {
3432 Binder.restoreCallingIdentity(token);
3433 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003434 }
3435
3436 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003437 public boolean isCapable(int subId, int capability, int regTech) {
3438 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003439 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3440 final long token = Binder.clearCallingIdentity();
3441 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003442 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003443 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003444 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003445 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3446 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003447 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003448 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3449 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003450 } finally {
3451 Binder.restoreCallingIdentity(token);
3452 }
3453 }
3454
3455 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003456 public boolean isAvailable(int subId, int capability, int regTech) {
3457 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003458 final long token = Binder.clearCallingIdentity();
3459 try {
3460 Phone phone = getPhone(subId);
3461 if (phone == null) return false;
3462 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright5e40e4e2020-03-11 16:35:39 -07003463 } catch (com.android.ims.ImsException e) {
3464 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3465 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003466 } finally {
3467 Binder.restoreCallingIdentity(token);
3468 }
3469 }
3470
Brad Ebingerbc7dd582019-10-17 17:03:22 -07003471 /**
3472 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3473 * subscription.
3474 * @param subId The subscription to use to check the configuration.
3475 * @param callback The callback that will be used to send the result.
3476 * @param capability The MmTelFeature capability that will be used to send the result.
3477 * @param transportType The transport type of the MmTelFeature capability.
3478 */
3479 @Override
3480 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3481 int transportType) {
3482 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3483 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3484 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3485 "IMS not available on device.");
3486 }
3487 final long token = Binder.clearCallingIdentity();
3488 try {
3489 int slotId = getSlotIndex(subId);
3490 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3491 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3492 + subId + "'");
3493 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3494 }
3495 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3496 transportType, aBoolean -> {
3497 try {
3498 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3499 } catch (RemoteException e) {
3500 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3501 + "running. Ignore");
3502 }
3503 });
3504 } finally {
3505 Binder.restoreCallingIdentity(token);
3506 }
3507 }
3508
shilu366312e2019-12-17 09:28:10 -08003509 /**
3510 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3511 * @param subId The subscription to use to check the configuration.
3512 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003513 @Override
3514 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003515 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3516 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003517
Brad Ebinger35c841c2018-10-01 10:40:55 -07003518 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3519 final long token = Binder.clearCallingIdentity();
3520 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003521 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003522 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003523 } catch (ImsException e) {
3524 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003525 } finally {
3526 Binder.restoreCallingIdentity(token);
3527 }
3528 }
3529
3530 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003531 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003533 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003534 final long identity = Binder.clearCallingIdentity();
3535 try {
3536 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003537 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003538 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003539 } catch (ImsException e) {
3540 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003541 } finally {
3542 Binder.restoreCallingIdentity(identity);
3543 }
3544 }
3545
shilu366312e2019-12-17 09:28:10 -08003546 /**
3547 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3548 * @param subId The subscription to use to check the configuration.
3549 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003550 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003551 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003552 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3553 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003554 final long identity = Binder.clearCallingIdentity();
3555 try {
3556 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003557 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3558 } catch (ImsException e) {
3559 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003560 } finally {
3561 Binder.restoreCallingIdentity(identity);
3562 }
3563 }
3564
3565 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003566 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003567 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003568 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003569 final long identity = Binder.clearCallingIdentity();
3570 try {
3571 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003572 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003573 } catch (ImsException e) {
3574 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003575 } finally {
3576 Binder.restoreCallingIdentity(identity);
3577 }
3578 }
3579
shilu366312e2019-12-17 09:28:10 -08003580 /**
3581 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3582 * @param subId The subscription to use to check the configuration.
3583 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003584 @Override
3585 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003586 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3587 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003588 final long identity = Binder.clearCallingIdentity();
3589 try {
3590 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003591 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003592 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003593 } catch (ImsException e) {
3594 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003595 } finally {
3596 Binder.restoreCallingIdentity(identity);
3597 }
3598 }
3599
3600 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003601 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003603 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003604 final long identity = Binder.clearCallingIdentity();
3605 try {
3606 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003607 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003608 } catch (ImsException e) {
3609 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003610 } finally {
3611 Binder.restoreCallingIdentity(identity);
3612 }
3613 }
3614
shilu366312e2019-12-17 09:28:10 -08003615 /**
3616 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3617 * @param subId The subscription to use to check the configuration.
3618 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003619 @Override
3620 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003621 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3622 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003623 final long identity = Binder.clearCallingIdentity();
3624 try {
3625 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003626 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003627 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003628 } catch (ImsException e) {
3629 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003630 } finally {
3631 Binder.restoreCallingIdentity(identity);
3632 }
3633 }
3634
3635 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003636 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003638 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003639 final long identity = Binder.clearCallingIdentity();
3640 try {
3641 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003642 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003643 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003644 } catch (ImsException e) {
3645 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003646 } finally {
3647 Binder.restoreCallingIdentity(identity);
3648 }
3649 }
3650
3651 @Override
3652 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3653 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3654 "setVoWiFiNonPersistent");
3655 final long identity = Binder.clearCallingIdentity();
3656 try {
3657 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003658 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003659 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003660 } catch (ImsException e) {
3661 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003662 } finally {
3663 Binder.restoreCallingIdentity(identity);
3664 }
3665 }
3666
shilu366312e2019-12-17 09:28:10 -08003667 /**
3668 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3669 * @param subId The subscription to use to check the configuration.
3670 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003671 @Override
3672 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003673 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3674 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003675 final long identity = Binder.clearCallingIdentity();
3676 try {
3677 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003678 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003679 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003680 } catch (ImsException e) {
3681 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003682 } finally {
3683 Binder.restoreCallingIdentity(identity);
3684 }
3685 }
3686
3687 @Override
3688 public void setVoWiFiModeSetting(int subId, int mode) {
3689 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3690 "setVoWiFiModeSetting");
3691 final long identity = Binder.clearCallingIdentity();
3692 try {
3693 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003694 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003695 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003696 } catch (ImsException e) {
3697 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003698 } finally {
3699 Binder.restoreCallingIdentity(identity);
3700 }
3701 }
3702
3703 @Override
3704 public int getVoWiFiRoamingModeSetting(int subId) {
3705 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3706 final long identity = Binder.clearCallingIdentity();
3707 try {
3708 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003709 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003710 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003711 } catch (ImsException e) {
3712 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003713 } finally {
3714 Binder.restoreCallingIdentity(identity);
3715 }
3716 }
3717
3718 @Override
3719 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3720 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3721 "setVoWiFiRoamingModeSetting");
3722 final long identity = Binder.clearCallingIdentity();
3723 try {
3724 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003725 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003726 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003727 } catch (ImsException e) {
3728 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003729 } finally {
3730 Binder.restoreCallingIdentity(identity);
3731 }
3732 }
3733
3734 @Override
3735 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3736 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3737 "setRttCapabilityEnabled");
3738 final long identity = Binder.clearCallingIdentity();
3739 try {
3740 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3742 } catch (ImsException e) {
3743 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003744 } finally {
3745 Binder.restoreCallingIdentity(identity);
3746 }
3747 }
3748
shilu366312e2019-12-17 09:28:10 -08003749 /**
3750 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3751 * @param subId The subscription to use to check the configuration.
3752 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003753 @Override
3754 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003755 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3756 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003757 final long identity = Binder.clearCallingIdentity();
3758 try {
3759 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003760 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003761 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003762 } catch (ImsException e) {
3763 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003764 } finally {
3765 Binder.restoreCallingIdentity(identity);
3766 }
3767 }
3768
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003769 @Override
3770 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3771 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3772 final long identity = Binder.clearCallingIdentity();
3773 try {
Brad Ebingerd0331732020-01-16 11:21:18 -08003774 if (!isImsAvailableOnDevice()) {
3775 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3776 "IMS not available on device.");
Peter Wang44b186e2020-01-13 23:33:09 -08003777 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003778 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003779 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003780 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003781 } catch (ImsException e) {
3782 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003783 } finally {
3784 Binder.restoreCallingIdentity(identity);
3785 }
3786 }
3787
3788 @Override
3789 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3790 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3791 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003792 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3793 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3794 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003795 try {
3796 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003797 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003798 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003799 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003800 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3801 + "is inactive, ignoring unregister.");
3802 // If the subscription is no longer active, just return, since the callback will already
3803 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003804 } finally {
3805 Binder.restoreCallingIdentity(identity);
3806 }
3807 }
3808
allenwtsu99c623b2020-01-03 18:24:23 +08003809
3810 private void checkModifyPhoneStatePermission(int subId, String message) {
3811 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3812 message);
3813 }
3814
3815 private boolean isImsProvisioningRequired(int subId, int capability,
3816 boolean isMmtelCapability) {
3817 Phone phone = getPhone(subId);
3818 if (phone == null) {
3819 loge("phone instance null for subid " + subId);
3820 return false;
3821 }
3822 if (isMmtelCapability) {
3823 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3824 return false;
3825 }
3826 } else {
3827 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3828 return false;
3829 }
3830 }
3831 return true;
3832 }
3833
3834 @Override
3835 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3836 boolean isProvisioned) {
3837 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3838
3839 final long identity = Binder.clearCallingIdentity();
3840 try {
3841 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3842 if (!isImsProvisioningRequired(subId, capability, false)) {
3843 return;
3844 }
3845
3846 // this capability requires provisioning, route to the correct API.
3847 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3848 switch (capability) {
3849 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3850 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3851 ims.setEabProvisioned(isProvisioned);
3852 break;
3853 default: {
3854 throw new IllegalArgumentException("Tried to set provisioning for "
3855 + "rcs capability '" + capability + "', which does not require "
3856 + "provisioning.");
3857 }
3858 }
3859 } finally {
3860 Binder.restoreCallingIdentity(identity);
3861 }
3862
3863 }
3864
3865
3866 @Override
3867 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3868 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3869 final long identity = Binder.clearCallingIdentity();
3870 try {
3871 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3872 if (!isImsProvisioningRequired(subId, capability, false)) {
3873 return true;
3874 }
3875
3876 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3877 switch (capability) {
3878 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3879 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3880 return ims.isEabProvisionedOnDevice();
3881
3882 default: {
3883 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3884 + "capability '" + capability + "', which does not require "
3885 + "provisioning.");
3886 }
3887 }
3888
3889 } finally {
3890 Binder.restoreCallingIdentity(identity);
3891 }
3892 }
3893
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003894 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003895 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3896 boolean isProvisioned) {
3897 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3898 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3899 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3900 }
allenwtsu99c623b2020-01-03 18:24:23 +08003901 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003902 final long identity = Binder.clearCallingIdentity();
3903 try {
3904 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003905 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003906 return;
3907 }
3908
3909 // this capability requires provisioning, route to the correct API.
3910 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3911 switch (capability) {
3912 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3913 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3914 ims.setVolteProvisioned(isProvisioned);
3915 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3916 ims.setWfcProvisioned(isProvisioned);
3917 }
3918 break;
3919 }
3920 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3921 // There is currently no difference in VT provisioning type.
3922 ims.setVtProvisioned(isProvisioned);
3923 break;
3924 }
3925 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3926 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3927 // change the capability of the feature instead if needed.
3928 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3929 == isProvisioned) {
3930 // No change in provisioning.
3931 return;
3932 }
3933 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3934 try {
3935 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003936 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003937 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3938 + ", Exception" + e.getMessage());
3939 }
3940 break;
3941 }
3942 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003943 throw new IllegalArgumentException("Tried to set provisioning for "
3944 + "MmTel capability '" + capability + "', which does not require "
3945 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003946 }
3947 }
3948
3949 } finally {
3950 Binder.restoreCallingIdentity(identity);
3951 }
3952 }
3953
3954 @Override
3955 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3956 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3957 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3958 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3959 }
3960 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3961 final long identity = Binder.clearCallingIdentity();
3962 try {
3963 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003964 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003965 return true;
3966 }
3967
3968 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3969 switch (capability) {
3970 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3971 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 return ims.isVolteProvisionedOnDevice();
3973 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3974 return ims.isWfcProvisionedOnDevice();
3975 }
3976 // This should never happen, since we are checking tech above to make sure it
3977 // is either LTE or IWLAN.
3978 throw new IllegalArgumentException("Invalid radio technology for voice "
3979 + "capability.");
3980 }
3981 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3982 // There is currently no difference in VT provisioning type.
3983 return ims.isVtProvisionedOnDevice();
3984 }
3985 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3986 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
3987 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
3988 }
3989 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003990 throw new IllegalArgumentException(
3991 "Tried to get provisioning for MmTel capability '" + capability
3992 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003993 }
3994 }
3995
3996 } finally {
3997 Binder.restoreCallingIdentity(identity);
3998 }
3999 }
4000
4001 @Override
4002 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4003 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4004 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4005 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4006 }
4007 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4008 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4009 return (provisionedBits & capability) > 0;
4010 }
4011
4012 @Override
4013 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4014 boolean isProvisioned) {
4015 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4016 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4017 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4018 }
4019 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4020 "setProvisioningStatusForCapability");
4021 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4022 // If the current provisioning status for capability already matches isProvisioned,
4023 // do nothing.
4024 if (((provisionedBits & capability) > 0) == isProvisioned) {
4025 return;
4026 }
4027 if (isProvisioned) {
4028 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4029 } else {
4030 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4031 }
4032 }
4033
4034 /**
4035 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4036 * technology. The bitfield should mirror the bitfield defined by
4037 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4038 */
4039 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4040 String key = getMmTelProvisioningKey(subId, tech);
4041 // Default is no capabilities are provisioned.
4042 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4043 }
4044
4045 /**
4046 * Sets the MmTel capability provisioning bitfield (defined by
4047 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4048 * technology specified.
4049 *
4050 * Note: This is a synchronous command and should not be called on UI thread.
4051 */
4052 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4053 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4054 String key = getMmTelProvisioningKey(subId, tech);
4055 editor.putInt(key, newField);
4056 editor.commit();
4057 }
4058
4059 private static String getMmTelProvisioningKey(int subId, int tech) {
4060 // resulting key is provision_ims_mmtel_{subId}_{tech}
4061 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4062 }
4063
4064 /**
4065 * Query CarrierConfig to see if the specified capability requires provisioning for the
4066 * carrier associated with the subscription id.
4067 */
4068 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4069 int capability) {
4070 CarrierConfigManager configManager = new CarrierConfigManager(context);
4071 PersistableBundle c = configManager.getConfigForSubId(subId);
4072 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004073 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004074 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4075 false);
4076 boolean requireVoiceVtProvisioning = c.getBoolean(
4077 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4078
4079 // First check to make sure that the capability requires provisioning.
4080 switch (capability) {
4081 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4082 // intentional fallthrough
4083 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4084 if (requireVoiceVtProvisioning) {
4085 // Voice and Video requires provisioning
4086 return true;
4087 }
4088 break;
4089 }
4090 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4091 if (requireUtProvisioning) {
4092 // UT requires provisioning
4093 return true;
4094 }
4095 break;
4096 }
4097 }
4098 return false;
4099 }
4100
allenwtsu99c623b2020-01-03 18:24:23 +08004101 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4102 int capability) {
4103 CarrierConfigManager configManager = new CarrierConfigManager(context);
4104 PersistableBundle c = configManager.getConfigForSubId(subId);
4105
4106 boolean requireRcsProvisioning = c.getBoolean(
4107 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4108
4109 // First check to make sure that the capability requires provisioning.
4110 switch (capability) {
4111 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4112 // intentional fallthrough
4113 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4114 if (requireRcsProvisioning) {
4115 // OPTION or PRESENCE requires provisioning
4116 return true;
4117 }
4118 break;
4119 }
4120 }
4121 return false;
4122 }
4123
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004124 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004125 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004126 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4127 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4128 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004129 enforceReadPrivilegedPermission("getImsProvisioningInt");
4130 final long identity = Binder.clearCallingIdentity();
4131 try {
4132 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004133 int slotId = getSlotIndex(subId);
4134 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4135 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4136 + subId + "' for key:" + key);
4137 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4138 }
4139 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004140 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004141 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4142 + subId + "' for key:" + key);
4143 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004144 } finally {
4145 Binder.restoreCallingIdentity(identity);
4146 }
4147 }
4148
4149 @Override
4150 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004151 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4152 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4153 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004154 enforceReadPrivilegedPermission("getImsProvisioningString");
4155 final long identity = Binder.clearCallingIdentity();
4156 try {
4157 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004158 int slotId = getSlotIndex(subId);
4159 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4160 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4161 + subId + "' for key:" + key);
4162 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4163 }
4164 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004165 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004166 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4167 + subId + "' for key:" + key);
4168 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004169 } finally {
4170 Binder.restoreCallingIdentity(identity);
4171 }
4172 }
4173
4174 @Override
4175 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004176 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4177 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4178 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004179 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4180 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004181 final long identity = Binder.clearCallingIdentity();
4182 try {
4183 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004184 int slotId = getSlotIndex(subId);
4185 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4186 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4187 + subId + "' for key:" + key);
4188 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4189 }
4190 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004191 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004192 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4193 + "' for key:" + key);
4194 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004195 } finally {
4196 Binder.restoreCallingIdentity(identity);
4197 }
4198 }
4199
4200 @Override
4201 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004202 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4203 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4204 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004205 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4206 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004207 final long identity = Binder.clearCallingIdentity();
4208 try {
4209 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004210 int slotId = getSlotIndex(subId);
4211 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4212 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4213 + subId + "' for key:" + key);
4214 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4215 }
4216 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004217 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004218 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4219 + "' for key:" + key);
4220 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004221 } finally {
4222 Binder.restoreCallingIdentity(identity);
4223 }
4224 }
4225
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004226 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004227 int slotId = SubscriptionManager.getSlotIndex(subId);
4228 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004229 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4230 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004231 }
4232 return slotId;
4233 }
4234
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004235 private int getSlotIndex(int subId) {
4236 int slotId = SubscriptionManager.getSlotIndex(subId);
4237 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4238 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4239 }
4240 return slotId;
4241 }
4242
Wink Saville36469e72014-06-11 15:17:00 -07004243 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004244 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004245 */
4246 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004247 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4248 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004249 final int targetSdk = getTargetSdk(callingPackage);
4250 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004251 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004252 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004253 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004254 mApp, subId, callingPackage, callingFeatureId,
4255 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004256 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4257 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004259 final long identity = Binder.clearCallingIdentity();
4260 try {
4261 final Phone phone = getPhone(subId);
4262 if (phone != null) {
4263 return phone.getServiceState().getDataNetworkType();
4264 } else {
4265 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4266 }
4267 } finally {
4268 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004269 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004270 }
4271
4272 /**
4273 * Returns the data network type
4274 */
4275 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004276 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4277 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4278 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004279 }
4280
4281 /**
4282 * Returns the data network type for a subId
4283 */
4284 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004285 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4286 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004287 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004288 mApp, subId, callingPackage, callingFeatureId,
4289 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004290 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4291 }
4292
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004293 final long identity = Binder.clearCallingIdentity();
4294 try {
4295 final Phone phone = getPhone(subId);
4296 if (phone != null) {
4297 return phone.getServiceState().getDataNetworkType();
4298 } else {
4299 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4300 }
4301 } finally {
4302 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004303 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004304 }
4305
4306 /**
Wink Saville36469e72014-06-11 15:17:00 -07004307 * Returns the Voice network type for a subId
4308 */
4309 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004310 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4311 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004312 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004313 mApp, subId, callingPackage, callingFeatureId,
4314 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004315 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4316 }
4317
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004318 final long identity = Binder.clearCallingIdentity();
4319 try {
4320 final Phone phone = getPhone(subId);
4321 if (phone != null) {
4322 return phone.getServiceState().getVoiceNetworkType();
4323 } else {
4324 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4325 }
4326 } finally {
4327 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004328 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004329 }
4330
4331 /**
4332 * @return true if a ICC card is present
4333 */
4334 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004335 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004336 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4337 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004338 }
4339
4340 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004341 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004342 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004343 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004344 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004345 final long identity = Binder.clearCallingIdentity();
4346 try {
4347 final Phone phone = PhoneFactory.getPhone(slotIndex);
4348 if (phone != null) {
4349 return phone.getIccCard().hasIccCard();
4350 } else {
4351 return false;
4352 }
4353 } finally {
4354 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004355 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004356 }
4357
4358 /**
4359 * Return if the current radio is LTE on CDMA. This
4360 * is a tri-state return value as for a period of time
4361 * the mode may be unknown.
4362 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004363 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004364 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004365 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004366 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004367 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004368 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4369 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4370 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004371 }
4372
Sanket Padawe356d7632015-06-22 14:03:32 -07004373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004374 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4375 String callingFeatureId) {
Sarah Chin790d2922020-01-16 12:17:23 -08004376 try {
4377 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4378 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004379 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4380 }
4381
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004382 final long identity = Binder.clearCallingIdentity();
4383 try {
4384 final Phone phone = getPhone(subId);
4385 if (phone == null) {
4386 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4387 } else {
4388 return phone.getLteOnCdmaMode();
4389 }
4390 } finally {
4391 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004392 }
Wink Saville36469e72014-06-11 15:17:00 -07004393 }
4394
Wink Saville36469e72014-06-11 15:17:00 -07004395 /**
4396 * {@hide}
4397 * Returns Default subId, 0 in the case of single standby.
4398 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004399 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004400 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004401 }
4402
Shishir Agrawala9f32182016-04-12 12:00:16 -07004403 private int getSlotForDefaultSubscription() {
4404 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4405 }
4406
Wink Savilleb564aae2014-10-23 10:18:09 -07004407 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004408 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004409 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004410
Pengquan Menge92a50d2018-09-21 15:54:48 -07004411 private boolean isActiveSubscription(int subId) {
4412 return mSubscriptionController.isActiveSubId(subId);
4413 }
4414
Ihab Awadf2177b72013-11-25 13:33:23 -08004415 /**
4416 * @see android.telephony.TelephonyManager.WifiCallingChoices
4417 */
4418 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004419 final long identity = Binder.clearCallingIdentity();
4420 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004421 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004422 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4423 getWhenToMakeWifiCallsDefaultPreference());
4424 } finally {
4425 Binder.restoreCallingIdentity(identity);
4426 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004427 }
4428
4429 /**
4430 * @see android.telephony.TelephonyManager.WifiCallingChoices
4431 */
4432 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004433 final long identity = Binder.clearCallingIdentity();
4434 try {
4435 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4438 } finally {
4439 Binder.restoreCallingIdentity(identity);
4440 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004441 }
4442
Sailesh Nepald1e68152013-12-12 19:08:02 -08004443 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004444 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004445 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004446 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004447
Jordan Liu4c733742019-02-28 12:03:40 -08004448 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4449 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4450 if (phoneId == -1) {
4451 throw new IllegalArgumentException("Given slot index: " + slotIndex
4452 + " does not correspond to an active phone");
4453 }
4454 return PhoneFactory.getPhone(phoneId);
4455 }
4456
Shishir Agrawal566b7612013-10-28 14:41:00 -07004457 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004458 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4459 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004460 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4461 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004462 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004463 if (DBG) {
4464 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4465 }
4466 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4467 p2);
4468 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004469
Jordan Liu4c733742019-02-28 12:03:40 -08004470
4471 @Override
4472 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4473 int slotIndex, String callingPackage, String aid, int p2) {
4474 enforceModifyPermission();
4475 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4476 if (DBG) {
4477 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4478 }
4479 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4480 callingPackage, aid, p2);
4481 }
4482
4483 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4484 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004485 final long identity = Binder.clearCallingIdentity();
4486 try {
4487 if (TextUtils.equals(ISDR_AID, aid)) {
4488 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004489 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4490 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004491 if (bestComponent == null
4492 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4493 loge("The calling package is not allowed to access ISD-R.");
4494 throw new SecurityException(
4495 "The calling package is not allowed to access ISD-R.");
4496 }
Derek Tan740e1672017-06-27 14:56:27 -07004497 }
Derek Tan740e1672017-06-27 14:56:27 -07004498
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004499 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004500 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4501 null /* workSource */);
4502 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004503 return response;
4504 } finally {
4505 Binder.restoreCallingIdentity(identity);
4506 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004507 }
4508
4509 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004510 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4512 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004513 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4514 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4515 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004516
Jordan Liu4c733742019-02-28 12:03:40 -08004517 @Override
4518 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4519 enforceModifyPermission();
4520 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4521 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4522 channel);
4523 }
4524
4525 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004526 final long identity = Binder.clearCallingIdentity();
4527 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004528 if (channel < 0) {
4529 return false;
4530 }
Jordan Liu4c733742019-02-28 12:03:40 -08004531 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4532 null /* workSource */);
4533 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004534 return success;
4535 } finally {
4536 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004537 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004538 }
4539
4540 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004541 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004542 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004543 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4544 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004545 if (DBG) {
4546 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4547 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4548 + p3 + " data=" + data);
4549 }
4550 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4551 command, p1, p2, p3, data);
4552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004553
Jordan Liu4c733742019-02-28 12:03:40 -08004554 @Override
4555 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4556 int command, int p1, int p2, int p3, String data) {
4557 enforceModifyPermission();
4558 if (DBG) {
4559 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4560 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4561 + p3 + " data=" + data);
4562 }
4563 return iccTransmitApduLogicalChannelWithPermission(
4564 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4565 data);
4566 }
4567
4568 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4569 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004570 final long identity = Binder.clearCallingIdentity();
4571 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004572 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004573 return "";
4574 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004575
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004576 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004577 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4578 null /* workSource */);
4579 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004580
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004581 // Append the returned status code to the end of the response payload.
4582 String s = Integer.toHexString(
4583 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4584 if (response.payload != null) {
4585 s = IccUtils.bytesToHexString(response.payload) + s;
4586 }
4587 return s;
4588 } finally {
4589 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004590 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004591 }
Jake Hambye994d462014-02-03 13:10:13 -08004592
Evan Charltonc66da362014-05-16 14:06:40 -07004593 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004594 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4595 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004596 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4597 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004598 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004599 if (DBG) {
4600 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4601 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4602 }
4603 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4604 cla, command, p1, p2, p3, data);
4605 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004606
Jordan Liu4c733742019-02-28 12:03:40 -08004607 @Override
4608 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4609 int command, int p1, int p2, int p3, String data) {
4610 enforceModifyPermission();
4611 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4612 if (DBG) {
4613 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4614 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4615 + " data=" + data);
4616 }
4617
4618 return iccTransmitApduBasicChannelWithPermission(
4619 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4620 p2, p3, data);
4621 }
4622
4623 // open APDU basic channel assuming the caller has sufficient permissions
4624 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4625 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004626 final long identity = Binder.clearCallingIdentity();
4627 try {
4628 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4629 && TextUtils.equals(ISDR_AID, data)) {
4630 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004631 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4632 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004633 if (bestComponent == null
4634 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4635 loge("The calling package is not allowed to select ISD-R.");
4636 throw new SecurityException(
4637 "The calling package is not allowed to select ISD-R.");
4638 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004639 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004640
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004642 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4643 null /* workSource */);
4644 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004645
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004646 // Append the returned status code to the end of the response payload.
4647 String s = Integer.toHexString(
4648 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4649 if (response.payload != null) {
4650 s = IccUtils.bytesToHexString(response.payload) + s;
4651 }
4652 return s;
4653 } finally {
4654 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004656 }
4657
4658 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004659 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004661 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4662 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004663
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004664 final long identity = Binder.clearCallingIdentity();
4665 try {
4666 if (DBG) {
4667 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4668 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4669 }
4670
4671 IccIoResult response =
4672 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4673 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4674 subId);
4675
4676 if (DBG) {
4677 log("Exchange SIM_IO [R]" + response);
4678 }
4679
4680 byte[] result = null;
4681 int length = 2;
4682 if (response.payload != null) {
4683 length = 2 + response.payload.length;
4684 result = new byte[length];
4685 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4686 } else {
4687 result = new byte[length];
4688 }
4689
4690 result[length - 1] = (byte) response.sw2;
4691 result[length - 2] = (byte) response.sw1;
4692 return result;
4693 } finally {
4694 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004695 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004696 }
4697
Nathan Haroldb3014052017-01-25 15:57:32 -08004698 /**
4699 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4700 * on a particular subscription
4701 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004702 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4703 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004704 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004705 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004706 return null;
4707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004708
4709 final long identity = Binder.clearCallingIdentity();
4710 try {
4711 if (appType != TelephonyManager.APPTYPE_USIM
4712 && appType != TelephonyManager.APPTYPE_SIM) {
4713 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4714 return null;
4715 }
4716 Object response = sendRequest(
4717 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4718 if (response instanceof String[]) {
4719 return (String[]) response;
4720 }
yincheng zhao2737e882019-09-06 17:06:54 -07004721 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004722 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004723 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004724 } finally {
4725 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004726 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004727 }
4728
yincheng zhao2737e882019-09-06 17:06:54 -07004729 /**
4730 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4731 * subscription.
4732 *
4733 * @param subId the id of the subscription.
4734 * @param appType the uicc app type, must be USIM or SIM.
4735 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4736 * @param callingPackage the op Package name.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004737 * @param callingFeatureId the feature in the package.
yincheng zhao2737e882019-09-06 17:06:54 -07004738 * @return number of fplmns that is successfully written to the SIM.
4739 */
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004740 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4741 String callingFeatureId) {
4742 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4743 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhao2737e882019-09-06 17:06:54 -07004744 if (DBG) logv("no permissions for setForbiddenplmns");
4745 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4746 }
4747 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4748 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4749 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4750 }
4751 if (fplmns == null) {
4752 throw new IllegalArgumentException("Fplmn List provided is null");
4753 }
4754 for (String fplmn : fplmns) {
4755 if (!CellIdentity.isValidPlmn(fplmn)) {
4756 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4757 }
4758 }
4759 final long identity = Binder.clearCallingIdentity();
4760 try {
4761 Object response = sendRequest(
4762 CMD_SET_FORBIDDEN_PLMNS,
4763 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4764 subId);
4765 return (int) response;
4766 } finally {
4767 Binder.restoreCallingIdentity(identity);
4768 }
4769 }
4770
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004771 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004772 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004773 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4774 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004775
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004776 final long identity = Binder.clearCallingIdentity();
4777 try {
4778 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4779 if (response.payload == null) {
4780 return "";
4781 }
Evan Charltonc66da362014-05-16 14:06:40 -07004782
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004783 // Append the returned status code to the end of the response payload.
4784 String s = Integer.toHexString(
4785 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4786 s = IccUtils.bytesToHexString(response.payload) + s;
4787 return s;
4788 } finally {
4789 Binder.restoreCallingIdentity(identity);
4790 }
Evan Charltonc66da362014-05-16 14:06:40 -07004791 }
4792
Jake Hambye994d462014-02-03 13:10:13 -08004793 /**
4794 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4795 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4796 *
4797 * @param itemID the ID of the item to read
4798 * @return the NV item as a String, or null on error.
4799 */
4800 @Override
4801 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004802 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004803 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4804 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004805
4806 final long identity = Binder.clearCallingIdentity();
4807 try {
4808 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004809 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004810 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4811 return value;
4812 } finally {
4813 Binder.restoreCallingIdentity(identity);
4814 }
Jake Hambye994d462014-02-03 13:10:13 -08004815 }
4816
4817 /**
4818 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4819 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4820 *
4821 * @param itemID the ID of the item to read
4822 * @param itemValue the value to write, as a String
4823 * @return true on success; false on any failure
4824 */
4825 @Override
4826 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004827 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004828 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4829 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004830
4831 final long identity = Binder.clearCallingIdentity();
4832 try {
4833 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4834 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004835 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004836 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4837 return success;
4838 } finally {
4839 Binder.restoreCallingIdentity(identity);
4840 }
Jake Hambye994d462014-02-03 13:10:13 -08004841 }
4842
4843 /**
4844 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4845 * Used for device configuration by some CDMA operators.
4846 *
4847 * @param preferredRoamingList byte array containing the new PRL
4848 * @return true on success; false on any failure
4849 */
4850 @Override
4851 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004852 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4853 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004854
4855 final long identity = Binder.clearCallingIdentity();
4856 try {
4857 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4858 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4859 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4860 return success;
4861 } finally {
4862 Binder.restoreCallingIdentity(identity);
4863 }
Jake Hambye994d462014-02-03 13:10:13 -08004864 }
4865
4866 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004867 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004868 * Used for device configuration by some CDMA operators.
4869 *
chen xu6dac5ab2018-10-26 17:39:23 -07004870 * @param slotIndex - device slot.
4871 *
Jake Hambye994d462014-02-03 13:10:13 -08004872 * @return true on success; false on any failure
4873 */
4874 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004875 public boolean resetModemConfig(int slotIndex) {
4876 Phone phone = PhoneFactory.getPhone(slotIndex);
4877 if (phone != null) {
4878 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4879 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004880
chen xu6dac5ab2018-10-26 17:39:23 -07004881 final long identity = Binder.clearCallingIdentity();
4882 try {
4883 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4884 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4885 return success;
4886 } finally {
4887 Binder.restoreCallingIdentity(identity);
4888 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004889 }
chen xu6dac5ab2018-10-26 17:39:23 -07004890 return false;
4891 }
4892
4893 /**
4894 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4895 *
4896 * @param slotIndex - device slot.
4897 *
4898 * @return true on success; false on any failure
4899 */
4900 @Override
4901 public boolean rebootModem(int slotIndex) {
4902 Phone phone = PhoneFactory.getPhone(slotIndex);
4903 if (phone != null) {
4904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4905 mApp, phone.getSubId(), "rebootModem");
4906
4907 final long identity = Binder.clearCallingIdentity();
4908 try {
4909 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4910 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4911 return success;
4912 } finally {
4913 Binder.restoreCallingIdentity(identity);
4914 }
4915 }
4916 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004917 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004918
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004919 public String[] getPcscfAddress(String apnType, String callingPackage,
4920 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004921 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07004922 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4923 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004924 return new String[0];
4925 }
4926
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004927 final long identity = Binder.clearCallingIdentity();
4928 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004929 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004930 } finally {
4931 Binder.restoreCallingIdentity(identity);
4932 }
Wink Saville36469e72014-06-11 15:17:00 -07004933 }
4934
Brad Ebinger51f743a2017-01-23 13:50:20 -08004935 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004936 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4937 * {@link #disableIms(int)}.
4938 * @param slotIndex device slot.
4939 */
4940 public void resetIms(int slotIndex) {
4941 enforceModifyPermission();
4942
4943 final long identity = Binder.clearCallingIdentity();
4944 try {
4945 if (mImsResolver == null) {
4946 // may happen if the does not support IMS.
4947 return;
4948 }
4949 mImsResolver.disableIms(slotIndex);
4950 mImsResolver.enableIms(slotIndex);
4951 } finally {
4952 Binder.restoreCallingIdentity(identity);
4953 }
4954 }
4955
4956 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004957 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4958 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004959 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004960 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004961 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004962
4963 final long identity = Binder.clearCallingIdentity();
4964 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004965 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004966 // may happen if the device does not support IMS.
4967 return;
4968 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004969 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004970 } finally {
4971 Binder.restoreCallingIdentity(identity);
4972 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004973 }
4974
4975 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004976 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4977 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004978 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004979 public void disableIms(int slotId) {
4980 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004981
4982 final long identity = Binder.clearCallingIdentity();
4983 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08004984 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004985 // may happen if the device does not support IMS.
4986 return;
4987 }
Brad Ebinger24c29992019-12-05 13:03:21 -08004988 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004989 } finally {
4990 Binder.restoreCallingIdentity(identity);
4991 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004992 }
4993
4994 /**
4995 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
4996 * feature or {@link null} if the service is not available. If the feature is available, the
4997 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
4998 */
4999 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005000 IImsServiceFeatureCallback callback) {
5001 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005002
5003 final long identity = Binder.clearCallingIdentity();
5004 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005005 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005006 // may happen if the device does not support IMS.
5007 return null;
5008 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005009 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005010 } finally {
5011 Binder.restoreCallingIdentity(identity);
5012 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005013 }
5014
5015 /**
5016 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5017 * feature during emergency calling or {@link null} if the service is not available. If the
5018 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5019 * listener for feature updates.
5020 */
5021 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5022 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005023
5024 final long identity = Binder.clearCallingIdentity();
5025 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005026 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005027 // may happen if the device does not support IMS.
5028 return null;
5029 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005030 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005031 } finally {
5032 Binder.restoreCallingIdentity(identity);
5033 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005034 }
5035
Brad Ebinger5f64b052017-12-14 14:26:15 -08005036 /**
Brad Ebinger075ff3a2020-05-18 17:52:58 -07005037 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5038 */
5039 public void unregisterImsFeatureCallback(int slotId, int featureType,
5040 IImsServiceFeatureCallback callback) {
5041 enforceModifyPermission();
5042
5043 final long identity = Binder.clearCallingIdentity();
5044 try {
5045 if (mImsResolver == null) return;
5046 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5047 } finally {
5048 Binder.restoreCallingIdentity(identity);
5049 }
5050 }
5051
5052 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005053 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005054 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005055 */
5056 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5057 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005058
5059 final long identity = Binder.clearCallingIdentity();
5060 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005061 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005062 // may happen if the device does not support IMS.
5063 return null;
5064 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005065 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005066 } finally {
5067 Binder.restoreCallingIdentity(identity);
5068 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005069 }
5070
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005071 /**
5072 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005073 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005074 */
5075 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5076 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005077
5078 final long identity = Binder.clearCallingIdentity();
5079 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005080 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005081 // may happen if the device does not support IMS.
5082 return null;
5083 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005084 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005085 } finally {
5086 Binder.restoreCallingIdentity(identity);
5087 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005088 }
5089
Brad Ebinger884c07b2018-02-15 16:17:40 -08005090 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005091 * Sets the ImsService Package Name that Telephony will bind to.
5092 *
Brad Ebinger24c29992019-12-05 13:03:21 -08005093 * @param slotIndex the slot ID that the ImsService should bind for.
5094 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005095 * ImsService is the device default ImsService.
Brad Ebinger24c29992019-12-05 13:03:21 -08005096 * @param featureTypes An integer array of feature types associated with a packageName.
5097 * @param packageName The name of the package that the current configuration will be replaced
5098 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005099 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005100 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005101 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5102 int[] featureTypes, String packageName) {
5103 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5104 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005105 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5106 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger24c29992019-12-05 13:03:21 -08005107 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005108
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005109 final long identity = Binder.clearCallingIdentity();
5110 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005111 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005112 // may happen if the device does not support IMS.
5113 return false;
5114 }
Brad Ebinger24c29992019-12-05 13:03:21 -08005115 Map<Integer, String> featureConfig = new HashMap<>();
5116 for (int featureType : featureTypes) {
5117 featureConfig.put(featureType, packageName);
5118 }
5119 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5120 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005121 } finally {
5122 Binder.restoreCallingIdentity(identity);
5123 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005124 }
5125
5126 /**
Brad Ebinger24c29992019-12-05 13:03:21 -08005127 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005128 *
5129 * @param slotId The slot that the ImsService is associated with.
5130 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5131 * the device default.
Brad Ebinger24c29992019-12-05 13:03:21 -08005132 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005133 * @return the package name of the ImsService configuration.
5134 */
Brad Ebinger24c29992019-12-05 13:03:21 -08005135 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5136 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005137 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger24c29992019-12-05 13:03:21 -08005138 TelephonyPermissions
5139 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5140 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5141 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005142
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005143 final long identity = Binder.clearCallingIdentity();
5144 try {
Brad Ebinger24c29992019-12-05 13:03:21 -08005145 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005146 // may happen if the device does not support IMS.
5147 return "";
5148 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005149 // TODO: change API to query RCS separately.
Brad Ebinger24c29992019-12-05 13:03:21 -08005150 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5151 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005152 } finally {
5153 Binder.restoreCallingIdentity(identity);
5154 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005155 }
5156
Brad Ebingerbc7dd582019-10-17 17:03:22 -07005157 /**
5158 * Get the MmTelFeature state associated with the requested subscription id.
5159 * @param subId The subscription that the MmTelFeature is associated with.
5160 * @param callback A callback with an integer containing the
5161 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5162 */
5163 @Override
5164 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5165 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5166 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5167 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5168 "IMS not available on device.");
5169 }
5170 final long token = Binder.clearCallingIdentity();
5171 try {
5172 int slotId = getSlotIndex(subId);
5173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5174 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5175 + subId + "'");
5176 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5177 }
5178 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5179 try {
5180 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5181 } catch (RemoteException e) {
5182 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5183 + "Ignore");
5184 }
5185 });
5186 } finally {
5187 Binder.restoreCallingIdentity(token);
5188 }
5189 }
5190
Wink Saville36469e72014-06-11 15:17:00 -07005191 public void setImsRegistrationState(boolean registered) {
5192 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005193
5194 final long identity = Binder.clearCallingIdentity();
5195 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005196 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005197 } finally {
5198 Binder.restoreCallingIdentity(identity);
5199 }
Wink Saville36469e72014-06-11 15:17:00 -07005200 }
5201
5202 /**
Stuart Scott54788802015-03-30 13:18:01 -07005203 * Set the network selection mode to automatic.
5204 *
5205 */
5206 @Override
5207 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005208 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5209 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005210
5211 final long identity = Binder.clearCallingIdentity();
5212 try {
shilufc958392020-01-20 11:36:01 -08005213 if (!isActiveSubscription(subId)) {
5214 return;
5215 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005216 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5217 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5218 } finally {
5219 Binder.restoreCallingIdentity(identity);
5220 }
Stuart Scott54788802015-03-30 13:18:01 -07005221 }
5222
Pengquan Mengea84e042018-09-20 14:57:26 -07005223 /**
5224 * Ask the radio to connect to the input network and change selection mode to manual.
5225 *
5226 * @param subId the id of the subscription.
5227 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5228 * the operator to attach to.
5229 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5230 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5231 * normal network selection next time.
5232 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005233 */
5234 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005235 public boolean setNetworkSelectionModeManual(
5236 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005237 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5238 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005239
5240 if (!isActiveSubscription(subId)) {
5241 return false;
5242 }
5243
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005244 final long identity = Binder.clearCallingIdentity();
5245 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005246 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005247 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005248 if (DBG) {
5249 log("setNetworkSelectionModeManual: subId: " + subId
5250 + " operator: " + operatorInfo);
5251 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005252 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5253 } finally {
5254 Binder.restoreCallingIdentity(identity);
5255 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005256 }
shilu84f6e8b2019-12-19 13:58:01 -08005257 /**
5258 * Get the manual network selection
5259 *
5260 * @param subId the id of the subscription.
5261 *
5262 * @return the previously saved user selected PLMN
5263 */
5264 @Override
5265 public String getManualNetworkSelectionPlmn(int subId) {
5266 TelephonyPermissions
5267 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5268 mApp, subId, "getManualNetworkSelectionPlmn");
5269
5270 final long identity = Binder.clearCallingIdentity();
5271 try {
5272 if (!isActiveSubscription(subId)) {
shilufa1c2592020-03-10 10:59:43 -07005273 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005274 }
5275
5276 final Phone phone = getPhone(subId);
5277 if (phone == null) {
shilufa1c2592020-03-10 10:59:43 -07005278 throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
shilu84f6e8b2019-12-19 13:58:01 -08005279 }
5280 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5281 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5282 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5283 } finally {
5284 Binder.restoreCallingIdentity(identity);
5285 }
5286 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005287
5288 /**
5289 * Scans for available networks.
5290 */
5291 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005292 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5293 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005294 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5295 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005296 LocationAccessPolicy.LocationPermissionResult locationResult =
5297 LocationAccessPolicy.checkLocationPermission(mApp,
5298 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5299 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005300 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005301 .setCallingPid(Binder.getCallingPid())
5302 .setCallingUid(Binder.getCallingUid())
5303 .setMethod("getCellNetworkScanResults")
5304 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07005305 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
5306 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08005307 .build());
5308 switch (locationResult) {
5309 case DENIED_HARD:
5310 throw new SecurityException("Not allowed to access scan results -- location");
5311 case DENIED_SOFT:
5312 return null;
5313 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005314
Pengquan Menga1bb6272018-09-06 09:59:22 -07005315 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005316 try {
5317 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005318 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005319 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005320 } finally {
5321 Binder.restoreCallingIdentity(identity);
5322 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005323 }
5324
5325 /**
Shuo Qian4a594052020-01-23 11:59:30 -08005326 * Get the call forwarding info, given the call forwarding reason.
5327 */
5328 @Override
5329 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5330 enforceReadPrivilegedPermission("getCallForwarding");
5331 long identity = Binder.clearCallingIdentity();
5332 try {
5333 if (DBG) {
5334 log("getCallForwarding: subId " + subId
5335 + " callForwardingReason" + callForwardingReason);
5336 }
5337 return (CallForwardingInfo) sendRequest(
5338 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5339 } finally {
5340 Binder.restoreCallingIdentity(identity);
5341 }
5342 }
5343
5344 /**
5345 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5346 * reason, the number to forward, and the timeout before the forwarding is attempted.
5347 */
5348 @Override
5349 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5350 enforceModifyPermission();
5351 long identity = Binder.clearCallingIdentity();
5352 try {
5353 if (DBG) {
5354 log("setCallForwarding: subId " + subId
5355 + " callForwardingInfo" + callForwardingInfo);
5356 }
5357 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5358 } finally {
5359 Binder.restoreCallingIdentity(identity);
5360 }
5361 }
5362
5363 /**
5364 * Get the call forwarding info, given the call forwarding reason.
5365 */
5366 @Override
5367 public int getCallWaitingStatus(int subId) {
5368 enforceReadPrivilegedPermission("getCallForwarding");
5369 long identity = Binder.clearCallingIdentity();
5370 try {
5371 if (DBG) log("getCallWaitingStatus: subId " + subId);
5372 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5373 } finally {
5374 Binder.restoreCallingIdentity(identity);
5375 }
5376 }
5377
5378 /**
5379 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5380 * reason, the number to forward, and the timeout before the forwarding is attempted.
5381 */
5382 @Override
5383 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5384 enforceModifyPermission();
5385 long identity = Binder.clearCallingIdentity();
5386 try {
5387 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5388 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5389 } finally {
5390 Binder.restoreCallingIdentity(identity);
5391 }
5392 }
5393
5394 /**
yinxub1bed742017-04-17 11:45:04 -07005395 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005396 *
yinxub1bed742017-04-17 11:45:04 -07005397 * @param subId id of the subscription
5398 * @param request contains the radio access networks with bands/channels to scan
5399 * @param messenger callback messenger for scan results or errors
5400 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005401 * @return the id of the requested scan which can be used to stop the scan.
5402 */
5403 @Override
5404 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005405 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005406 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5407 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005408 LocationAccessPolicy.LocationPermissionResult locationResult =
5409 LocationAccessPolicy.checkLocationPermission(mApp,
5410 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5411 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07005412 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005413 .setCallingPid(Binder.getCallingPid())
5414 .setCallingUid(Binder.getCallingUid())
5415 .setMethod("requestNetworkScan")
5416 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5417 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005418 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005419 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005420 if (e != null) {
5421 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5422 throw e;
5423 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005424 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005425 return TelephonyScanManager.INVALID_SCAN_ID;
5426 }
5427 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005428 }
Hall Liu912dfd32019-04-25 14:02:26 -07005429 int callingUid = Binder.getCallingUid();
5430 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005431 final long identity = Binder.clearCallingIdentity();
5432 try {
5433 return mNetworkScanRequestTracker.startNetworkScan(
5434 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005435 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005436 } finally {
5437 Binder.restoreCallingIdentity(identity);
5438 }
yinxu504e1392017-04-12 16:03:22 -07005439 }
5440
Hall Liub2ac8ef2019-02-28 15:56:23 -08005441 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005442 NetworkScanRequest request, int subId) {
5443 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5444 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5445 boolean hasNetworkScanPermission =
5446 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5447 == PERMISSION_GRANTED;
5448
5449 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5450 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5451 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005452 }
5453
5454 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5455 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005456 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5457 return new SecurityException("Specific channels must not be"
5458 + " scanned without location access.");
5459 }
5460 }
5461 }
5462
Hall Liub2ac8ef2019-02-28 15:56:23 -08005463 return null;
5464 }
5465
yinxu504e1392017-04-12 16:03:22 -07005466 /**
5467 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005468 *
5469 * @param subId id of the subscription
5470 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005471 */
5472 @Override
5473 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005474 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5475 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005476
Hall Liu912dfd32019-04-25 14:02:26 -07005477 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005478 final long identity = Binder.clearCallingIdentity();
5479 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005480 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005481 } finally {
5482 Binder.restoreCallingIdentity(identity);
5483 }
yinxu504e1392017-04-12 16:03:22 -07005484 }
5485
5486 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005487 * Get the calculated preferred network type.
5488 * Used for debugging incorrect network type.
5489 *
5490 * @return the preferred network type, defined in RILConstants.java.
5491 */
5492 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005493 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005494 final Phone defaultPhone = getDefaultPhone();
5495 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07005496 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005497 return RILConstants.PREFERRED_NETWORK_MODE;
5498 }
5499
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005500 final long identity = Binder.clearCallingIdentity();
5501 try {
5502 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005503 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005504 } finally {
5505 Binder.restoreCallingIdentity(identity);
5506 }
Junda Liu84d15a22014-07-02 11:21:04 -07005507 }
5508
5509 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005510 * Get the preferred network type.
5511 * Used for device configuration by some CDMA operators.
5512 *
5513 * @return the preferred network type, defined in RILConstants.java.
5514 */
5515 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005516 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005517 TelephonyPermissions
5518 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5519 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005520
5521 final long identity = Binder.clearCallingIdentity();
5522 try {
5523 if (DBG) log("getPreferredNetworkType");
5524 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5525 int networkType = (result != null ? result[0] : -1);
5526 if (DBG) log("getPreferredNetworkType: " + networkType);
5527 return networkType;
5528 } finally {
5529 Binder.restoreCallingIdentity(identity);
5530 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005531 }
5532
5533 /**
5534 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005535 *
5536 * @param networkType the preferred network type, defined in RILConstants.java.
5537 * @return true on success; false on any failure.
5538 */
5539 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005540 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005541 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5542 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005543
5544 final long identity = Binder.clearCallingIdentity();
5545 try {
calvinpan0ac9c1a2020-01-14 20:42:55 +08005546 Settings.Global.putInt(mApp.getContentResolver(),
5547 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan8ed33732020-03-12 14:17:55 +08005548
5549 Boolean success = (Boolean) sendRequest(
5550 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5551 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5552 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005553 } finally {
5554 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005555 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005556 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005557
5558 /**
calvinpan0ac9c1a2020-01-14 20:42:55 +08005559 * Get the allowed network types that store in the telephony provider.
5560 *
5561 * @param subId the id of the subscription.
5562 * @return allowedNetworkTypes the allowed network types.
5563 */
5564 @Override
5565 public long getAllowedNetworkTypes(int subId) {
5566 TelephonyPermissions
5567 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5568 mApp, subId, "getAllowedNetworkTypes");
5569
5570 final long identity = Binder.clearCallingIdentity();
5571 try {
5572 return SubscriptionManager.getLongSubscriptionProperty(
5573 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5574 } finally {
5575 Binder.restoreCallingIdentity(identity);
5576 }
5577 }
5578
5579 /**
5580 * Set the allowed network types.
5581 *
5582 * @param subId the id of the subscription.
5583 * @param allowedNetworkTypes the allowed network types.
5584 * @return true on success; false on any failure.
5585 */
5586 @Override
5587 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5588 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5589 mApp, subId, "setAllowedNetworkTypes");
calvinpan0ac9c1a2020-01-14 20:42:55 +08005590
calvinpan8ed33732020-03-12 14:17:55 +08005591 SubscriptionManager.setSubscriptionProperty(subId,
5592 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5593 String.valueOf(allowedNetworkTypes));
calvinpan0ac9c1a2020-01-14 20:42:55 +08005594
calvinpan8ed33732020-03-12 14:17:55 +08005595 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5596 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5597 RILConstants.PREFERRED_NETWORK_MODE);
5598 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan0ac9c1a2020-01-14 20:42:55 +08005599 }
5600
5601 /**
Miaoa84611c2019-03-15 09:21:10 +08005602 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005603 *
Miaoa84611c2019-03-15 09:21:10 +08005604 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005605 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005606 * @hide
5607 */
5608 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005609 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005610 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005611 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005612 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005613 try {
Miaoa84611c2019-03-15 09:21:10 +08005614 if (phone != null) {
5615 return phone.hasMatchedTetherApnSetting();
5616 } else {
5617 return false;
5618 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005619 } finally {
5620 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005621 }
Junda Liu475951f2014-11-07 16:45:03 -08005622 }
5623
5624 /**
Shuo Qiancd19c462020-01-16 20:51:11 -08005625 * Enable or disable always reporting signal strength changes from radio.
5626 *
5627 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5628 */
5629 @Override
5630 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5631 enforceModifyPermission();
5632 enforceSystemCaller();
5633
5634 final long identity = Binder.clearCallingIdentity();
5635 final Phone phone = getPhone(subId);
5636 try {
5637 if (phone != null) {
5638 if (DBG) {
5639 log("setAlwaysReportSignalStrength: subId=" + subId
5640 + " isEnable=" + isEnable);
5641 }
5642 phone.setAlwaysReportSignalStrength(isEnable);
5643 } else {
5644 loge("setAlwaysReportSignalStrength: no phone found for subId="
5645 + subId);
5646 }
5647 } finally {
5648 Binder.restoreCallingIdentity(identity);
5649 }
5650 }
5651
5652 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005653 * Get the user enabled state of Mobile Data.
5654 *
5655 * TODO: remove and use isUserDataEnabled.
5656 * This can't be removed now because some vendor codes
5657 * calls through ITelephony directly while they should
5658 * use TelephonyManager.
5659 *
5660 * @return true on enabled
5661 */
5662 @Override
5663 public boolean getDataEnabled(int subId) {
5664 return isUserDataEnabled(subId);
5665 }
5666
5667 /**
5668 * Get whether mobile data is enabled per user setting.
5669 *
5670 * There are other factors deciding whether mobile data is actually enabled, but they are
5671 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005672 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005673 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005674 *
5675 * @return {@code true} if data is enabled else {@code false}
5676 */
5677 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005678 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005679 try {
5680 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5681 null);
5682 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005683 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5684 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005685 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005686
5687 final long identity = Binder.clearCallingIdentity();
5688 try {
5689 int phoneId = mSubscriptionController.getPhoneId(subId);
5690 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5691 Phone phone = PhoneFactory.getPhone(phoneId);
5692 if (phone != null) {
5693 boolean retVal = phone.isUserDataEnabled();
5694 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5695 return retVal;
5696 } else {
5697 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5698 return false;
5699 }
5700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005702 }
5703 }
5704
5705 /**
Shuo Qian8ee4e882020-01-08 14:30:06 -08005706 * Checks if the device is capable of mobile data by considering whether whether the
5707 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5708 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005709 *
Shuo Qian8ee4e882020-01-08 14:30:06 -08005710 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005711 */
5712 @Override
5713 public boolean isDataEnabled(int subId) {
Shuo Qian8ee4e882020-01-08 14:30:06 -08005714 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005715
5716 final long identity = Binder.clearCallingIdentity();
5717 try {
5718 int phoneId = mSubscriptionController.getPhoneId(subId);
5719 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5720 Phone phone = PhoneFactory.getPhone(phoneId);
5721 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005722 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005723 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5724 return retVal;
5725 } else {
5726 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5727 return false;
5728 }
5729 } finally {
5730 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005731 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005732 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005733
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00005734 /**
5735 * Check if data is enabled for a specific reason
5736 * @param subId Subscription index
5737 * @param reason the reason the data enable change is taking place
5738 * @return {@code true} if the overall data is enabled; {@code false} if not.
5739 */
5740 @Override
5741 public boolean isDataEnabledWithReason(int subId,
5742 @TelephonyManager.DataEnabledReason int reason) {
5743 try {
5744 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5745 null);
5746 } catch (Exception e) {
5747 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE,
5748 "isDataEnabledWithReason");
5749 }
5750
5751
5752 final long identity = Binder.clearCallingIdentity();
5753 try {
5754 int phoneId = mSubscriptionController.getPhoneId(subId);
5755 if (DBG) {
5756 log("isDataEnabledWithReason: subId=" + subId + " phoneId=" + phoneId
5757 + " reason=" + reason);
5758 }
5759 Phone phone = PhoneFactory.getPhone(phoneId);
5760 if (phone != null) {
5761 boolean retVal;
5762 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) {
5763 retVal = phone.isUserDataEnabled();
5764 } else {
5765 retVal = phone.getDataEnabledSettings().isDataEnabledWithReason(reason);
5766 }
5767 if (DBG) log("isDataEnabledWithReason: retVal=" + retVal);
5768 return retVal;
5769 } else {
5770 if (DBG) {
5771 loge("isDataEnabledWithReason: no phone subId="
5772 + subId + " retVal=false");
5773 }
5774 return false;
5775 }
5776 } finally {
5777 Binder.restoreCallingIdentity(identity);
5778 }
5779 }
5780
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005781 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005782 Phone phone) {
5783 //load access rules from carrier configs, and check those as well: b/139133814
5784 SubscriptionController subController = SubscriptionController.getInstance();
5785 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5786 || subController == null) return privilegeFromSim;
5787
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005788 PackageManager pkgMgr = phone.getContext().getPackageManager();
5789 String[] packages = pkgMgr.getPackagesForUid(uid);
5790
5791 final long identity = Binder.clearCallingIdentity();
5792 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005793 int subId = phone.getSubId();
5794 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5795 // A test override is in place for the privileges for this subId, so don't try to
5796 // read the subscription privileges.
5797 return privilegeFromSim;
5798 }
5799 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005800 SubscriptionManager subManager = (SubscriptionManager)
5801 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5802 for (String pkg : packages) {
5803 if (subManager.canManageSubscription(subInfo, pkg)) {
5804 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5805 }
5806 }
5807 return privilegeFromSim;
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
5810 }
5811 }
5812
5813 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5814 String pkgName) {
5815 //load access rules from carrier configs, and check those as well: b/139133814
5816 SubscriptionController subController = SubscriptionController.getInstance();
5817 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5818 || subController == null) return privilegeFromSim;
5819
5820 final long identity = Binder.clearCallingIdentity();
5821 try {
Jeff Davidson8ab02b22020-03-28 12:24:40 -07005822 int subId = phone.getSubId();
5823 if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) {
5824 // A test override is in place for the privileges for this subId, so don't try to
5825 // read the subscription privileges.
5826 return privilegeFromSim;
5827 }
5828 SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId);
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005829 SubscriptionManager subManager = (SubscriptionManager)
5830 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5831 return subManager.canManageSubscription(subInfo, pkgName)
5832 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5833 } finally {
5834 Binder.restoreCallingIdentity(identity);
5835 }
5836 }
5837
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005838 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005839 public int getCarrierPrivilegeStatus(int subId) {
5840 final Phone phone = getPhone(subId);
5841 if (phone == null) {
5842 loge("getCarrierPrivilegeStatus: Invalid subId");
5843 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5844 }
5845 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005846 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005847 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005848 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5849 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005850
5851 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5852 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005853 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005854 }
Junda Liu29340342014-07-10 15:23:27 -07005855
5856 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005857 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005858 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005859 final Phone phone = getPhone(subId);
5860 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005861 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005862 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5863 }
5864 UiccProfile profile =
5865 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5866 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005867 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005868 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5869 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005870 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian2c0ae432019-12-05 11:40:37 -08005871 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005872 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005873 }
5874
5875 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005876 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5877 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005878 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005879 }
5880
5881 int phoneId = SubscriptionManager.getPhoneId(subId);
5882 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005883 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005884 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005885 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5886 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005887 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5888 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5889 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005890 }
5891
5892 @Override
5893 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005894 if (TextUtils.isEmpty(pkgName))
5895 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005896 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5897 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5898 UiccCard card = UiccController.getInstance().getUiccCard(i);
5899 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005900 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005901 continue;
5902 }
5903
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005904 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5905 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5906 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005907 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5908 break;
5909 }
5910 }
5911
5912 return result;
Junda Liu29340342014-07-10 15:23:27 -07005913 }
Derek Tan89e89d42014-07-08 17:00:10 -07005914
5915 @Override
Junda Liue64de782015-04-16 17:19:16 -07005916 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5917 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5918 loge("phoneId " + phoneId + " is not valid.");
5919 return null;
5920 }
5921 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005922 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005923 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005924 return null ;
5925 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005926 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005927 }
5928
Amith Yamasani6e118872016-02-19 12:53:51 -08005929 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005930 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005931 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005932 List<String> privilegedPackages = new ArrayList<>();
5933 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005934 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5935 // has UICC in that slot.
5936 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005937 if (card.hasCarrierPrivilegeRules()) {
5938 if (packages == null) {
5939 // Only check packages in user 0 for now
5940 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005941 PackageManager.MATCH_DISABLED_COMPONENTS
5942 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005943 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajanb8f13202020-01-27 18:16:07 -08005944 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005945 }
5946 for (int p = packages.size() - 1; p >= 0; p--) {
5947 PackageInfo pkgInfo = packages.get(p);
5948 if (pkgInfo != null && pkgInfo.packageName != null
5949 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07005950 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005951 privilegedPackages.add(pkgInfo.packageName);
5952 }
5953 }
5954 }
5955 }
5956 return privilegedPackages;
5957 }
5958
chen xuf7e9fe82019-05-09 19:31:02 -07005959 @Override
5960 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qian067a06d2019-12-03 23:40:18 +00005961 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
5962
5963 final long identity = Binder.clearCallingIdentity();
5964
chen xuf7e9fe82019-05-09 19:31:02 -07005965 List<String> privilegedPackages = new ArrayList<>();
Shuo Qian067a06d2019-12-03 23:40:18 +00005966 try {
5967 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5968 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
5969 }
5970 } finally {
5971 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07005972 }
5973 return privilegedPackages;
5974 }
5975
Wink Savilleb564aae2014-10-23 10:18:09 -07005976 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07005977 final Phone phone = getPhone(subId);
5978 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07005979 if (card == null) {
5980 loge("getIccId: No UICC");
5981 return null;
5982 }
5983 String iccId = card.getIccId();
5984 if (TextUtils.isEmpty(iccId)) {
5985 loge("getIccId: ICC ID is null or empty.");
5986 return null;
5987 }
5988 return iccId;
5989 }
5990
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005991 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08005992 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
5993 String number) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08005994 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08005995 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07005996
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005997 final long identity = Binder.clearCallingIdentity();
5998 try {
5999 final String iccId = getIccId(subId);
6000 final Phone phone = getPhone(subId);
6001 if (phone == null) {
6002 return false;
6003 }
6004 final String subscriberId = phone.getSubscriberId();
6005
6006 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006007 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006008 + subscriberId + " to " + number);
6009 }
6010
6011 if (TextUtils.isEmpty(iccId)) {
6012 return false;
6013 }
6014
6015 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6016
6017 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6018 if (alphaTag == null) {
6019 editor.remove(alphaTagPrefKey);
6020 } else {
6021 editor.putString(alphaTagPrefKey, alphaTag);
6022 }
6023
6024 // Record both the line number and IMSI for this ICCID, since we need to
6025 // track all merged IMSIs based on line number
6026 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6027 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6028 if (number == null) {
6029 editor.remove(numberPrefKey);
6030 editor.remove(subscriberPrefKey);
6031 } else {
6032 editor.putString(numberPrefKey, number);
6033 editor.putString(subscriberPrefKey, subscriberId);
6034 }
6035
6036 editor.commit();
6037 return true;
6038 } finally {
6039 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006040 }
Derek Tan7226c842014-07-02 17:42:23 -07006041 }
6042
6043 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006044 public String getLine1NumberForDisplay(int subId, String callingPackage,
6045 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006046 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006047 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006048 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006049 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006050 return null;
6051 }
Derek Tan97ebb422014-09-05 16:55:38 -07006052
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006053 final long identity = Binder.clearCallingIdentity();
6054 try {
6055 String iccId = getIccId(subId);
6056 if (iccId != null) {
6057 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6058 if (DBG_MERGE) {
6059 log("getLine1NumberForDisplay returning "
6060 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6061 }
6062 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006063 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006064 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6065 return null;
6066 } finally {
6067 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006068 }
Derek Tan7226c842014-07-02 17:42:23 -07006069 }
6070
6071 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006072 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6073 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006074 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006075 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006076 return null;
6077 }
Derek Tan97ebb422014-09-05 16:55:38 -07006078
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006079 final long identity = Binder.clearCallingIdentity();
6080 try {
6081 String iccId = getIccId(subId);
6082 if (iccId != null) {
6083 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6084 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6085 }
6086 return null;
6087 } finally {
6088 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006089 }
Derek Tan7226c842014-07-02 17:42:23 -07006090 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006091
6092 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006093 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6094 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006095 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6096 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006097 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006098 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006099 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006100 return null;
6101 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006102
Jordan Liub49b04b2019-05-06 14:45:15 -07006103 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6104 // the process, where TelephonyManager was instantiated.
6105 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006106 final long identity = Binder.clearCallingIdentity();
6107 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006108 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006109 final TelephonyManager tele = TelephonyManager.from(context);
6110 final SubscriptionManager sub = SubscriptionManager.from(context);
6111
6112 // Figure out what subscribers are currently active
6113 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006114
Jordan Liub49b04b2019-05-06 14:45:15 -07006115 // Only consider subs which match the current subId
6116 // This logic can be simplified. See b/131189269 for progress.
6117 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006118 activeSubscriberIds.add(tele.getSubscriberId(subId));
6119 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006120
6121 // First pass, find a number override for an active subscriber
6122 String mergeNumber = null;
6123 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6124 for (String key : prefs.keySet()) {
6125 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6126 final String subscriberId = (String) prefs.get(key);
6127 if (activeSubscriberIds.contains(subscriberId)) {
6128 final String iccId = key.substring(
6129 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6130 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6131 mergeNumber = (String) prefs.get(numberKey);
6132 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006133 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006134 + " for active subscriber " + subscriberId);
6135 }
6136 if (!TextUtils.isEmpty(mergeNumber)) {
6137 break;
6138 }
6139 }
6140 }
6141 }
6142
6143 // Shortcut when no active merged subscribers
6144 if (TextUtils.isEmpty(mergeNumber)) {
6145 return null;
6146 }
6147
6148 // Second pass, find all subscribers under that line override
6149 final ArraySet<String> result = new ArraySet<>();
6150 for (String key : prefs.keySet()) {
6151 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6152 final String number = (String) prefs.get(key);
6153 if (mergeNumber.equals(number)) {
6154 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6155 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6156 final String subscriberId = (String) prefs.get(subscriberKey);
6157 if (!TextUtils.isEmpty(subscriberId)) {
6158 result.add(subscriberId);
6159 }
6160 }
6161 }
6162 }
6163
6164 final String[] resultArray = result.toArray(new String[result.size()]);
6165 Arrays.sort(resultArray);
6166 if (DBG_MERGE) {
Amit Mahajanb8f13202020-01-27 18:16:07 -08006167 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6169 }
6170 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006171 } finally {
6172 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006173 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006174 }
6175
6176 @Override
zoey chen38003472019-12-13 17:16:31 +08006177 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6178 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006179
6180 final long identity = Binder.clearCallingIdentity();
6181 try {
6182 final TelephonyManager telephonyManager = mApp.getSystemService(
6183 TelephonyManager.class);
6184 String subscriberId = telephonyManager.getSubscriberId(subId);
6185 if (subscriberId == null) {
6186 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006187 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006188 + subId);
6189 }
6190 return null;
6191 }
6192
6193 final SubscriptionInfo info = SubscriptionController.getInstance()
6194 .getSubscriptionInfo(subId);
6195 final ParcelUuid groupUuid = info.getGroupUuid();
6196 // If it doesn't belong to any group, return just subscriberId of itself.
6197 if (groupUuid == null) {
6198 return new String[]{subscriberId};
6199 }
6200
6201 // Get all subscriberIds from the group.
6202 final List<String> mergedSubscriberIds = new ArrayList<>();
6203 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006204 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006205 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006206 for (SubscriptionInfo subInfo : groupInfos) {
6207 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6208 if (subscriberId != null) {
6209 mergedSubscriberIds.add(subscriberId);
6210 }
6211 }
6212
6213 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6214 } finally {
6215 Binder.restoreCallingIdentity(identity);
6216
6217 }
6218 }
6219
6220 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006221 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006222 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006223 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006224
6225 final long identity = Binder.clearCallingIdentity();
6226 try {
6227 final Phone phone = getPhone(subId);
6228 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6229 } finally {
6230 Binder.restoreCallingIdentity(identity);
6231 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006232 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006233
6234 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006235 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006236 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6237 List<String> cdmaNonRoamingList) {
Shuo Qian2c0ae432019-12-05 11:40:37 -08006238 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6239 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006240
6241 final long identity = Binder.clearCallingIdentity();
6242 try {
6243 final Phone phone = getPhone(subId);
6244 if (phone == null) {
6245 return false;
6246 }
6247 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6248 cdmaNonRoamingList);
6249 } finally {
6250 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006251 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006252 }
6253
6254 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006255 @Deprecated
6256 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6257 enforceModifyPermission();
6258
6259 int returnValue = 0;
6260 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006261 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006262 if(result.exception == null) {
6263 if (result.result != null) {
6264 byte[] responseData = (byte[])(result.result);
6265 if(responseData.length > oemResp.length) {
6266 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6267 responseData.length + "bytes. Buffer Size is " +
6268 oemResp.length + "bytes.");
6269 }
6270 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6271 returnValue = responseData.length;
6272 }
6273 } else {
6274 CommandException ex = (CommandException) result.exception;
6275 returnValue = ex.getCommandError().ordinal();
6276 if(returnValue > 0) returnValue *= -1;
6277 }
6278 } catch (RuntimeException e) {
6279 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6280 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6281 if(returnValue > 0) returnValue *= -1;
6282 }
6283
6284 return returnValue;
6285 }
6286
6287 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006288 public void setRadioCapability(RadioAccessFamily[] rafs) {
6289 try {
6290 ProxyController.getInstance().setRadioCapability(rafs);
6291 } catch (RuntimeException e) {
6292 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6293 }
6294 }
6295
6296 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006297 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006298 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006299 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006300 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006301 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006302 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006303 final long identity = Binder.clearCallingIdentity();
6304 try {
chen xub97461a2018-10-26 14:17:57 -07006305 TelephonyPermissions
6306 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6307 mApp, phone.getSubId(), "getRadioAccessFamily");
6308 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006309 } finally {
6310 Binder.restoreCallingIdentity(identity);
6311 }
chen xub97461a2018-10-26 14:17:57 -07006312 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006313 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006314
6315 @Override
6316 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006317 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006318 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006319
6320 final long identity = Binder.clearCallingIdentity();
6321 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006322 ImsManager.getInstance(defaultPhone.getContext(),
6323 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006324 } finally {
6325 Binder.restoreCallingIdentity(identity);
6326 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006327 }
6328
6329 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006330 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006331 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006332 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6333 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006334 return false;
6335 }
Svet Ganovb320e182015-04-16 12:30:10 -07006336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006337 final long identity = Binder.clearCallingIdentity();
6338 try {
6339 // Check the user preference and the system-level IMS setting. Even if the user has
6340 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6341 // In the long run, we may instead need to check if there exists a connection service
6342 // which can support video calling.
6343 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006344 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006345 return imsManager.isVtEnabledByPlatform()
6346 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6347 && imsManager.isVtEnabledByUser();
6348 } finally {
6349 Binder.restoreCallingIdentity(identity);
6350 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006351 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006352
Andrew Leea1239f22015-03-02 17:44:07 -08006353 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006354 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6355 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006356 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006357 mApp, subId, callingPackage, callingFeatureId,
6358 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006359 return false;
6360 }
6361
6362 final long identity = Binder.clearCallingIdentity();
6363 try {
6364 CarrierConfigManager configManager =
6365 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006366 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006367 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6368 } finally {
6369 Binder.restoreCallingIdentity(identity);
6370 }
Andrew Leea1239f22015-03-02 17:44:07 -08006371 }
6372
6373 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006374 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006375 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006376 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006377 return false;
6378 }
6379
6380 final long identity = Binder.clearCallingIdentity();
6381 try {
6382 CarrierConfigManager configManager =
6383 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006384 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006385 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6386 } finally {
6387 Binder.restoreCallingIdentity(identity);
6388 }
Andrew Leea1239f22015-03-02 17:44:07 -08006389 }
6390
Andrew Lee9431b832015-03-09 18:46:45 -07006391 @Override
6392 public boolean isTtyModeSupported() {
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006393 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006394 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006395 }
6396
6397 @Override
6398 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 final long identity = Binder.clearCallingIdentity();
6400 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006401 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Andrew Lee9431b832015-03-09 18:46:45 -07006405 }
6406
Hall Liuf6668912018-10-31 17:05:23 -07006407 /**
6408 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6409 * support for the feature and device firmware support.
6410 *
6411 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6412 */
6413 @Override
6414 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006415 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006416 final Phone phone = getPhone(subscriptionId);
6417 if (phone == null) {
6418 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6419 return false;
6420 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006422 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006423 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6424 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006425 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006426 return isCarrierSupported && isDeviceSupported;
6427 } finally {
6428 Binder.restoreCallingIdentity(identity);
6429 }
Hall Liu98187582018-01-22 19:15:32 -08006430 }
6431
Hall Liuf6668912018-10-31 17:05:23 -07006432 /**
Hall Liuf2daa022019-07-23 18:39:00 -07006433 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6434 * RTT setting, will return true if the device and carrier both support RTT.
6435 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006436 */
6437 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006438 final long identity = Binder.clearCallingIdentity();
6439 try {
Hall Liu5bab75c2019-12-11 23:58:20 +00006440 boolean isRttSupported = isRttSupported(subscriptionId);
6441 boolean isUserRttSettingOn = Settings.Secure.getInt(
6442 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6443 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6444 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6445 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006446 } finally {
6447 Binder.restoreCallingIdentity(identity);
6448 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006449 }
6450
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006451 @Deprecated
6452 @Override
6453 public String getDeviceId(String callingPackage) {
6454 return getDeviceIdWithFeature(callingPackage, null);
6455 }
6456
Sanket Padawe7310cc72015-01-14 09:53:20 -08006457 /**
6458 * Returns the unique device ID of phone, for example, the IMEI for
6459 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6460 *
6461 * <p>Requires Permission:
6462 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6463 */
6464 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006465 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006466 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006467 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006468 return null;
6469 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006470 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006471 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006472 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006473 return null;
6474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475
6476 final long identity = Binder.clearCallingIdentity();
6477 try {
6478 return phone.getDeviceId();
6479 } finally {
6480 Binder.restoreCallingIdentity(identity);
6481 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006482 }
6483
Ping Sunc67b7c22016-03-02 19:16:45 +08006484 /**
6485 * {@hide}
6486 * Returns the IMS Registration Status on a particular subid
6487 *
6488 * @param subId
6489 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006490 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006491 Phone phone = getPhone(subId);
6492 if (phone != null) {
6493 return phone.isImsRegistered();
6494 } else {
6495 return false;
6496 }
6497 }
6498
Santos Cordon7a1885b2015-02-03 11:15:19 -08006499 @Override
6500 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006501 final long identity = Binder.clearCallingIdentity();
6502 try {
6503 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6504 } finally {
6505 Binder.restoreCallingIdentity(identity);
6506 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006507 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006508
Tyler Gunnf70ed162019-04-03 15:28:53 -07006509 @Override
Shuo Qian6e6137d2019-10-30 16:33:31 -07006510 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006511 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006512 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006513 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian6e6137d2019-10-30 16:33:31 -07006514 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6515 }
6516 final long identity = Binder.clearCallingIdentity();
6517 try {
6518 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6519 } finally {
6520 Binder.restoreCallingIdentity(identity);
6521 }
6522 }
6523
6524 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006525 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
6526 final long identity = Binder.clearCallingIdentity();
6527 try {
6528 Phone phone = getPhone(subscriptionId);
6529 if (phone == null) {
6530 return null;
6531 }
6532 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
6536 }
6537
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006538 /**
6539 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006540 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006541 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006542 final long identity = Binder.clearCallingIdentity();
6543 try {
6544 Phone phone = getPhone(subId);
6545 if (phone != null) {
6546 return phone.isWifiCallingEnabled();
6547 } else {
6548 return false;
6549 }
6550 } finally {
6551 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006552 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006553 }
6554
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006555 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006556 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006557 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006558 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006559 final long identity = Binder.clearCallingIdentity();
6560 try {
6561 Phone phone = getPhone(subId);
6562 if (phone != null) {
6563 return phone.isVideoEnabled();
6564 } else {
6565 return false;
6566 }
6567 } finally {
6568 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006569 }
6570 }
6571
6572 /**
6573 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6574 * defined in {@link ImsRegistrationImplBase}.
6575 */
6576 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006577 final long identity = Binder.clearCallingIdentity();
6578 try {
6579 Phone phone = getPhone(subId);
6580 if (phone != null) {
6581 return phone.getImsRegistrationTech();
6582 } else {
6583 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6584 }
6585 } finally {
6586 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006587 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006588 }
6589
Stuart Scott8eef64f2015-04-08 15:13:54 -07006590 @Override
6591 public void factoryReset(int subId) {
paulhu5a773602019-08-23 19:17:33 +08006592 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006593 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6594 return;
6595 }
6596
Svet Ganovcc087f82015-05-12 20:35:54 -07006597 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006598
Svet Ganovcc087f82015-05-12 20:35:54 -07006599 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006600 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6601 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00006602 setDataEnabledWithReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER,
6603 getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006604 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006605 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006606 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6607 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006608 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006609 // There has been issues when Sms raw table somehow stores orphan
6610 // fragments. They lead to garbled message when new fragments come
6611 // in and combined with those stale ones. In case this happens again,
6612 // user can reset all network settings which will clean up this table.
6613 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebingerbc7dd582019-10-17 17:03:22 -07006614 // Clean up IMS settings as well here.
6615 int slotId = getSlotIndex(subId);
6616 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6617 ImsManager.getInstance(mApp, slotId).factoryReset();
6618 }
Naina Nallurid63128d2019-09-17 14:10:30 -07006619
6620 // Erase modem config if erase modem on network setting is enabled.
6621 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6622 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6623 if (configValue != null && Boolean.parseBoolean(configValue)) {
6624 sendEraseModemConfig(getDefaultPhone());
6625 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006626 } finally {
6627 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006628 }
6629 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006630
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006631 private void cleanUpSmsRawTable(Context context) {
6632 ContentResolver resolver = context.getContentResolver();
6633 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6634 resolver.delete(uri, null, null);
6635 }
6636
Narayan Kamath1c496c22015-04-16 14:40:19 +01006637 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006638 public String getSimLocaleForSubscriber(int subId) {
6639 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6640 final Phone phone = getPhone(subId);
6641 if (phone == null) {
6642 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006643 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006644 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006645 final long identity = Binder.clearCallingIdentity();
6646 try {
chen xu5d3637b2019-01-21 23:31:38 -08006647 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006648 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006649 if (info == null) {
6650 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6651 return null;
6652 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006653 // Try and fetch the locale from the carrier properties or from the SIM language
6654 // preferences (EF-PL and EF-LI)...
6655 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006656 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006657 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6658 if (localeFromDefaultSim != null) {
6659 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6660 if (DBG) log("Using locale from subId: " + subId + " locale: "
6661 + localeFromDefaultSim);
6662 return localeFromDefaultSim.toLanguageTag();
6663 } else {
6664 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006665 }
6666 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006667
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006668 // The SIM language preferences only store a language (e.g. fr = French), not an
6669 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6670 // the SIM and carrier preferences does not include a country we add the country
6671 // determined from the SIM MCC to provide an exact locale.
zoey chenc730df82019-12-18 17:07:20 +08006672 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006673 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006674 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006675 return mccLocale.toLanguageTag();
6676 }
6677
6678 if (DBG) log("No locale found - returning null");
6679 return null;
6680 } finally {
6681 Binder.restoreCallingIdentity(identity);
6682 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006683 }
6684
6685 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006686 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006687 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006688 }
6689
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006690 /**
6691 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6692 */
6693 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006694 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann8d34f0c2020-03-05 16:24:02 -08006695 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006696 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006697
Chenjie Yu1ba97252018-01-11 18:16:20 -08006698 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xud78231e2019-09-10 18:49:52 -07006699 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006700
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006701 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006702 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6703 * representing the state of the modem.
6704 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006705 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6706 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006707 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006708 */
6709 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006710 public void requestModemActivityInfo(ResultReceiver result) {
6711 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006712 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006713
6714 final long identity = Binder.clearCallingIdentity();
6715 try {
Shuo Qian8f4750a2020-02-20 17:12:10 -08006716 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006717 } finally {
6718 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006719 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006720 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006721
Siddharth Rayb8114062018-06-17 15:02:38 -07006722 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6723 // less than total activity duration.
6724 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6725 if (info == null) {
6726 return false;
6727 }
6728 int activityDurationMs =
6729 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6730 int totalTxTimeMs = 0;
Chen Xud78231e2019-09-10 18:49:52 -07006731 int[] txTimeMs = info.getTransmitTimeMillis();
6732 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6733 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006734 }
6735 return (info.isValid()
6736 && (info.getSleepTimeMillis() <= activityDurationMs)
6737 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xud78231e2019-09-10 18:49:52 -07006738 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006739 && (totalTxTimeMs <= activityDurationMs));
6740 }
6741
Jack Yu85bd38a2015-11-09 11:34:32 -08006742 /**
6743 * {@hide}
6744 * Returns the service state information on specified subscription.
6745 */
6746 @Override
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006747 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6748 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006749 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07006750 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006751 return null;
6752 }
6753
Hall Liuf19c44f2018-11-27 14:38:17 -08006754 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6755 LocationAccessPolicy.checkLocationPermission(mApp,
6756 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6757 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006758 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006759 .setCallingPid(Binder.getCallingPid())
6760 .setCallingUid(Binder.getCallingUid())
6761 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006762 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006763 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006764 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6765 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006766 .build());
6767
6768 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6769 LocationAccessPolicy.checkLocationPermission(mApp,
6770 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6771 .setCallingPackage(callingPackage)
Philip P. Moltmann3a2772a2019-10-04 08:15:00 -07006772 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006773 .setCallingPid(Binder.getCallingPid())
6774 .setCallingUid(Binder.getCallingUid())
6775 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006776 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006777 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
Hall Liuc4a3e422020-05-26 17:18:03 -07006778 .setMinSdkVersionForFine(Integer.MAX_VALUE)
6779 .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q)
Hall Liuf19c44f2018-11-27 14:38:17 -08006780 .build());
6781 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6782 boolean hasFinePermission =
6783 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6784 boolean hasCoarsePermission =
6785 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6786
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006787 final long identity = Binder.clearCallingIdentity();
6788 try {
6789 final Phone phone = getPhone(subId);
6790 if (phone == null) {
6791 return null;
6792 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006793
Hall Liuf19c44f2018-11-27 14:38:17 -08006794 ServiceState ss = phone.getServiceState();
6795
6796 // Scrub out the location info in ServiceState depending on what level of access
6797 // the caller has.
6798 if (hasFinePermission) return ss;
Malcolm Chen5052de62019-12-30 13:56:38 -08006799 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6800 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006801 } finally {
6802 Binder.restoreCallingIdentity(identity);
6803 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006804 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006805
6806 /**
6807 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6808 *
6809 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6810 * voicemail ringtone.
6811 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6812 * PhoneAccount.
6813 */
6814 @Override
6815 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006816 final long identity = Binder.clearCallingIdentity();
6817 try {
6818 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6819 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006820 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006821 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006822
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006823 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6824 } finally {
6825 Binder.restoreCallingIdentity(identity);
6826 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006827 }
6828
6829 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006830 * Sets the per-account voicemail ringtone.
6831 *
6832 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6833 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6834 *
6835 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6836 * voicemail ringtone.
6837 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6838 * PhoneAccount.
6839 */
6840 @Override
6841 public void setVoicemailRingtoneUri(String callingPackage,
6842 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006843 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006844 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006845 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6846 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006847 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6848 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6849 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006850 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006851
6852 final long identity = Binder.clearCallingIdentity();
6853 try {
6854 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6855 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006856 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006857 }
6858 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6859 } finally {
6860 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006861 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006862 }
6863
6864 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006865 * Returns whether vibration is set for voicemail notification in Phone settings.
6866 *
6867 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6868 * voicemail vibration setting.
6869 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6870 */
6871 @Override
6872 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006873 final long identity = Binder.clearCallingIdentity();
6874 try {
6875 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6876 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006877 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006878 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006879
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006880 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6881 } finally {
6882 Binder.restoreCallingIdentity(identity);
6883 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006884 }
6885
Youhan Wange64578a2016-05-02 15:32:42 -07006886 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006887 * Sets the per-account voicemail vibration.
6888 *
6889 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6890 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6891 *
6892 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6893 * voicemail vibration setting.
6894 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6895 * specific PhoneAccount.
6896 */
6897 @Override
6898 public void setVoicemailVibrationEnabled(String callingPackage,
6899 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006900 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006901 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn5ddfdc92019-10-31 13:08:23 -07006902 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6903 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006904 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6905 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6906 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006907 }
6908
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006909 final long identity = Binder.clearCallingIdentity();
6910 try {
6911 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6912 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006913 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006914 }
6915 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6916 } finally {
6917 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006918 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006919 }
6920
6921 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006922 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6923 *
6924 * @throws SecurityException if the caller does not have the required permission
6925 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006926 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006927 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006928 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006929 }
6930
6931 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006932 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6933 * permission.
6934 *
6935 * @throws SecurityException if the caller does not have the required permission
6936 */
6937 private void enforceSendSmsPermission() {
6938 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6939 }
6940
6941 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006942 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006943 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006944 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006945 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006946 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006947 final long identity = Binder.clearCallingIdentity();
6948 try {
6949 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006950 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006951 if (componentName == null) {
6952 throw new SecurityException(
6953 "Caller not current active visual voicemail package[null]");
6954 }
6955 String vvmPackage = componentName.getPackageName();
6956 if (!callingPackage.equals(vvmPackage)) {
6957 throw new SecurityException("Caller not current active visual voicemail package["
6958 + vvmPackage + "]");
6959 }
6960 } finally {
6961 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006962 }
6963 }
6964
6965 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006966 * Return the application ID for the app type.
6967 *
6968 * @param subId the subscription ID that this request applies to.
6969 * @param appType the uicc app type.
6970 * @return Application ID for specificied app type, or null if no uicc.
6971 */
6972 @Override
6973 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07006974 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07006975 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006976
6977 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07006978 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006979 if (phone == null) {
6980 return null;
6981 }
6982 String aid = null;
6983 try {
6984 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
6985 .getApplicationByType(appType).getAid();
6986 } catch (Exception e) {
6987 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
6988 }
6989 return aid;
6990 } finally {
6991 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07006992 }
Youhan Wange64578a2016-05-02 15:32:42 -07006993 }
6994
Youhan Wang4001d252016-05-11 10:29:41 -07006995 /**
6996 * Return the Electronic Serial Number.
6997 *
6998 * @param subId the subscription ID that this request applies to.
6999 * @return ESN or null if error.
7000 */
7001 @Override
7002 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007003 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007004 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007005
7006 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007007 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007008 if (phone == null) {
7009 return null;
7010 }
7011 String esn = null;
7012 try {
7013 esn = phone.getEsn();
7014 } catch (Exception e) {
7015 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7016 }
7017 return esn;
7018 } finally {
7019 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007020 }
Youhan Wang4001d252016-05-11 10:29:41 -07007021 }
7022
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007023 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007024 * Return the Preferred Roaming List Version.
7025 *
7026 * @param subId the subscription ID that this request applies to.
7027 * @return PRLVersion or null if error.
7028 */
7029 @Override
7030 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007031 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007032 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007033
7034 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007035 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007036 if (phone == null) {
7037 return null;
7038 }
7039 String cdmaPrlVersion = null;
7040 try {
7041 cdmaPrlVersion = phone.getCdmaPrlVersion();
7042 } catch (Exception e) {
7043 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7044 }
7045 return cdmaPrlVersion;
7046 } finally {
7047 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007048 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007049 }
7050
7051 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007052 * Get snapshot of Telephony histograms
7053 * @return List of Telephony histograms
7054 * @hide
7055 */
7056 @Override
7057 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007058 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7059 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007060
7061 final long identity = Binder.clearCallingIdentity();
7062 try {
7063 return RIL.getTelephonyRILTimingHistograms();
7064 } finally {
7065 Binder.restoreCallingIdentity(identity);
7066 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007067 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007068
7069 /**
7070 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007071 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7072 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007073 * Require system privileges. In the future we may add this to carrier APIs.
7074 *
Michele Berionne482f8202018-11-27 18:57:59 -08007075 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007076 */
7077 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007078 @TelephonyManager.SetCarrierRestrictionResult
7079 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007080 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007081 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007082
Michele Berionne482f8202018-11-27 18:57:59 -08007083 if (carrierRestrictionRules == null) {
7084 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007085 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007086
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 final long identity = Binder.clearCallingIdentity();
7088 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007089 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007090 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007091 } finally {
7092 Binder.restoreCallingIdentity(identity);
7093 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007094 }
7095
7096 /**
7097 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007098 * Get the allowed carrier list and the excluded carrier list, including the priority between
7099 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007100 * Require system privileges. In the future we may add this to carrier APIs.
7101 *
Michele Berionne482f8202018-11-27 18:57:59 -08007102 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007103 */
7104 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007105 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007106 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007107 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007108
7109 final long identity = Binder.clearCallingIdentity();
7110 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007111 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7112 if (response instanceof CarrierRestrictionRules) {
7113 return (CarrierRestrictionRules) response;
7114 }
7115 // Response is an Exception of some kind,
7116 // which is signalled to the user as a NULL retval
7117 return null;
7118 } catch (Exception e) {
7119 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7120 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007121 } finally {
7122 Binder.restoreCallingIdentity(identity);
7123 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007124 }
7125
fionaxu59545b42016-05-25 15:53:37 -07007126 /**
fionaxu59545b42016-05-25 15:53:37 -07007127 * Action set from carrier signalling broadcast receivers to enable/disable radio
7128 * @param subId the subscription ID that this action applies to.
7129 * @param enabled control enable or disable radio.
7130 * {@hide}
7131 */
7132 @Override
7133 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7134 enforceModifyPermission();
7135 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007136
7137 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007138 if (phone == null) {
7139 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7140 return;
7141 }
7142 try {
7143 phone.carrierActionSetRadioEnabled(enabled);
7144 } catch (Exception e) {
7145 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007146 } finally {
7147 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007148 }
7149 }
7150
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007151 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007152 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7153 * network status based on which carrier apps could apply actions accordingly,
7154 * enable/disable default url handler for example.
7155 *
7156 * @param subId the subscription ID that this action applies to.
7157 * @param report control start/stop reporting the default network status.
7158 * {@hide}
7159 */
7160 @Override
7161 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7162 enforceModifyPermission();
7163 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007164
7165 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007166 if (phone == null) {
7167 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7168 return;
7169 }
7170 try {
7171 phone.carrierActionReportDefaultNetworkStatus(report);
7172 } catch (Exception e) {
7173 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007174 } finally {
7175 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007176 }
7177 }
7178
7179 /**
fionaxud9622282017-07-17 17:51:30 -07007180 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7181 * @param subId the subscription ID that this action applies to.
7182 * {@hide}
7183 */
7184 @Override
7185 public void carrierActionResetAll(int subId) {
7186 enforceModifyPermission();
7187 final Phone phone = getPhone(subId);
7188 if (phone == null) {
7189 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7190 return;
7191 }
7192 try {
7193 phone.carrierActionResetAll();
7194 } catch (Exception e) {
7195 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7196 }
7197 }
7198
7199 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007200 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7201 * bug report is being generated.
7202 */
7203 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007204 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007205 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7206 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007207 writer.println("Permission Denial: can't dump Phone from pid="
7208 + Binder.getCallingPid()
7209 + ", uid=" + Binder.getCallingUid()
7210 + "without permission "
7211 + android.Manifest.permission.DUMP);
7212 return;
7213 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007214 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007215 }
Jack Yueb89b242016-06-22 13:27:47 -07007216
Brad Ebingerdac2f002018-04-03 15:17:52 -07007217 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007218 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7219 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7220 @NonNull String[] args) {
7221 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7222 this, in.getFileDescriptor(), out.getFileDescriptor(),
7223 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007224 }
7225
Jack Yueb89b242016-06-22 13:27:47 -07007226 /**
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007227 * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason}
Greg Kaiser17f41752020-05-05 16:47:47 +00007228 * @param subId Subscription index
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007229 * @param reason the reason the data enable change is taking place
7230 * @param enabled True if enabling the data, otherwise disabling.
7231 * @hide
Jack Yu75ab2952016-07-08 14:29:33 -07007232 */
7233 @Override
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007234 public void setDataEnabledWithReason(int subId, @TelephonyManager.DataEnabledReason int reason,
7235 boolean enabled) {
7236 if (reason == TelephonyManager.DATA_ENABLED_REASON_USER
7237 || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7238 try {
7239 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
7240 mApp, subId, "setDataEnabledWithReason");
7241 } catch (SecurityException se) {
7242 enforceModifyPermission();
7243 }
7244 } else {
7245 enforceModifyPermission();
7246 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007247
7248 final long identity = Binder.clearCallingIdentity();
7249 try {
7250 Phone phone = getPhone(subId);
7251 if (phone != null) {
Sooraj Sasindranaf1b5132020-05-05 21:06:20 +00007252 if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) {
7253 phone.carrierActionSetMeteredApnsEnabled(enabled);
7254 } else {
7255 phone.getDataEnabledSettings().setDataEnabled(reason, enabled);
7256 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007257 }
7258 } finally {
7259 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007260 }
7261 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007262
7263 /**
7264 * Get Client request stats
7265 * @return List of Client Request Stats
7266 * @hide
7267 */
7268 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007269 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7270 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007271 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007272 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007273 return null;
7274 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007275 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007276
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007277 final long identity = Binder.clearCallingIdentity();
7278 try {
7279 if (phone != null) {
7280 return phone.getClientRequestStats();
7281 }
7282
7283 return null;
7284 } finally {
7285 Binder.restoreCallingIdentity(identity);
7286 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007287 }
7288
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007289 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007291 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007292 }
Jack Yueb4124c2017-02-16 15:32:43 -08007293
7294 /**
Grace Chen70990072017-03-24 17:21:30 -07007295 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007296 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007297 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007298 * @param state State of SIM (power down, power up, pass through)
7299 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7300 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7301 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007302 *
7303 **/
7304 @Override
Grace Chen70990072017-03-24 17:21:30 -07007305 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007306 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007307 Phone phone = PhoneFactory.getPhone(slotIndex);
7308
vagdeviaf9a5b92018-08-15 16:01:53 -07007309 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7310
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311 final long identity = Binder.clearCallingIdentity();
7312 try {
7313 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007314 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007315 }
7316 } finally {
7317 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007318 }
7319 }
Shuo Qiandd210312017-04-12 22:11:33 +00007320
Tyler Gunn65d45c22017-06-05 11:22:26 -07007321 private boolean isUssdApiAllowed(int subId) {
7322 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007323 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007324 if (configManager == null) {
7325 return false;
7326 }
7327 PersistableBundle pb = configManager.getConfigForSubId(subId);
7328 if (pb == null) {
7329 return false;
7330 }
7331 return pb.getBoolean(
7332 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7333 }
7334
Shuo Qiandd210312017-04-12 22:11:33 +00007335 /**
7336 * Check if phone is in emergency callback mode
7337 * @return true if phone is in emergency callback mode
7338 * @param subId sub id
7339 */
goneil9c5f4872017-12-05 14:07:56 -08007340 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007341 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007342 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007343 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007344
7345 final long identity = Binder.clearCallingIdentity();
7346 try {
7347 if (phone != null) {
7348 return phone.isInEcm();
7349 } else {
7350 return false;
7351 }
7352 } finally {
7353 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007354 }
7355 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007356
7357 /**
7358 * Get the current signal strength information for the given subscription.
7359 * Because this information is not updated when the device is in a low power state
7360 * it should not be relied-upon to be current.
7361 * @param subId Subscription index
7362 * @return the most recent cached signal strength info from the modem
7363 */
7364 @Override
7365 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007366 final long identity = Binder.clearCallingIdentity();
7367 try {
7368 Phone p = getPhone(subId);
7369 if (p == null) {
7370 return null;
7371 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007372
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007373 return p.getSignalStrength();
7374 } finally {
7375 Binder.restoreCallingIdentity(identity);
7376 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007377 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007378
Pengquan Meng77b7f132018-08-22 14:49:57 -07007379 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007380 * Get the current modem radio state for the given slot.
7381 * @param slotIndex slot index.
7382 * @param callingPackage the name of the package making the call.
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007383 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007384 * @return the current radio power state from the modem
7385 */
7386 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007387 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007388 Phone phone = PhoneFactory.getPhone(slotIndex);
7389 if (phone != null) {
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007390 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7391 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007392 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7393 }
7394
7395 final long identity = Binder.clearCallingIdentity();
7396 try {
7397 return phone.getRadioPowerState();
7398 } finally {
7399 Binder.restoreCallingIdentity(identity);
7400 }
7401 }
7402 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7403 }
7404
7405 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007406 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7407 *
7408 * <p>Requires one of the following permissions:
7409 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7410 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7411 * privileges.
7412 *
7413 * @param subId subscription id
7414 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7415 * {@code false}.
7416 */
7417 @Override
7418 public boolean isDataRoamingEnabled(int subId) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007419 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7420 null /* message */);
7421
Pengquan Menga1bb6272018-09-06 09:59:22 -07007422 boolean isEnabled = false;
7423 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007424 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007425 Phone phone = getPhone(subId);
7426 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007427 } catch (Exception e) {
7428 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7429 mApp, subId, "isDataRoamingEnabled");
Pengquan Menga1bb6272018-09-06 09:59:22 -07007430 } finally {
7431 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007432 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007433 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007434 }
7435
7436
7437 /**
7438 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7439 *
7440 * <p> Requires permission:
7441 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7442 * privileges.
7443 *
7444 * @param subId subscription id
7445 * @param isEnabled {@code true} means enable, {@code false} means disable.
7446 */
7447 @Override
7448 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007449 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7450 mApp, subId, "setDataRoamingEnabled");
7451
Pengquan Menga1bb6272018-09-06 09:59:22 -07007452 final long identity = Binder.clearCallingIdentity();
7453 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007454 Phone phone = getPhone(subId);
7455 if (phone != null) {
7456 phone.setDataRoamingEnabled(isEnabled);
7457 }
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007460 }
7461 }
7462
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007463 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007464 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007465 TelephonyPermissions
7466 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007467 mApp, subId, "isManualNetworkSelectionAllowed");
7468
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007469 boolean isAllowed = true;
7470 final long identity = Binder.clearCallingIdentity();
7471 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007472 Phone phone = getPhone(subId);
7473 if (phone != null) {
7474 isAllowed = phone.isCspPlmnEnabled();
7475 }
7476 } finally {
7477 Binder.restoreCallingIdentity(identity);
7478 }
7479 return isAllowed;
7480 }
7481
7482 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007483 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liu4cda4552020-03-23 11:55:07 -07007484 // Verify that tha callingPackage belongs to the calling UID
7485 mApp.getSystemService(AppOpsManager.class)
7486 .checkPackage(Binder.getCallingUid(), callingPackage);
7487
Jordan Liu1e142fc2019-04-22 15:10:43 -07007488 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007489 try {
7490 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007491 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007492 } catch (SecurityException e) {
7493 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7494 // has carrier privileges on an active UICC
7495 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7496 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007497 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007498 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007499 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007500
7501 final long identity = Binder.clearCallingIdentity();
7502 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007503 UiccController uiccController = UiccController.getInstance();
7504 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007505 if (hasReadPermission) {
7506 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007507 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007508
7509 // Remove private info if the caller doesn't have access
7510 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7511 for (UiccCardInfo cardInfo : cardInfos) {
7512 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7513 // is available
7514 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7515 if (card == null || card.getUiccProfile() == null) {
7516 // assume no access if the card or profile is unavailable
7517 filteredInfos.add(cardInfo.getUnprivileged());
7518 continue;
7519 }
7520 UiccProfile profile = card.getUiccProfile();
7521 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7522 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7523 filteredInfos.add(cardInfo);
7524 } else {
7525 filteredInfos.add(cardInfo.getUnprivileged());
7526 }
7527 }
7528 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007529 } finally {
7530 Binder.restoreCallingIdentity(identity);
7531 }
7532 }
7533
7534 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007535 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007536 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007537
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007538 final long identity = Binder.clearCallingIdentity();
7539 try {
7540 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7541 if (slots == null) {
7542 Rlog.i(LOG_TAG, "slots is null.");
7543 return null;
7544 }
7545
7546 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7547 for (int i = 0; i < slots.length; i++) {
7548 UiccSlot slot = slots[i];
7549 if (slot == null) {
7550 continue;
7551 }
7552
Jordan Liu7be7e652019-05-06 18:55:02 +00007553 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007554 UiccCard card = slot.getUiccCard();
7555 if (card != null) {
7556 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007557 } else {
Jordan Liu01bd00d2019-09-12 16:19:43 -07007558 cardId = slot.getEid();
7559 if (TextUtils.isEmpty(cardId)) {
7560 cardId = slot.getIccId();
7561 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007562 }
7563
Jordan Liu857451f2019-05-09 16:35:35 -07007564 if (cardId != null) {
7565 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7566 // if cardId is an EID, it's all digits so this is fine
7567 cardId = IccUtils.stripTrailingFs(cardId);
7568 }
7569
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007570 int cardState = 0;
7571 switch (slot.getCardState()) {
7572 case CARDSTATE_ABSENT:
7573 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7574 break;
7575 case CARDSTATE_PRESENT:
7576 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7577 break;
7578 case CARDSTATE_ERROR:
7579 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7580 break;
7581 case CARDSTATE_RESTRICTED:
7582 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7583 break;
7584 default:
7585 break;
7586
7587 }
7588
7589 infos[i] = new UiccSlotInfo(
7590 slot.isActive(),
7591 slot.isEuicc(),
7592 cardId,
7593 cardState,
7594 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007595 slot.isExtendedApduSupported(),
7596 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007597 }
7598 return infos;
7599 } finally {
7600 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007601 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007602 }
7603
7604 @Override
7605 public boolean switchSlots(int[] physicalSlots) {
7606 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007607
7608 final long identity = Binder.clearCallingIdentity();
7609 try {
7610 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7611 } finally {
7612 Binder.restoreCallingIdentity(identity);
7613 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007614 }
Jack Yu4c988042018-02-27 15:30:01 -08007615
7616 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007617 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007618 final long identity = Binder.clearCallingIdentity();
7619 try {
7620 return UiccController.getInstance().getCardIdForDefaultEuicc();
7621 } finally {
7622 Binder.restoreCallingIdentity(identity);
7623 }
7624 }
7625
Pengquan Meng85728fb2018-03-12 16:31:21 -07007626 /**
goneil47ffb6e2018-04-06 15:40:58 -07007627 * A test API to reload the UICC profile.
7628 *
7629 * <p>Requires that the calling app has permission
7630 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7631 * @hide
7632 */
7633 @Override
7634 public void refreshUiccProfile(int subId) {
7635 enforceModifyPermission();
7636
7637 final long identity = Binder.clearCallingIdentity();
7638 try {
7639 Phone phone = getPhone(subId);
7640 if (phone == null) {
7641 return;
7642 }
7643 UiccCard uiccCard = phone.getUiccCard();
7644 if (uiccCard == null) {
7645 return;
7646 }
7647 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7648 if (uiccProfile == null) {
7649 return;
7650 }
7651 uiccProfile.refresh();
7652 } finally {
7653 Binder.restoreCallingIdentity(identity);
7654 }
7655 }
7656
7657 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007658 * Returns false if the mobile data is disabled by default, otherwise return true.
7659 */
7660 private boolean getDefaultDataEnabled() {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007661 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007662 }
7663
7664 /**
7665 * Returns true if the data roaming is enabled by default, i.e the system property
7666 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7667 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7668 */
7669 private boolean getDefaultDataRoamingEnabled(int subId) {
7670 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007671 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Inseob Kim14bb3d02018-12-13 17:11:34 +09007672 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007673 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7674 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7675 return isDataRoamingEnabled;
7676 }
7677
7678 /**
7679 * Returns the default network type for the given {@code subId}, if the default network type is
7680 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7681 */
7682 private int getDefaultNetworkType(int subId) {
Inseob Kim14bb3d02018-12-13 17:11:34 +09007683 List<Integer> list = TelephonyProperties.default_network();
7684 int phoneId = mSubscriptionController.getPhoneId(subId);
7685 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7686 return list.get(phoneId);
7687 }
7688 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007689 }
fionaxua13278b2018-03-21 00:08:13 -07007690
7691 @Override
7692 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007693 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007694 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007695
7696 final long identity = Binder.clearCallingIdentity();
7697 try {
7698 final Phone phone = getPhone(subId);
7699 if (phone == null) {
7700 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7701 return;
7702 }
chen xueaba88a2019-03-15 13:15:10 -07007703 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7704 carrierPrivilegeRules, apn);
Jeff Davidson8ab02b22020-03-28 12:24:40 -07007705 if (carrierPrivilegeRules == null) {
7706 mCarrierPrivilegeTestOverrideSubIds.remove(subId);
7707 } else {
7708 mCarrierPrivilegeTestOverrideSubIds.add(subId);
7709 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007710 } finally {
7711 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007712 }
fionaxua13278b2018-03-21 00:08:13 -07007713 }
7714
7715 @Override
7716 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007717 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007718
7719 final long identity = Binder.clearCallingIdentity();
7720 try {
7721 final Phone phone = getPhone(subId);
7722 if (phone == null) {
7723 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7724 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7725 }
7726 return phone.getCarrierIdListVersion();
7727 } finally {
7728 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007729 }
fionaxua13278b2018-03-21 00:08:13 -07007730 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007731
7732 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007733 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7734 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007735 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007736 mApp, subId, callingPackage, callingFeatureId,
7737 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007738 return -1;
7739 }
7740
7741 final long identity = Binder.clearCallingIdentity();
7742 try {
7743 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7744 } finally {
7745 Binder.restoreCallingIdentity(identity);
7746 }
7747 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007748
7749 @Override
7750 public int getCdmaRoamingMode(int subId) {
zoey chen7e6d4e52019-12-17 18:18:59 +08007751 TelephonyPermissions
7752 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007753 mApp, subId, "getCdmaRoamingMode");
7754
7755 final long identity = Binder.clearCallingIdentity();
7756 try {
7757 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7758 } finally {
7759 Binder.restoreCallingIdentity(identity);
7760 }
7761 }
7762
7763 @Override
7764 public boolean setCdmaRoamingMode(int subId, int mode) {
7765 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7766 mApp, subId, "setCdmaRoamingMode");
7767
7768 final long identity = Binder.clearCallingIdentity();
7769 try {
7770 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7771 } finally {
7772 Binder.restoreCallingIdentity(identity);
7773 }
7774 }
7775
7776 @Override
7777 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7778 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7779 mApp, subId, "setCdmaSubscriptionMode");
7780
7781 final long identity = Binder.clearCallingIdentity();
7782 try {
7783 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
7786 }
7787 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007788
sqianc5eccab2018-10-19 18:46:41 -07007789 @Override
sqian8c685422019-02-22 15:55:18 -08007790 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007791 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007793 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7794 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007795 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7796 }
7797 final long identity = Binder.clearCallingIdentity();
7798 try {
sqian854d44b2018-12-12 16:48:18 -08007799 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7800 for (Phone phone: PhoneFactory.getPhones()) {
7801 if (phone.getEmergencyNumberTracker() != null
7802 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7803 emergencyNumberListInternal.put(
7804 phone.getSubId(),
7805 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7806 }
sqian11b7a0e2018-12-05 18:48:28 -08007807 }
sqian854d44b2018-12-12 16:48:18 -08007808 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007809 } finally {
7810 Binder.restoreCallingIdentity(identity);
7811 }
sqianc5eccab2018-10-19 18:46:41 -07007812 }
7813
7814 @Override
sqian8c685422019-02-22 15:55:18 -08007815 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007816 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007817 if (!exactMatch) {
7818 TelephonyPermissions
7819 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007820 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007821 }
7822 final long identity = Binder.clearCallingIdentity();
7823 try {
sqian854d44b2018-12-12 16:48:18 -08007824 for (Phone phone: PhoneFactory.getPhones()) {
7825 if (phone.getEmergencyNumberTracker() != null
7826 && phone.getEmergencyNumberTracker() != null) {
7827 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7828 number, exactMatch)) {
7829 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007830 }
7831 }
sqian11b7a0e2018-12-05 18:48:28 -08007832 }
7833 return false;
7834 } finally {
7835 Binder.restoreCallingIdentity(identity);
7836 }
7837 }
7838
sqianf4ca7ed2019-01-15 18:32:07 -08007839 /**
7840 * Update emergency number list for test mode.
7841 */
7842 @Override
7843 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7844 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7845 "updateEmergencyNumberListTestMode");
7846
7847 final long identity = Binder.clearCallingIdentity();
7848 try {
7849 for (Phone phone: PhoneFactory.getPhones()) {
7850 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7851 if (tracker != null) {
7852 tracker.executeEmergencyNumberTestModeCommand(action, num);
7853 }
7854 }
7855 } finally {
7856 Binder.restoreCallingIdentity(identity);
7857 }
7858 }
7859
7860 /**
7861 * Get the full emergency number list for test mode.
7862 */
7863 @Override
7864 public List<String> getEmergencyNumberListTestMode() {
7865 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7866 "getEmergencyNumberListTestMode");
7867
7868 final long identity = Binder.clearCallingIdentity();
7869 try {
7870 Set<String> emergencyNumbers = new HashSet<>();
7871 for (Phone phone: PhoneFactory.getPhones()) {
7872 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7873 if (tracker != null) {
7874 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7875 emergencyNumbers.add(num.getNumber());
7876 }
7877 }
7878 }
7879 return new ArrayList<>(emergencyNumbers);
7880 } finally {
7881 Binder.restoreCallingIdentity(identity);
7882 }
7883 }
7884
chen xud6b45bd2018-10-30 22:27:10 -07007885 @Override
Shuo Qian3b6ee772019-11-13 17:43:31 -08007886 public int getEmergencyNumberDbVersion(int subId) {
7887 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7888
7889 final long identity = Binder.clearCallingIdentity();
7890 try {
7891 final Phone phone = getPhone(subId);
7892 if (phone == null) {
7893 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7894 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7895 }
7896 return phone.getEmergencyNumberDbVersion();
7897 } finally {
7898 Binder.restoreCallingIdentity(identity);
7899 }
7900 }
7901
7902 @Override
7903 public void notifyOtaEmergencyNumberDbInstalled() {
7904 enforceModifyPermission();
7905
7906 final long identity = Binder.clearCallingIdentity();
7907 try {
7908 for (Phone phone: PhoneFactory.getPhones()) {
7909 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7910 if (tracker != null) {
7911 tracker.updateOtaEmergencyNumberDatabase();
7912 }
7913 }
7914 } finally {
7915 Binder.restoreCallingIdentity(identity);
7916 }
7917 }
7918
7919 @Override
Shuo Qianc373f112020-03-05 17:55:34 -08007920 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qian3b6ee772019-11-13 17:43:31 -08007921 enforceActiveEmergencySessionPermission();
7922
7923 final long identity = Binder.clearCallingIdentity();
7924 try {
7925 for (Phone phone: PhoneFactory.getPhones()) {
7926 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7927 if (tracker != null) {
Shuo Qianc373f112020-03-05 17:55:34 -08007928 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7929 }
7930 }
7931 } finally {
7932 Binder.restoreCallingIdentity(identity);
7933 }
7934 }
7935
7936 @Override
7937 public void resetOtaEmergencyNumberDbFilePath() {
7938 enforceActiveEmergencySessionPermission();
7939
7940 final long identity = Binder.clearCallingIdentity();
7941 try {
7942 for (Phone phone: PhoneFactory.getPhones()) {
7943 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7944 if (tracker != null) {
7945 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qian3b6ee772019-11-13 17:43:31 -08007946 }
7947 }
7948 } finally {
7949 Binder.restoreCallingIdentity(identity);
7950 }
7951 }
7952
7953 @Override
chen xud6b45bd2018-10-30 22:27:10 -07007954 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
7955 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
7956 Phone phone = getPhone(subId);
7957 if (phone == null) {
7958 return null;
7959 }
7960 final long identity = Binder.clearCallingIdentity();
7961 try {
7962 UiccProfile profile = UiccController.getInstance()
7963 .getUiccProfileForPhone(phone.getPhoneId());
7964 if (profile != null) {
7965 return profile.getCertsFromCarrierPrivilegeAccessRules();
7966 }
7967 } finally {
7968 Binder.restoreCallingIdentity(identity);
7969 }
7970 return null;
7971 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08007972
7973 /**
7974 * Enable or disable a modem stack.
7975 */
7976 @Override
7977 public boolean enableModemForSlot(int slotIndex, boolean enable) {
7978 enforceModifyPermission();
7979
7980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 Phone phone = PhoneFactory.getPhone(slotIndex);
7983 if (phone == null) {
7984 return false;
7985 } else {
7986 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
7987 }
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
7990 }
7991 }
Michelecea4cf22018-12-21 15:00:11 -08007992
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007993 /**
7994 * Whether a modem stack is enabled or not.
7995 */
7996 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07007997 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
7998 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07007999 Phone phone = PhoneFactory.getPhone(slotIndex);
8000 if (phone == null) return false;
8001
8002 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008003 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8004 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008005 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8006 }
8007
8008 final long identity = Binder.clearCallingIdentity();
8009 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008010 try {
8011 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8012 } catch (NoSuchElementException ex) {
8013 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8014 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008015 } finally {
8016 Binder.restoreCallingIdentity(identity);
8017 }
8018 }
8019
Michelecea4cf22018-12-21 15:00:11 -08008020 @Override
Michele0ea7d782019-03-19 14:58:42 -07008021 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008022 enforceModifyPermission();
8023
8024 final long identity = Binder.clearCallingIdentity();
8025 try {
8026 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008027 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008028 .commit();
8029 } finally {
8030 Binder.restoreCallingIdentity(identity);
8031 }
8032 }
8033
8034 @Override
Michele0ea7d782019-03-19 14:58:42 -07008035 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008036 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008037 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008038 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8039 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008040 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008041 }
Michelecea4cf22018-12-21 15:00:11 -08008042
8043 final long identity = Binder.clearCallingIdentity();
8044 try {
Michele0ea7d782019-03-19 14:58:42 -07008045 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008046 } finally {
8047 Binder.restoreCallingIdentity(identity);
8048 }
8049 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008050
Michele0ea7d782019-03-19 14:58:42 -07008051 @TelephonyManager.IsMultiSimSupportedResult
8052 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008053 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8054 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8055 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008056 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8057 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008058 }
8059 // Check if the hardware supports multisim functionality. If usage of multisim is not
8060 // supported by the modem, indicate that it is restricted.
8061 PhoneCapability staticCapability =
8062 mPhoneConfigurationManager.getStaticPhoneCapability();
8063 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008064 loge("isMultiSimSupportedInternal: no static configuration available");
8065 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008066 }
Sarah Chin7caee492020-02-18 20:49:02 +00008067 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008068 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8069 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008070 }
8071 // Check if support of multiple SIMs is restricted by carrier
8072 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008073 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008074 }
8075
Michele0ea7d782019-03-19 14:58:42 -07008076 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008077 }
8078
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008079 /**
8080 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008081 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8082 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8083 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008084 * @param numOfSims number of active sims we want to switch to
8085 */
8086 @Override
8087 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008088 if (numOfSims == 1) {
8089 enforceModifyPermission();
8090 } else {
8091 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8092 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8093 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008094 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008095
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008096 try {
Michele30b57b22019-03-01 12:01:14 -08008097 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008098 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008099 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8100 return;
8101 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008102 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8103 } finally {
8104 Binder.restoreCallingIdentity(identity);
8105 }
8106 }
8107
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008108 @Override
8109 public boolean isApplicationOnUicc(int subId, int appType) {
8110 enforceReadPrivilegedPermission("isApplicationOnUicc");
8111 Phone phone = getPhone(subId);
8112 if (phone == null) {
8113 return false;
8114 }
8115 final long identity = Binder.clearCallingIdentity();
8116 try {
8117 UiccCard uiccCard = phone.getUiccCard();
8118 if (uiccCard == null) {
8119 return false;
8120 }
8121 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8122 if (uiccProfile == null) {
8123 return false;
8124 }
8125 if (TelephonyManager.APPTYPE_SIM <= appType
8126 && appType <= TelephonyManager.APPTYPE_ISIM) {
8127 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8128 }
8129 return false;
8130 } finally {
8131 Binder.restoreCallingIdentity(identity);
8132 }
8133 }
8134
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008135 /**
chen xub4baa772019-04-03 10:23:41 -07008136 * Get whether making changes to modem configurations will trigger reboot.
8137 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008138 */
8139 @Override
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008140 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8141 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008142 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann700a9592019-10-03 11:53:50 -07008143 mApp, subId, callingPackage, callingFeatureId,
8144 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008145 return false;
8146 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008147 final long identity = Binder.clearCallingIdentity();
8148 try {
8149 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8150 } finally {
8151 Binder.restoreCallingIdentity(identity);
8152 }
8153 }
8154
Nathan Harold29f5f052019-02-15 13:41:57 -08008155 private void updateModemStateMetrics() {
8156 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8157 // TODO: check the state for each modem if the api is ready.
8158 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8159 }
8160
Pengquan Meng3889a572019-01-23 11:16:29 -08008161 @Override
8162 public int[] getSlotsMapping() {
8163 enforceReadPrivilegedPermission("getSlotsMapping");
8164
8165 final long identity = Binder.clearCallingIdentity();
8166 try {
8167 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8168 // All logical slots should have a mapping to a physical slot.
8169 int[] logicalSlotsMapping = new int[phoneCount];
8170 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8171 for (int i = 0; i < slotInfos.length; i++) {
8172 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8173 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8174 }
8175 }
8176 return logicalSlotsMapping;
8177 } finally {
8178 Binder.restoreCallingIdentity(identity);
8179 }
8180 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008181
8182 /**
8183 * Get the IRadio HAL Version
8184 */
8185 @Override
8186 public int getRadioHalVersion() {
8187 Phone phone = getDefaultPhone();
8188 if (phone == null) return -1;
8189 HalVersion hv = phone.getHalVersion();
8190 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8191 return hv.major * 100 + hv.minor;
8192 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008193
8194 /**
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008195 * Get the current calling package name.
8196 * @return the current calling package name
8197 */
8198 @Override
8199 public String getCurrentPackageName() {
8200 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8201 }
8202
8203 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008204 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8205 * corresponding network requests on a subId.
8206 *
8207 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008208 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008209 * 2) APN is un-metered for this subscription, or
8210 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbettyd5c246e2019-12-24 15:40:37 +08008211 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008212 *
8213 * @return whether data is allowed for a apn type.
8214 *
8215 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008216 */
8217 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008218 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajan5d4e1922019-10-07 16:20:43 -07008219 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8220 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008221
8222 // Now that all security checks passes, perform the operation as ourselves.
8223 final long identity = Binder.clearCallingIdentity();
8224 try {
8225 Phone phone = getPhone(subId);
8226 if (phone == null) return false;
8227
Jack Yu41407ee2019-05-13 16:54:09 -07008228 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008229 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8230 } finally {
8231 Binder.restoreCallingIdentity(identity);
8232 }
8233 }
8234
8235 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008236 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008237 enforceReadPrivilegedPermission("isApnMetered");
8238
8239 // Now that all security checks passes, perform the operation as ourselves.
8240 final long identity = Binder.clearCallingIdentity();
8241 try {
8242 Phone phone = getPhone(subId);
8243 if (phone == null) return true; // By default return true.
8244
Jack Yu41407ee2019-05-13 16:54:09 -07008245 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008246 } finally {
8247 Binder.restoreCallingIdentity(identity);
8248 }
8249 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008250
8251 @Override
Hall Liu73f5d362020-01-20 13:42:00 -08008252 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8253 int subscriptionId, IBooleanConsumer resultCallback) {
8254 enforceModifyPermission();
8255 long token = Binder.clearCallingIdentity();
8256 try {
8257 Phone phone = getPhone(subscriptionId);
8258 if (phone == null) {
8259 try {
8260 if (resultCallback != null) {
8261 resultCallback.accept(false);
8262 }
8263 } catch (RemoteException e) {
8264 // ignore
8265 }
8266 return;
8267 }
8268 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8269 Pair.create(specifiers, (x) -> {
8270 try {
8271 if (resultCallback != null) {
8272 resultCallback.accept(x);
8273 }
8274 } catch (RemoteException e) {
8275 // ignore
8276 }
8277 });
8278 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8279 } finally {
8280 Binder.restoreCallingIdentity(token);
8281 }
8282 }
8283
8284 @Override
changbetty7157e9e2019-12-06 18:16:37 +08008285 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008286 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty7157e9e2019-12-06 18:16:37 +08008287 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8288 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8289 if (iccRecords == null) {
8290 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8291 return false;
8292 }
8293 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8294 }
8295
8296 @Override
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008297 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8298 IIntegerConsumer pendingSubIdResult) {
Shuo Qianda2d6ec2020-01-14 15:18:28 -08008299 if (callingPackage == null) {
8300 callingPackage = getCurrentPackageName();
8301 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008302 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8303 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmannd02b7372020-03-18 17:06:12 -07008304 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8305 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008306 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8307 }
8308 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8309 Intent intent = new Intent();
8310 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8311 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8312 // Bring up choose default SMS subscription dialog right now
8313 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8314 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8315 mApp.startActivity(intent);
8316 }
chen xud5ca2d52019-05-28 15:20:57 -07008317
8318 @Override
8319 public String getMmsUAProfUrl(int subId) {
8320 //TODO investigate if this API should require proper permission check in R b/133791609
8321 final long identity = Binder.clearCallingIdentity();
8322 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008323 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8324 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
chen xud5ca2d52019-05-28 15:20:57 -07008325 } finally {
8326 Binder.restoreCallingIdentity(identity);
8327 }
8328 }
8329
8330 @Override
8331 public String getMmsUserAgent(int subId) {
8332 //TODO investigate if this API should require proper permission check in R b/133791609
8333 final long identity = Binder.clearCallingIdentity();
8334 try {
Daniel Brightebb4eb72020-02-18 15:16:33 -08008335 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8336 .getString(com.android.internal.R.string.config_mms_user_agent);
chen xud5ca2d52019-05-28 15:20:57 -07008337 } finally {
8338 Binder.restoreCallingIdentity(identity);
8339 }
8340 }
Jack Yub07d4972019-05-28 16:12:25 -07008341
8342 @Override
8343 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8344 enforceModifyPermission();
8345
8346 // Now that all security checks passes, perform the operation as ourselves.
8347 final long identity = Binder.clearCallingIdentity();
8348 try {
8349 Phone phone = getPhone(subId);
8350 if (phone == null) return false;
8351
8352 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8353 } finally {
8354 Binder.restoreCallingIdentity(identity);
8355 }
8356 }
8357
8358 @Override
8359 public boolean isDataAllowedInVoiceCall(int subId) {
8360 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8361
8362 // Now that all security checks passes, perform the operation as ourselves.
8363 final long identity = Binder.clearCallingIdentity();
8364 try {
8365 Phone phone = getPhone(subId);
8366 if (phone == null) return false;
8367
8368 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8369 } finally {
8370 Binder.restoreCallingIdentity(identity);
8371 }
8372 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008373
changbettyd5c246e2019-12-24 15:40:37 +08008374 @Override
8375 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8376 enforceModifyPermission();
8377
8378 // Now that all security checks passes, perform the operation as ourselves.
8379 final long identity = Binder.clearCallingIdentity();
8380 try {
8381 Phone phone = getPhone(subId);
8382 if (phone == null) return false;
8383
8384 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8385 } finally {
8386 Binder.restoreCallingIdentity(identity);
8387 }
8388 }
8389
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008390 /**
8391 * Updates whether conference event pacakge handling is enabled.
8392 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8393 * otherwise.
8394 */
8395 @Override
8396 public void setCepEnabled(boolean isCepEnabled) {
8397 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8398
8399 final long identity = Binder.clearCallingIdentity();
8400 try {
8401 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8402 for (Phone phone : PhoneFactory.getPhones()) {
8403 Phone defaultPhone = phone.getImsPhone();
8404 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8405 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8406 ImsPhoneCallTracker imsPhoneCallTracker =
8407 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8408 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8409 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8410 + imsPhone.getMsisdn());
8411 }
8412 }
8413 } finally {
8414 Binder.restoreCallingIdentity(identity);
8415 }
8416 }
allenwtsu46dcc572020-01-08 18:24:03 +08008417
8418 /**
8419 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8420 *
8421 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8422 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8423 * before being read.
8424 */
8425 @Override
8426 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8427 isCompressed) {
8428 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8429 mApp, subId, "notifyRcsAutoConfigurationReceived");
8430 try {
8431 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8432 if (configBinder == null) {
8433 Rlog.e(LOG_TAG, "null result for getImsConfig");
8434 } else {
8435 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8436 }
8437 } catch (RemoteException e) {
8438 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8439 }
8440 }
zoey chene02881a2019-12-30 16:11:23 +08008441
8442 @Override
8443 public boolean isIccLockEnabled(int subId) {
8444 enforceReadPrivilegedPermission("isIccLockEnabled");
8445
8446 // Now that all security checks passes, perform the operation as ourselves.
8447 final long identity = Binder.clearCallingIdentity();
8448 try {
8449 Phone phone = getPhone(subId);
8450 if (phone != null && phone.getIccCard() != null) {
8451 return phone.getIccCard().getIccLockEnabled();
8452 } else {
8453 return false;
8454 }
8455 } finally {
8456 Binder.restoreCallingIdentity(identity);
8457 }
8458 }
8459
8460 /**
8461 * Set the ICC pin lock enabled or disabled.
8462 *
8463 * @return an integer representing the status of IccLock enabled or disabled in the following
8464 * three cases:
8465 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8466 * successfully.
8467 * - Positive number and zero for remaining password attempts.
8468 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8469 *
8470 */
8471 @Override
8472 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8473 enforceModifyPermission();
8474
8475 Phone phone = getPhone(subId);
8476 if (phone == null) {
8477 return 0;
8478 }
8479 // Now that all security checks passes, perform the operation as ourselves.
8480 final long identity = Binder.clearCallingIdentity();
8481 try {
8482 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8483 new Pair<Boolean, String>(enabled, password), phone, null);
8484 return attemptsRemaining;
8485
8486 } catch (Exception e) {
8487 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8488 } finally {
8489 Binder.restoreCallingIdentity(identity);
8490 }
8491 return 0;
8492 }
8493
8494 /**
8495 * Change the ICC password used in ICC pin lock.
8496 *
8497 * @return an integer representing the status of IccLock changed in the following three cases:
8498 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8499 * - Positive number and zero for remaining password attempts.
8500 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
8501 *
8502 */
8503 @Override
8504 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8505 enforceModifyPermission();
8506
8507 Phone phone = getPhone(subId);
8508 if (phone == null) {
8509 return 0;
8510 }
8511 // Now that all security checks passes, perform the operation as ourselves.
8512 final long identity = Binder.clearCallingIdentity();
8513 try {
8514 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8515 new Pair<String, String>(oldPassword, newPassword), phone, null);
8516 return attemptsRemaining;
8517
8518 } catch (Exception e) {
8519 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8520 } finally {
8521 Binder.restoreCallingIdentity(identity);
8522 }
8523 return 0;
8524 }
Peter Wangdafb9ac2020-01-15 14:13:38 -08008525
8526 /**
8527 * Request for receiving user activity notification
8528 */
8529 @Override
8530 public void requestUserActivityNotification() {
8531 if (!mNotifyUserActivity.get()
8532 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8533 mNotifyUserActivity.set(true);
8534 }
8535 }
8536
8537 /**
8538 * Called when userActivity is signalled in the power manager.
8539 * This is safe to call from any thread, with any window manager locks held or not.
8540 */
8541 @Override
8542 public void userActivity() {
8543 // ***************************************
8544 // * Inherited from PhoneWindowManager *
8545 // ***************************************
8546 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8547 // WITH ITS LOCKS HELD.
8548 //
8549 // This code must be VERY careful about the locks
8550 // it acquires.
8551 // In fact, the current code acquires way too many,
8552 // and probably has lurking deadlocks.
8553
8554 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8555 throw new SecurityException("Only the OS may call notifyUserActivity()");
8556 }
8557
8558 if (mNotifyUserActivity.getAndSet(false)) {
8559 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8560 USER_ACTIVITY_NOTIFICATION_DELAY);
8561 }
8562 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008563
8564 @Override
8565 public boolean canConnectTo5GInDsdsMode() {
8566 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008568}