blob: c22a8a4e992140e1ea5818acaac549fb19c45e40 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.phone;
18
Hall Liud892bec2018-11-30 14:51:45 -080019import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20
Tyler Gunn7bcdc742019-10-04 15:56:59 -070021import static com.android.internal.telephony.PhoneConstants.PHONE_TYPE_IMS;
Ta-wei Yen87c49842016-05-13 21:19:52 -070022import static com.android.internal.telephony.PhoneConstants.SUBSCRIPTION_KEY;
23
Ta-wei Yen30a69c82016-12-27 14:52:32 -080024import android.Manifest.permission;
changbetty363e8ac2019-12-06 18:16:37 +080025import android.annotation.NonNull;
Tyler Gunnf70ed162019-04-03 15:28:53 -070026import android.annotation.Nullable;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070027import android.app.AppOpsManager;
Ta-wei Yen30a69c82016-12-27 14:52:32 -080028import android.app.PendingIntent;
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -070029import android.content.ComponentName;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070030import android.content.ContentResolver;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070031import android.content.Context;
32import android.content.Intent;
Derek Tan97ebb422014-09-05 16:55:38 -070033import android.content.SharedPreferences;
Nathan Harold31d7ff32018-10-15 20:20:30 -070034import android.content.pm.ApplicationInfo;
Derek Tan740e1672017-06-27 14:56:27 -070035import android.content.pm.ComponentInfo;
Amith Yamasani6e118872016-02-19 12:53:51 -080036import android.content.pm.PackageInfo;
Shishir Agrawal60f9c952014-06-23 12:00:43 -070037import android.content.pm.PackageManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070038import android.net.Uri;
39import android.os.AsyncResult;
40import android.os.Binder;
Hall Liuf19c44f2018-11-27 14:38:17 -080041import android.os.Build;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070042import android.os.Bundle;
43import android.os.Handler;
yinxu504e1392017-04-12 16:03:22 -070044import android.os.IBinder;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045import android.os.Looper;
46import android.os.Message;
yinxu504e1392017-04-12 16:03:22 -070047import android.os.Messenger;
Shuo Qianb15c6be2020-03-05 17:55:34 -080048import android.os.ParcelFileDescriptor;
Malcolm Chen6ca97372019-07-01 16:28:21 -070049import android.os.ParcelUuid;
Tyler Gunn65d45c22017-06-05 11:22:26 -070050import android.os.PersistableBundle;
Shuo Qian5bac1ee2020-01-16 20:51:11 -080051import android.os.Process;
Brad Ebinger5f64b052017-12-14 14:26:15 -080052import android.os.RemoteException;
Adam Lesinski903a54c2016-04-11 14:49:52 -070053import android.os.ResultReceiver;
Brad Ebinger1ce9c432019-07-16 13:19:44 -070054import android.os.ServiceSpecificException;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055import android.os.UserHandle;
Stuart Scott981d8582015-04-21 14:09:50 -070056import android.os.UserManager;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070057import android.os.WorkSource;
Derek Tan97ebb422014-09-05 16:55:38 -070058import android.preference.PreferenceManager;
Naina Nalluri8ff344d2019-09-17 14:10:30 -070059import android.provider.DeviceConfig;
Ihab Awadf2177b72013-11-25 13:33:23 -080060import android.provider.Settings;
Amit Mahajan7dbbd822019-03-13 17:33:47 -070061import android.provider.Telephony;
Inseob Kim8d298d42018-12-13 17:11:34 +090062import android.sysprop.TelephonyProperties;
Santos Cordon7a1885b2015-02-03 11:15:19 -080063import android.telecom.PhoneAccount;
Nancy Chen31f9ba12016-01-06 11:42:12 -080064import android.telecom.PhoneAccountHandle;
Andrew Lee9431b832015-03-09 18:46:45 -070065import android.telecom.TelecomManager;
Chen Xuc7b18ec2019-09-26 22:48:11 -070066import android.telephony.Annotation.ApnType;
sqian80370722020-01-29 15:02:51 -080067import android.telephony.CallForwardingInfo;
Junda Liu12f7d802015-05-01 12:06:44 -070068import android.telephony.CarrierConfigManager;
Michele Berionne482f8202018-11-27 18:57:59 -080069import android.telephony.CarrierRestrictionRules;
yincheng zhaod698b842019-09-06 17:06:54 -070070import android.telephony.CellIdentity;
Meng Wangd64acad2019-12-09 13:13:01 -080071import android.telephony.CellIdentityCdma;
72import android.telephony.CellIdentityGsm;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070073import android.telephony.CellInfo;
Nathan Haroldf180aac2018-06-01 18:43:55 -070074import android.telephony.CellInfoGsm;
75import android.telephony.CellInfoWcdma;
Sooraj Sasindran9a909312016-07-18 11:57:25 -070076import android.telephony.ClientRequestStats;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -070077import android.telephony.ICellInfoCallback;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -070078import android.telephony.IccOpenLogicalChannelResponse;
Hall Liu1aa510f2017-11-22 17:40:08 -080079import android.telephony.LocationAccessPolicy;
Ta-wei Yen87c49842016-05-13 21:19:52 -070080import android.telephony.ModemActivityInfo;
Jake Hambye994d462014-02-03 13:10:13 -080081import android.telephony.NeighboringCellInfo;
yinxu504e1392017-04-12 16:03:22 -070082import android.telephony.NetworkScanRequest;
Michele4245e952019-02-04 11:36:23 -080083import android.telephony.PhoneCapability;
Hall Liud892bec2018-11-30 14:51:45 -080084import android.telephony.PhoneNumberRange;
Wink Saville5d475dd2014-10-17 15:00:58 -070085import android.telephony.RadioAccessFamily;
Hall Liub2ac8ef2019-02-28 15:56:23 -080086import android.telephony.RadioAccessSpecifier;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070087import android.telephony.ServiceState;
Nathan Harold46b42aa2017-03-10 19:38:22 -080088import android.telephony.SignalStrength;
Wink Saville0f3b5fc2014-11-11 08:40:49 -080089import android.telephony.SubscriptionInfo;
Jeff Sharkey85190e62014-12-05 09:40:12 -080090import android.telephony.SubscriptionManager;
Peter Wangc035ce42020-01-08 21:00:22 -080091import android.telephony.TelephonyFrameworkInitializer;
Sanket Padawe99ef1e32016-05-18 16:12:33 -070092import android.telephony.TelephonyHistogram;
Ta-wei Yenb6929602016-05-24 15:48:27 -070093import android.telephony.TelephonyManager;
Hall Liub2ac8ef2019-02-28 15:56:23 -080094import android.telephony.TelephonyScanManager;
Jordan Liu5aa07002018-12-18 15:44:48 -080095import android.telephony.UiccCardInfo;
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +000096import android.telephony.UiccSlotInfo;
Tyler Gunn65d45c22017-06-05 11:22:26 -070097import android.telephony.UssdResponse;
Ta-wei Yenb6929602016-05-24 15:48:27 -070098import android.telephony.VisualVoicemailSmsFilterSettings;
Jack Yub5d8f642018-11-26 11:20:48 -080099import android.telephony.data.ApnSetting;
100import android.telephony.emergency.EmergencyNumber;
Brad Ebinger1ce9c432019-07-16 13:19:44 -0700101import android.telephony.ims.ImsException;
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800102import android.telephony.ims.ProvisioningManager;
Brad Ebinger774ba362019-10-22 17:36:18 -0700103import android.telephony.ims.RegistrationManager;
Brad Ebinger35c841c2018-10-01 10:40:55 -0700104import android.telephony.ims.aidl.IImsCapabilityCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800105import android.telephony.ims.aidl.IImsConfig;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -0700106import android.telephony.ims.aidl.IImsConfigCallback;
Brad Ebinger22bc3e42018-01-16 09:39:35 -0800107import android.telephony.ims.aidl.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 Ebinger77b832e2019-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 Liuaa4283b2020-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;
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -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 Liud0d1dc92020-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;
Taesu Leef8fbed92019-10-07 18:47:02 +0900163import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700164import com.android.internal.telephony.uicc.IccIoResult;
changbetty363e8ac2019-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 chen84e2b212019-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 Wang050bb052020-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 Liud0d1dc92020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 chenf95ca592019-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 Liud0d1dc92020-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;
sqian80370722020-01-29 15:02:51 -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 Ebinger05f52c22019-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
Derek Tan97ebb422014-09-05 16:55:38 -0700316 private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_";
317 private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_";
Jeff Sharkey85190e62014-12-05 09:40:12 -0800318 private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_";
Brad Ebinger1c8542e2019-01-14 13:43:14 -0800319 private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_";
Derek Tan89e89d42014-07-08 17:00:10 -0700320
Michelecea4cf22018-12-21 15:00:11 -0800321 // String to store multi SIM allowed
322 private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted";
323
Derek Tan740e1672017-06-27 14:56:27 -0700324 // The AID of ISD-R.
325 private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100";
326
yinxub1bed742017-04-17 11:45:04 -0700327 private NetworkScanRequestTracker mNetworkScanRequestTracker;
328
David Kelly5e06a7f2018-03-12 14:10:59 +0000329 private static final int TYPE_ALLOCATION_CODE_LENGTH = 8;
330 private static final int MANUFACTURER_CODE_LENGTH = 8;
331
Derek Tan89e89d42014-07-08 17:00:10 -0700332 /**
Naina Nalluri8ff344d2019-09-17 14:10:30 -0700333 * Experiment flag to enable erase modem config on reset network, default value is false
334 */
335 public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED =
336 "reset_network_erase_modem_config_enabled";
337
338 /**
Shishir Agrawal566b7612013-10-28 14:41:00 -0700339 * A request object to use for transmitting data to an ICC.
340 */
341 private static final class IccAPDUArgument {
342 public int channel, cla, command, p1, p2, p3;
343 public String data;
344
345 public IccAPDUArgument(int channel, int cla, int command,
346 int p1, int p2, int p3, String data) {
347 this.channel = channel;
348 this.cla = cla;
349 this.command = command;
350 this.p1 = p1;
351 this.p2 = p2;
352 this.p3 = p3;
353 this.data = data;
354 }
355 }
356
357 /**
Shishir Agrawal77ba3172015-09-10 14:50:19 -0700358 * A request object to use for transmitting data to an ICC.
359 */
360 private static final class ManualNetworkSelectionArgument {
361 public OperatorInfo operatorInfo;
362 public boolean persistSelection;
363
364 public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) {
365 this.operatorInfo = operatorInfo;
366 this.persistSelection = persistSelection;
367 }
368 }
369
370 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700371 * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the
372 * request after sending. The main thread will notify the request when it is complete.
373 */
374 private static final class MainThreadRequest {
375 /** The argument to use for the request */
376 public Object argument;
377 /** The result of the request that is run on the main thread */
378 public Object result;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800379 // The subscriber id that this request applies to. Defaults to
380 // SubscriptionManager.INVALID_SUBSCRIPTION_ID
381 public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700382
Nathan Harold92bed182018-10-12 18:16:49 -0700383 // In cases where subId is unavailable, the caller needs to specify the phone.
384 public Phone phone;
385
vagdeviaf9a5b92018-08-15 16:01:53 -0700386 public WorkSource workSource;
387
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700388 public MainThreadRequest(Object argument) {
389 this.argument = argument;
390 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800391
Nathan Harold92bed182018-10-12 18:16:49 -0700392 MainThreadRequest(Object argument, Phone phone, WorkSource workSource) {
393 this.argument = argument;
394 if (phone != null) {
395 this.phone = phone;
396 }
397 this.workSource = workSource;
398 }
399
vagdeviaf9a5b92018-08-15 16:01:53 -0700400 MainThreadRequest(Object argument, Integer subId, WorkSource workSource) {
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800401 this.argument = argument;
Sanket Padawe56e75a32016-02-08 12:18:19 -0800402 if (subId != null) {
403 this.subId = subId;
404 }
vagdeviaf9a5b92018-08-15 16:01:53 -0700405 this.workSource = workSource;
Shishir Agrawal76d5da92014-11-09 16:17:25 -0800406 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700407 }
408
Sailesh Nepalcc0375f2013-11-13 09:15:18 -0800409 private static final class IncomingThirdPartyCallArgs {
410 public final ComponentName component;
411 public final String callId;
412 public final String callerDisplayName;
413
414 public IncomingThirdPartyCallArgs(ComponentName component, String callId,
415 String callerDisplayName) {
416 this.component = component;
417 this.callId = callId;
418 this.callerDisplayName = callerDisplayName;
419 }
420 }
421
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700422 /**
423 * A handler that processes messages on the main thread in the phone process. Since many
424 * of the Phone calls are not thread safe this is needed to shuttle the requests from the
425 * inbound binder threads to the main thread in the phone process. The Binder thread
426 * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting
427 * on, which will be notified when the operation completes and will contain the result of the
428 * request.
429 *
430 * <p>If a MainThreadRequest object is provided in the msg.obj field,
431 * note that request.result must be set to something non-null for the calling thread to
432 * unblock.
433 */
434 private final class MainThreadHandler extends Handler {
435 @Override
436 public void handleMessage(Message msg) {
437 MainThreadRequest request;
438 Message onCompleted;
439 AsyncResult ar;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800440 UiccCard uiccCard;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700441 IccAPDUArgument iccArgument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800442 final Phone defaultPhone = getDefaultPhone();
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700443
444 switch (msg.what) {
Pengquan Menga1bb6272018-09-06 09:59:22 -0700445 case CMD_HANDLE_USSD_REQUEST: {
446 request = (MainThreadRequest) msg.obj;
447 final Phone phone = getPhoneFromRequest(request);
448 Pair<String, ResultReceiver> ussdObject = (Pair) request.argument;
449 String ussdRequest = ussdObject.first;
450 ResultReceiver wrappedCallback = ussdObject.second;
Tyler Gunn65d45c22017-06-05 11:22:26 -0700451
Pengquan Menga1bb6272018-09-06 09:59:22 -0700452 if (!isUssdApiAllowed(request.subId)) {
453 // Carrier does not support use of this API, return failure.
454 Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis.");
455 UssdResponse response = new UssdResponse(ussdRequest, null);
456 Bundle returnData = new Bundle();
457 returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response);
458 wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData);
Tyler Gunn65d45c22017-06-05 11:22:26 -0700459
Pengquan Menga1bb6272018-09-06 09:59:22 -0700460 request.result = true;
461 notifyRequester(request);
462 return;
463 }
Tyler Gunn65d45c22017-06-05 11:22:26 -0700464
Pengquan Menga1bb6272018-09-06 09:59:22 -0700465 try {
466 request.result = phone != null
467 ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false;
468 } catch (CallStateException cse) {
469 request.result = false;
470 }
471 // Wake up the requesting thread
472 notifyRequester(request);
473 break;
pkanwar32d516d2016-10-14 19:37:38 -0700474 }
475
Yorke Lee716f67e2015-06-17 15:39:16 -0700476 case CMD_HANDLE_PIN_MMI: {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700477 request = (MainThreadRequest) msg.obj;
Yorke Lee716f67e2015-06-17 15:39:16 -0700478 final Phone phone = getPhoneFromRequest(request);
479 request.result = phone != null ?
480 getPhoneFromRequest(request).handlePinMmi((String) request.argument)
481 : false;
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700482 // Wake up the requesting thread
Pengquan Menga1bb6272018-09-06 09:59:22 -0700483 notifyRequester(request);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700484 break;
Yorke Lee716f67e2015-06-17 15:39:16 -0700485 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700486
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700487 case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700488 request = (MainThreadRequest) msg.obj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700489 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800490 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700491 if (uiccCard == null) {
492 loge("iccTransmitApduLogicalChannel: No UICC");
493 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700494 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700495 } else {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700496 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE,
497 request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700498 uiccCard.iccTransmitApduLogicalChannel(
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700499 iccArgument.channel, iccArgument.cla, iccArgument.command,
500 iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data,
Shishir Agrawal566b7612013-10-28 14:41:00 -0700501 onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700502 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700503 break;
504
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700505 case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700506 ar = (AsyncResult) msg.obj;
507 request = (MainThreadRequest) ar.userObj;
508 if (ar.exception == null && ar.result != null) {
509 request.result = ar.result;
510 } else {
511 request.result = new IccIoResult(0x6F, 0, (byte[])null);
512 if (ar.result == null) {
513 loge("iccTransmitApduLogicalChannel: Empty response");
Jake Hambye994d462014-02-03 13:10:13 -0800514 } else if (ar.exception instanceof CommandException) {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700515 loge("iccTransmitApduLogicalChannel: CommandException: " +
Jake Hambye994d462014-02-03 13:10:13 -0800516 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700517 } else {
518 loge("iccTransmitApduLogicalChannel: Unknown exception");
519 }
520 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700521 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700522 break;
523
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700524 case CMD_TRANSMIT_APDU_BASIC_CHANNEL:
525 request = (MainThreadRequest) msg.obj;
526 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800527 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700528 if (uiccCard == null) {
529 loge("iccTransmitApduBasicChannel: No UICC");
530 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700531 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700532 } else {
533 onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE,
534 request);
535 uiccCard.iccTransmitApduBasicChannel(
536 iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2,
537 iccArgument.p3, iccArgument.data, onCompleted);
538 }
539 break;
540
541 case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE:
542 ar = (AsyncResult) msg.obj;
543 request = (MainThreadRequest) ar.userObj;
544 if (ar.exception == null && ar.result != null) {
545 request.result = ar.result;
546 } else {
547 request.result = new IccIoResult(0x6F, 0, (byte[])null);
548 if (ar.result == null) {
549 loge("iccTransmitApduBasicChannel: Empty response");
550 } else if (ar.exception instanceof CommandException) {
551 loge("iccTransmitApduBasicChannel: CommandException: " +
552 ar.exception);
553 } else {
554 loge("iccTransmitApduBasicChannel: Unknown exception");
555 }
556 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700557 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700558 break;
559
560 case CMD_EXCHANGE_SIM_IO:
561 request = (MainThreadRequest) msg.obj;
562 iccArgument = (IccAPDUArgument) request.argument;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800563 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700564 if (uiccCard == null) {
565 loge("iccExchangeSimIO: No UICC");
566 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700567 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700568 } else {
569 onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE,
570 request);
571 uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */
572 iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3,
573 iccArgument.data, onCompleted);
574 }
575 break;
576
577 case EVENT_EXCHANGE_SIM_IO_DONE:
578 ar = (AsyncResult) msg.obj;
579 request = (MainThreadRequest) ar.userObj;
580 if (ar.exception == null && ar.result != null) {
581 request.result = ar.result;
582 } else {
583 request.result = new IccIoResult(0x6f, 0, (byte[])null);
584 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700585 notifyRequester(request);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700586 break;
587
Derek Tan4d5e5c12014-02-04 11:54:58 -0800588 case CMD_SEND_ENVELOPE:
589 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800590 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700591 if (uiccCard == null) {
592 loge("sendEnvelopeWithStatus: No UICC");
593 request.result = new IccIoResult(0x6F, 0, (byte[])null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700594 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700595 } else {
596 onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request);
597 uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted);
598 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800599 break;
600
601 case EVENT_SEND_ENVELOPE_DONE:
602 ar = (AsyncResult) msg.obj;
603 request = (MainThreadRequest) ar.userObj;
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700604 if (ar.exception == null && ar.result != null) {
605 request.result = ar.result;
Derek Tan4d5e5c12014-02-04 11:54:58 -0800606 } else {
Shishir Agrawal9f9877d2014-03-14 09:36:27 -0700607 request.result = new IccIoResult(0x6F, 0, (byte[])null);
608 if (ar.result == null) {
609 loge("sendEnvelopeWithStatus: Empty response");
610 } else if (ar.exception instanceof CommandException) {
611 loge("sendEnvelopeWithStatus: CommandException: " +
612 ar.exception);
613 } else {
614 loge("sendEnvelopeWithStatus: exception:" + ar.exception);
615 }
Derek Tan4d5e5c12014-02-04 11:54:58 -0800616 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700617 notifyRequester(request);
Derek Tan4d5e5c12014-02-04 11:54:58 -0800618 break;
619
Shishir Agrawal566b7612013-10-28 14:41:00 -0700620 case CMD_OPEN_CHANNEL:
621 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800622 uiccCard = getUiccCardFromRequest(request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800623 Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument;
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700624 if (uiccCard == null) {
625 loge("iccOpenLogicalChannel: No UICC");
Shishir Agrawalfc0492a2016-02-17 11:15:33 -0800626 request.result = new IccOpenLogicalChannelResponse(-1,
627 IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null);
Pengquan Menga1bb6272018-09-06 09:59:22 -0700628 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700629 } else {
630 onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request);
Ajay Nambid7454d32015-12-03 13:50:00 -0800631 uiccCard.iccOpenLogicalChannel(openChannelArgs.first,
632 openChannelArgs.second, onCompleted);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700633 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700634 break;
635
636 case EVENT_OPEN_CHANNEL_DONE:
637 ar = (AsyncResult) msg.obj;
638 request = (MainThreadRequest) ar.userObj;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700639 IccOpenLogicalChannelResponse openChannelResp;
Shishir Agrawal566b7612013-10-28 14:41:00 -0700640 if (ar.exception == null && ar.result != null) {
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700641 int[] result = (int[]) ar.result;
642 int channelId = result[0];
643 byte[] selectResponse = null;
644 if (result.length > 1) {
645 selectResponse = new byte[result.length - 1];
646 for (int i = 1; i < result.length; ++i) {
647 selectResponse[i - 1] = (byte) result[i];
648 }
649 }
650 openChannelResp = new IccOpenLogicalChannelResponse(channelId,
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700651 IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700652 } else {
Shishir Agrawal566b7612013-10-28 14:41:00 -0700653 if (ar.result == null) {
654 loge("iccOpenLogicalChannel: Empty response");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700655 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700656 if (ar.exception != null) {
657 loge("iccOpenLogicalChannel: Exception: " + ar.exception);
658 }
659
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700660 int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR;
Junda Liua754ba12015-05-20 01:17:52 -0700661 if (ar.exception instanceof CommandException) {
662 CommandException.Error error =
663 ((CommandException) (ar.exception)).getCommandError();
664 if (error == CommandException.Error.MISSING_RESOURCE) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700665 errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE;
Junda Liua754ba12015-05-20 01:17:52 -0700666 } else if (error == CommandException.Error.NO_SUCH_ELEMENT) {
Shishir Agrawal527e8bf2014-08-25 08:54:56 -0700667 errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT;
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -0700668 }
669 }
670 openChannelResp = new IccOpenLogicalChannelResponse(
671 IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700672 }
Shishir Agrawal82c8a462014-07-31 18:13:17 -0700673 request.result = openChannelResp;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700674 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700675 break;
676
677 case CMD_CLOSE_CHANNEL:
678 request = (MainThreadRequest) msg.obj;
Shishir Agrawalc04d9752016-02-19 10:41:00 -0800679 uiccCard = getUiccCardFromRequest(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700680 if (uiccCard == null) {
681 loge("iccCloseLogicalChannel: No UICC");
Yoshiaki Naka2e29d822016-09-02 19:27:39 +0900682 request.result = false;
Pengquan Menga1bb6272018-09-06 09:59:22 -0700683 notifyRequester(request);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -0700684 } else {
685 onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request);
686 uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted);
687 }
Shishir Agrawal566b7612013-10-28 14:41:00 -0700688 break;
689
690 case EVENT_CLOSE_CHANNEL_DONE:
Jake Hambye994d462014-02-03 13:10:13 -0800691 handleNullReturnEvent(msg, "iccCloseLogicalChannel");
692 break;
693
694 case CMD_NV_READ_ITEM:
695 request = (MainThreadRequest) msg.obj;
696 onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800697 defaultPhone.nvReadItem((Integer) request.argument, onCompleted,
698 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800699 break;
700
701 case EVENT_NV_READ_ITEM_DONE:
Shishir Agrawal566b7612013-10-28 14:41:00 -0700702 ar = (AsyncResult) msg.obj;
703 request = (MainThreadRequest) ar.userObj;
Jake Hambye994d462014-02-03 13:10:13 -0800704 if (ar.exception == null && ar.result != null) {
705 request.result = ar.result; // String
Shishir Agrawal566b7612013-10-28 14:41:00 -0700706 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800707 request.result = "";
708 if (ar.result == null) {
709 loge("nvReadItem: Empty response");
710 } else if (ar.exception instanceof CommandException) {
711 loge("nvReadItem: CommandException: " +
712 ar.exception);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700713 } else {
Jake Hambye994d462014-02-03 13:10:13 -0800714 loge("nvReadItem: Unknown exception");
Shishir Agrawal566b7612013-10-28 14:41:00 -0700715 }
716 }
Pengquan Menga1bb6272018-09-06 09:59:22 -0700717 notifyRequester(request);
Shishir Agrawal566b7612013-10-28 14:41:00 -0700718 break;
719
Jake Hambye994d462014-02-03 13:10:13 -0800720 case CMD_NV_WRITE_ITEM:
721 request = (MainThreadRequest) msg.obj;
722 onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request);
723 Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument;
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800724 defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted,
vagdeviaf9a5b92018-08-15 16:01:53 -0700725 request.workSource);
Jake Hambye994d462014-02-03 13:10:13 -0800726 break;
727
728 case EVENT_NV_WRITE_ITEM_DONE:
729 handleNullReturnEvent(msg, "nvWriteItem");
730 break;
731
732 case CMD_NV_WRITE_CDMA_PRL:
733 request = (MainThreadRequest) msg.obj;
734 onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800735 defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800736 break;
737
738 case EVENT_NV_WRITE_CDMA_PRL_DONE:
739 handleNullReturnEvent(msg, "nvWriteCdmaPrl");
740 break;
741
chen xu6dac5ab2018-10-26 17:39:23 -0700742 case CMD_RESET_MODEM_CONFIG:
Jake Hambye994d462014-02-03 13:10:13 -0800743 request = (MainThreadRequest) msg.obj;
chen xu6dac5ab2018-10-26 17:39:23 -0700744 onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request);
Nazanin Bakhshif782e562018-12-11 15:15:39 -0800745 defaultPhone.resetModemConfig(onCompleted);
Jake Hambye994d462014-02-03 13:10:13 -0800746 break;
747
chen xu6dac5ab2018-10-26 17:39:23 -0700748 case EVENT_RESET_MODEM_CONFIG_DONE:
749 handleNullReturnEvent(msg, "resetModemConfig");
Jake Hambye994d462014-02-03 13:10:13 -0800750 break;
751
Jake Hamby7c27be32014-03-03 13:25:59 -0800752 case CMD_GET_PREFERRED_NETWORK_TYPE:
753 request = (MainThreadRequest) msg.obj;
754 onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request);
Stuart Scott54788802015-03-30 13:18:01 -0700755 getPhoneFromRequest(request).getPreferredNetworkType(onCompleted);
Jake Hamby7c27be32014-03-03 13:25:59 -0800756 break;
757
758 case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE:
759 ar = (AsyncResult) msg.obj;
760 request = (MainThreadRequest) ar.userObj;
761 if (ar.exception == null && ar.result != null) {
762 request.result = ar.result; // Integer
763 } else {
Nazish Tabassume8ba43a2020-07-28 14:49:25 +0530764 // request.result must be set to something non-null
765 // for the calling thread to unblock
766 request.result = new int[]{-1};
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
sqian80370722020-01-29 15:02:51 -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;
sqian80370722020-01-29 15:02:51 -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
sqian80370722020-01-29 15:02:51 -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);
sqian1a1be542020-03-05 11:37:28 -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;
sqian1a1be542020-03-05 11:37:28 -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) {
sqian1a1be542020-03-05 11:37:28 -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 }
sqian1a1be542020-03-05 11:37:28 -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 Wang6c08ecd2019-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 Wang6c08ecd2019-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 Wangd64acad2019-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 Wangd64acad2019-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 Liud0d1dc92020-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 zhaod698b842019-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 Nalluri8ff344d2019-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 zhaod698b842019-09-06 17:06:54 -07001452 break;
zoey chenf95ca592019-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 Ebinger05f52c22019-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 Nalluri8ff344d2019-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 Wang050bb052020-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
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001950 /**
1951 * This method has been removed due to privacy and stability concerns.
1952 */
1953 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001954 public void updateServiceLocation() {
Nathan Harold7c8d0f12020-05-28 20:40:31 -07001955 Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()");
1956 return;
Wink Saville36469e72014-06-11 15:17:00 -07001957 }
1958
Nathan Harold1f889d82020-06-04 17:05:26 -07001959 @Override
1960 public void updateServiceLocationWithPackageName(String callingPackage) {
1961 mApp.getSystemService(AppOpsManager.class)
1962 .checkPackage(Binder.getCallingUid(), callingPackage);
1963
1964 final int targetSdk = getTargetSdk(callingPackage);
1965 if (targetSdk > android.os.Build.VERSION_CODES.R) {
1966 // Callers targeting S have no business invoking this method.
1967 return;
1968 }
1969
1970 LocationAccessPolicy.LocationPermissionResult locationResult =
1971 LocationAccessPolicy.checkLocationPermission(mApp,
1972 new LocationAccessPolicy.LocationPermissionQuery.Builder()
1973 .setCallingPackage(callingPackage)
1974 .setCallingFeatureId(null)
1975 .setCallingPid(Binder.getCallingPid())
1976 .setCallingUid(Binder.getCallingUid())
1977 .setMethod("updateServiceLocation")
1978 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
1979 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
1980 .build());
1981 // Apps that lack location permission have no business calling this method;
1982 // however, because no permission was declared in the public API, denials must
1983 // all be "soft".
1984 switch (locationResult) {
1985 case DENIED_HARD: /* fall through */
1986 case DENIED_SOFT:
1987 return;
1988 }
1989
1990 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001991 final long identity = Binder.clearCallingIdentity();
1992 try {
Nathan Harold1f889d82020-06-04 17:05:26 -07001993 final Phone phone = getPhone(getDefaultSubscription());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001994 if (phone != null) {
Nathan Harold1f889d82020-06-04 17:05:26 -07001995 phone.updateServiceLocation(workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08001996 }
1997 } finally {
1998 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07001999 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002000 }
2001
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002002 @Deprecated
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002003 @Override
2004 public boolean isRadioOn(String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002005 return isRadioOnWithFeature(callingPackage, null);
Wink Saville36469e72014-06-11 15:17:00 -07002006 }
2007
Philip P. Moltmann700a9592019-10-03 11:53:50 -07002008
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002009 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002010 public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) {
2011 return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage,
2012 callingFeatureId);
2013 }
2014
2015 @Deprecated
2016 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002017 public boolean isRadioOnForSubscriber(int subId, String callingPackage) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002018 return isRadioOnForSubscriberWithFeature(subId, callingPackage, null);
2019 }
2020
2021 @Override
2022 public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage,
2023 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002024 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002025 mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002026 return false;
2027 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002028
2029 final long identity = Binder.clearCallingIdentity();
2030 try {
2031 return isRadioOnForSubscriber(subId);
2032 } finally {
2033 Binder.restoreCallingIdentity(identity);
2034 }
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002035 }
2036
2037 private boolean isRadioOnForSubscriber(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002038 final long identity = Binder.clearCallingIdentity();
2039 try {
2040 final Phone phone = getPhone(subId);
2041 if (phone != null) {
2042 return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF;
2043 } else {
2044 return false;
2045 }
2046 } finally {
2047 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002048 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002049 }
2050
2051 public void toggleRadioOnOff() {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002052 toggleRadioOnOffForSubscriber(getDefaultSubscription());
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002053 }
Wink Saville36469e72014-06-11 15:17:00 -07002054
Wink Savilleb564aae2014-10-23 10:18:09 -07002055 public void toggleRadioOnOffForSubscriber(int subId) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002056 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002057
2058 final long identity = Binder.clearCallingIdentity();
2059 try {
2060 final Phone phone = getPhone(subId);
2061 if (phone != null) {
2062 phone.setRadioPower(!isRadioOnForSubscriber(subId));
2063 }
2064 } finally {
2065 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002066 }
Wink Saville36469e72014-06-11 15:17:00 -07002067 }
2068
2069 public boolean setRadio(boolean turnOn) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002070 return setRadioForSubscriber(getDefaultSubscription(), turnOn);
Wink Saville36469e72014-06-11 15:17:00 -07002071 }
2072
Wink Savilleb564aae2014-10-23 10:18:09 -07002073 public boolean setRadioForSubscriber(int subId, boolean turnOn) {
Wink Saville36469e72014-06-11 15:17:00 -07002074 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002075
2076 final long identity = Binder.clearCallingIdentity();
2077 try {
2078 final Phone phone = getPhone(subId);
2079 if (phone == null) {
2080 return false;
2081 }
2082 if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) {
2083 toggleRadioOnOffForSubscriber(subId);
2084 }
2085 return true;
2086 } finally {
2087 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002088 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002089 }
Wink Saville36469e72014-06-11 15:17:00 -07002090
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002091 public boolean needMobileRadioShutdown() {
Shuo Qianafeaf7d2019-12-10 10:40:38 -08002092 enforceReadPrivilegedPermission("needMobileRadioShutdown");
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002093 /*
2094 * If any of the Radios are available, it will need to be
2095 * shutdown. So return true if any Radio is available.
2096 */
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002097 final long identity = Binder.clearCallingIdentity();
2098 try {
2099 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2100 Phone phone = PhoneFactory.getPhone(i);
2101 if (phone != null && phone.isRadioAvailable()) return true;
2102 }
2103 logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown.");
2104 return false;
2105 } finally {
2106 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002107 }
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002108 }
2109
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002110 @Override
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002111 public void shutdownMobileRadios() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002112 enforceModifyPermission();
2113
2114 final long identity = Binder.clearCallingIdentity();
2115 try {
2116 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
2117 logv("Shutting down Phone " + i);
2118 shutdownRadioUsingPhoneId(i);
2119 }
2120 } finally {
2121 Binder.restoreCallingIdentity(identity);
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002122 }
2123 }
2124
2125 private void shutdownRadioUsingPhoneId(int phoneId) {
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002126 Phone phone = PhoneFactory.getPhone(phoneId);
2127 if (phone != null && phone.isRadioAvailable()) {
2128 phone.shutdownRadio();
2129 }
2130 }
2131
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002132 public boolean setRadioPower(boolean turnOn) {
Jack Yub4e16162017-05-15 12:48:40 -07002133 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002134
2135 final long identity = Binder.clearCallingIdentity();
2136 try {
2137 final Phone defaultPhone = PhoneFactory.getDefaultPhone();
2138 if (defaultPhone != null) {
2139 defaultPhone.setRadioPower(turnOn);
2140 return true;
2141 } else {
2142 loge("There's no default phone.");
2143 return false;
2144 }
2145 } finally {
2146 Binder.restoreCallingIdentity(identity);
Wei Liu9ae2a062016-08-08 11:09:34 -07002147 }
Wink Saville36469e72014-06-11 15:17:00 -07002148 }
2149
Wink Savilleb564aae2014-10-23 10:18:09 -07002150 public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002151 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002152
2153 final long identity = Binder.clearCallingIdentity();
2154 try {
2155 final Phone phone = getPhone(subId);
2156 if (phone != null) {
2157 phone.setRadioPower(turnOn);
2158 return true;
2159 } else {
2160 return false;
2161 }
2162 } finally {
2163 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002164 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002165 }
2166
Wink Saville36469e72014-06-11 15:17:00 -07002167 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002168 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002169 public boolean enableDataConnectivity() {
2170 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002171
2172 final long identity = Binder.clearCallingIdentity();
2173 try {
2174 int subId = mSubscriptionController.getDefaultDataSubId();
2175 final Phone phone = getPhone(subId);
2176 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002177 phone.getDataEnabledSettings().setUserDataEnabled(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002178 return true;
2179 } else {
2180 return false;
2181 }
2182 } finally {
2183 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002184 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002185 }
2186
Wink Saville36469e72014-06-11 15:17:00 -07002187 // FIXME: subId version needed
Sanket Padawe356d7632015-06-22 14:03:32 -07002188 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002189 public boolean disableDataConnectivity() {
2190 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002191
2192 final long identity = Binder.clearCallingIdentity();
2193 try {
2194 int subId = mSubscriptionController.getDefaultDataSubId();
2195 final Phone phone = getPhone(subId);
2196 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08002197 phone.getDataEnabledSettings().setUserDataEnabled(false);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002198 return true;
2199 } else {
2200 return false;
2201 }
2202 } finally {
2203 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002204 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002205 }
2206
Sanket Padawe356d7632015-06-22 14:03:32 -07002207 @Override
Jack Yuacf8a132017-05-01 17:00:48 -07002208 public boolean isDataConnectivityPossible(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002209 final long identity = Binder.clearCallingIdentity();
2210 try {
2211 final Phone phone = getPhone(subId);
2212 if (phone != null) {
Jack Yub5d8f642018-11-26 11:20:48 -08002213 return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002214 } else {
2215 return false;
2216 }
2217 } finally {
2218 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002219 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002220 }
2221
2222 public boolean handlePinMmi(String dialString) {
Wink Savilleadd7cc52014-09-08 14:23:09 -07002223 return handlePinMmiForSubscriber(getDefaultSubscription(), dialString);
Wink Saville36469e72014-06-11 15:17:00 -07002224 }
2225
pkanwarae03a6b2016-11-06 20:37:09 -08002226 public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002227 enforceCallPermission();
2228
2229 final long identity = Binder.clearCallingIdentity();
2230 try {
2231 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2232 return;
2233 }
2234 Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback);
2235 sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId);
2236 } finally {
2237 Binder.restoreCallingIdentity(identity);
2238 }
pkanwar32d516d2016-10-14 19:37:38 -07002239 };
2240
Wink Savilleb564aae2014-10-23 10:18:09 -07002241 public boolean handlePinMmiForSubscriber(int subId, String dialString) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002242 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002243
2244 final long identity = Binder.clearCallingIdentity();
2245 try {
2246 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
2247 return false;
2248 }
2249 return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId);
2250 } finally {
2251 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002252 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002253 }
2254
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002255 public int getCallState() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002256 return getCallStateForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002257 }
2258
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002259 public int getCallStateForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002260 final long identity = Binder.clearCallingIdentity();
2261 try {
2262 Phone phone = PhoneFactory.getPhone(slotIndex);
2263 return phone == null ? TelephonyManager.CALL_STATE_IDLE :
2264 PhoneConstantConversions.convertCallState(phone.getState());
2265 } finally {
2266 Binder.restoreCallingIdentity(identity);
2267 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002268 }
2269
Sanket Padawe356d7632015-06-22 14:03:32 -07002270 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002271 public int getDataState() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002272 return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId());
2273 }
2274
2275 @Override
2276 public int getDataStateForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002277 final long identity = Binder.clearCallingIdentity();
2278 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002279 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002280 if (phone != null) {
2281 return PhoneConstantConversions.convertDataState(phone.getDataConnectionState());
2282 } else {
2283 return PhoneConstantConversions.convertDataState(
2284 PhoneConstants.DataState.DISCONNECTED);
2285 }
2286 } finally {
2287 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002288 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002289 }
2290
Sanket Padawe356d7632015-06-22 14:03:32 -07002291 @Override
Nathan Harolde037c472019-06-26 00:41:07 +00002292 public int getDataActivity() {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002293 return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId());
2294 }
2295
2296 @Override
2297 public int getDataActivityForSubId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002298 final long identity = Binder.clearCallingIdentity();
2299 try {
Nathan Haroldc4689b12019-06-14 16:58:30 -07002300 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002301 if (phone != null) {
2302 return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState());
2303 } else {
2304 return TelephonyManager.DATA_ACTIVITY_NONE;
2305 }
2306 } finally {
2307 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002308 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002309 }
2310
2311 @Override
Meng Wangd64acad2019-12-09 13:13:01 -08002312 public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002313 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002314 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002315
2316 LocationAccessPolicy.LocationPermissionResult locationResult =
2317 LocationAccessPolicy.checkLocationPermission(mApp,
2318 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2319 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002320 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002321 .setCallingPid(Binder.getCallingPid())
2322 .setCallingUid(Binder.getCallingUid())
2323 .setMethod("getCellLocation")
Hall Liuc3f8eb62020-01-24 18:07:12 -08002324 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002325 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2326 .build());
2327 switch (locationResult) {
2328 case DENIED_HARD:
2329 throw new SecurityException("Not allowed to access cell location");
2330 case DENIED_SOFT:
Meng Wangd64acad2019-12-09 13:13:01 -08002331 return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA)
2332 ? new CellIdentityCdma() : new CellIdentityGsm();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002333 }
2334
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002335 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002336 final long identity = Binder.clearCallingIdentity();
2337 try {
2338 if (DBG_LOC) log("getCellLocation: is active user");
Nathan Harold3ff88932018-08-14 10:19:49 -07002339 int subId = mSubscriptionController.getDefaultDataSubId();
Meng Wangd64acad2019-12-09 13:13:01 -08002340 return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002341 } finally {
2342 Binder.restoreCallingIdentity(identity);
2343 }
Svetoslav64fad262015-04-14 14:35:21 -07002344 }
2345
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002346 @Override
Jack Yu01425032020-02-22 19:38:58 -08002347 public String getNetworkCountryIsoForPhone(int phoneId) {
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002348 // Reporting the correct network country is ambiguous when IWLAN could conflict with
2349 // registered cell info, so return a NULL country instead.
2350 final long identity = Binder.clearCallingIdentity();
2351 try {
Malcolm Chen3732c2b2018-07-18 20:15:24 -07002352 if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) {
2353 // Get default phone in this case.
2354 phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX;
2355 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002356 final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002357 Phone phone = PhoneFactory.getPhone(phoneId);
Nathan Haroldcf38ed92020-04-21 19:31:10 -07002358 if (phone == null) return "";
2359 ServiceStateTracker sst = phone.getServiceStateTracker();
2360 if (sst == null) return "";
2361 LocaleTracker lt = sst.getLocaleTracker();
2362 if (lt == null) return "";
2363 if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry();
2364 EmergencyNumberTracker ent = phone.getEmergencyNumberTracker();
2365 return (ent == null) ? "" : ent.getEmergencyCountryIso();
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002366 } finally {
2367 Binder.restoreCallingIdentity(identity);
2368 }
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002369 }
2370
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002371 /**
2372 * This method was removed due to potential issues caused by performing partial
2373 * updates of service state, and lack of a credible use case.
2374 *
2375 * This has the ability to break the telephony implementation by disabling notification of
2376 * changes in device connectivity. DO NOT USE THIS!
2377 */
Jonathan Basseribf5362b2017-07-19 12:22:35 -07002378 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002379 public void enableLocationUpdates() {
2380 mApp.enforceCallingOrSelfPermission(
2381 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002382 }
2383
Nathan Harold7c8d0f12020-05-28 20:40:31 -07002384 /**
2385 * This method was removed due to potential issues caused by performing partial
2386 * updates of service state, and lack of a credible use case.
2387 *
2388 * This has the ability to break the telephony implementation by disabling notification of
2389 * changes in device connectivity. DO NOT USE THIS!
2390 */
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002391 @Override
2392 public void disableLocationUpdates() {
2393 mApp.enforceCallingOrSelfPermission(
2394 android.Manifest.permission.CONTROL_LOCATION_UPDATES, null);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002395 }
2396
Nathan Harold31d7ff32018-10-15 20:20:30 -07002397 /**
2398 * Returns the target SDK version number for a given package name.
2399 *
Nathan Haroldec184742019-07-10 17:04:16 -07002400 * This call MUST be invoked before clearing the calling UID.
2401 *
Nathan Harold31d7ff32018-10-15 20:20:30 -07002402 * @return target SDK if the package is found or INT_MAX.
2403 */
2404 private int getTargetSdk(String packageName) {
2405 try {
Nathan Haroldec184742019-07-10 17:04:16 -07002406 final ApplicationInfo ai = mApp.getPackageManager().getApplicationInfoAsUser(
Chen Xu54d20302019-07-30 15:12:06 -07002407 packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
Nathan Harold31d7ff32018-10-15 20:20:30 -07002408 if (ai != null) return ai.targetSdkVersion;
2409 } catch (PackageManager.NameNotFoundException unexpected) {
Nathan Haroldec184742019-07-10 17:04:16 -07002410 loge("Failed to get package info for pkg="
2411 + packageName + ", uid=" + Binder.getCallingUid());
Nathan Harold31d7ff32018-10-15 20:20:30 -07002412 }
2413 return Integer.MAX_VALUE;
2414 }
2415
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002416 @Override
2417 @SuppressWarnings("unchecked")
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002418 public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage,
2419 String callingFeatureId) {
Nathan Harold31d7ff32018-10-15 20:20:30 -07002420 final int targetSdk = getTargetSdk(callingPackage);
Nathan Harolddbea45a2018-08-30 14:35:07 -07002421 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2422 throw new SecurityException(
2423 "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels.");
2424 }
Nathan Haroldb4d55612018-07-20 13:13:08 -07002425
Jordan Liu1617b712019-07-10 15:06:26 -07002426 if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(),
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002427 callingPackage) != AppOpsManager.MODE_ALLOWED) {
2428 return null;
2429 }
Svetoslav64fad262015-04-14 14:35:21 -07002430
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002431 if (DBG_LOC) log("getNeighboringCellInfo: is active user");
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002432
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002433 List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId);
Nathan Haroldf180aac2018-06-01 18:43:55 -07002434 if (info == null) return null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002435
Nathan Haroldf180aac2018-06-01 18:43:55 -07002436 List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>();
2437 for (CellInfo ci : info) {
2438 if (ci instanceof CellInfoGsm) {
2439 neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci));
2440 } else if (ci instanceof CellInfoWcdma) {
2441 neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci));
2442 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002443 }
Nathan Haroldf180aac2018-06-01 18:43:55 -07002444 return (neighbors.size()) > 0 ? neighbors : null;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002445 }
2446
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002447 private List<CellInfo> getCachedCellInfo() {
2448 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2449 for (Phone phone : PhoneFactory.getPhones()) {
2450 List<CellInfo> info = phone.getAllCellInfo();
2451 if (info != null) cellInfos.addAll(info);
2452 }
2453 return cellInfos;
2454 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002455
2456 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002457 public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002458 mApp.getSystemService(AppOpsManager.class)
Hall Liu1aa510f2017-11-22 17:40:08 -08002459 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002460
2461 LocationAccessPolicy.LocationPermissionResult locationResult =
2462 LocationAccessPolicy.checkLocationPermission(mApp,
2463 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2464 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002465 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002466 .setCallingPid(Binder.getCallingPid())
2467 .setCallingUid(Binder.getCallingUid())
2468 .setMethod("getAllCellInfo")
Nathan Harold5ae50b52019-02-20 15:46:36 -08002469 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002470 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
2471 .build());
2472 switch (locationResult) {
2473 case DENIED_HARD:
2474 throw new SecurityException("Not allowed to access cell info");
2475 case DENIED_SOFT:
2476 return new ArrayList<>();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002477 }
2478
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002479 final int targetSdk = getTargetSdk(callingPackage);
2480 if (targetSdk >= android.os.Build.VERSION_CODES.Q) {
2481 return getCachedCellInfo();
2482 }
2483
Svetoslav Ganov4a9d4482017-06-20 19:53:35 -07002484 if (DBG_LOC) log("getAllCellInfo: is active user");
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002485 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002486 final long identity = Binder.clearCallingIdentity();
2487 try {
2488 List<CellInfo> cellInfos = new ArrayList<CellInfo>();
2489 for (Phone phone : PhoneFactory.getPhones()) {
Nathan Harold3ff88932018-08-14 10:19:49 -07002490 final List<CellInfo> info = (List<CellInfo>) sendRequest(
Nathan Harold92bed182018-10-12 18:16:49 -07002491 CMD_GET_ALL_CELL_INFO, null, phone, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002492 if (info != null) cellInfos.addAll(info);
2493 }
2494 return cellInfos;
2495 } finally {
2496 Binder.restoreCallingIdentity(identity);
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002497 }
2498 }
2499
Sailesh Nepalbd76e4e2013-10-27 13:59:44 -07002500 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002501 public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage,
2502 String callingFeatureId) {
2503 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId,
2504 getWorkSource(Binder.getCallingUid()));
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002505 }
2506
2507 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002508 public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb,
2509 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002510 enforceModifyPermission();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002511 requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002512 }
2513
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002514 private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb,
2515 String callingPackage, String callingFeatureId, WorkSource workSource) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002516 mApp.getSystemService(AppOpsManager.class)
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002517 .checkPackage(Binder.getCallingUid(), callingPackage);
Hall Liuf19c44f2018-11-27 14:38:17 -08002518
2519 LocationAccessPolicy.LocationPermissionResult locationResult =
2520 LocationAccessPolicy.checkLocationPermission(mApp,
2521 new LocationAccessPolicy.LocationPermissionQuery.Builder()
2522 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002523 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08002524 .setCallingPid(Binder.getCallingPid())
2525 .setCallingUid(Binder.getCallingUid())
2526 .setMethod("requestCellInfoUpdate")
Hall Liuaa4283b2020-05-21 17:09:35 -07002527 .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE)
2528 .setMinSdkVersionForFine(Build.VERSION_CODES.BASE)
Hall Liuf19c44f2018-11-27 14:38:17 -08002529 .build());
2530 switch (locationResult) {
2531 case DENIED_HARD:
Hall Liuaa4283b2020-05-21 17:09:35 -07002532 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2533 // Safetynet logging for b/154934934
2534 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2535 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002536 throw new SecurityException("Not allowed to access cell info");
2537 case DENIED_SOFT:
Hall Liuaa4283b2020-05-21 17:09:35 -07002538 if (getTargetSdk(callingPackage) < Build.VERSION_CODES.Q) {
2539 // Safetynet logging for b/154934934
2540 EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid());
2541 }
Nathan Harold5320c422019-05-09 10:26:08 -07002542 try {
2543 cb.onCellInfo(new ArrayList<CellInfo>());
2544 } catch (RemoteException re) {
2545 // Drop without consequences
2546 }
Hall Liuf19c44f2018-11-27 14:38:17 -08002547 return;
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002548 }
2549
Nathan Harolda939a962019-05-09 10:13:47 -07002550
2551 final Phone phone = getPhoneFromSubId(subId);
Nathan Haroldfa8da0f2018-09-27 18:51:29 -07002552 if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId);
2553
2554 sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource);
2555 }
2556
2557 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002558 public void setCellInfoListRate(int rateInMillis) {
Jack Yua8d8cb82017-01-16 10:15:34 -08002559 enforceModifyPermission();
Narayan Kamathf04b5a12018-01-09 11:47:15 +00002560 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002561
2562 final long identity = Binder.clearCallingIdentity();
2563 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002564 getDefaultPhone().setCellInfoListRate(rateInMillis, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002565 } finally {
2566 Binder.restoreCallingIdentity(identity);
2567 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002568 }
2569
Shishir Agrawala9f32182016-04-12 12:00:16 -07002570 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002571 public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002572 Phone phone = PhoneFactory.getPhone(slotIndex);
2573 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002574 return null;
2575 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002576 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002577 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002578 callingPackage, callingFeatureId, "getImeiForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002579 return null;
2580 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002581
2582 final long identity = Binder.clearCallingIdentity();
2583 try {
2584 return phone.getImei();
2585 } finally {
2586 Binder.restoreCallingIdentity(identity);
2587 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002588 }
2589
2590 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002591 public String getTypeAllocationCodeForSlot(int slotIndex) {
2592 Phone phone = PhoneFactory.getPhone(slotIndex);
2593 String tac = null;
2594 if (phone != null) {
2595 String imei = phone.getImei();
2596 tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH);
2597 }
2598 return tac;
2599 }
2600
2601 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002602 public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002603 Phone phone = PhoneFactory.getPhone(slotIndex);
2604 if (phone == null) {
Jack Yu2af8d712017-03-15 17:14:14 -07002605 return null;
2606 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002607
Jeff Davidson913390f2018-02-23 17:11:49 -08002608 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07002609 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002610 callingPackage, callingFeatureId, "getMeidForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002611 return null;
2612 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002613
2614 final long identity = Binder.clearCallingIdentity();
2615 try {
2616 return phone.getMeid();
2617 } finally {
2618 Binder.restoreCallingIdentity(identity);
2619 }
Jack Yu2af8d712017-03-15 17:14:14 -07002620 }
2621
2622 @Override
David Kelly5e06a7f2018-03-12 14:10:59 +00002623 public String getManufacturerCodeForSlot(int slotIndex) {
2624 Phone phone = PhoneFactory.getPhone(slotIndex);
2625 String manufacturerCode = null;
2626 if (phone != null) {
2627 String meid = phone.getMeid();
2628 manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH);
2629 }
2630 return manufacturerCode;
2631 }
2632
2633 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002634 public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage,
2635 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002636 Phone phone = PhoneFactory.getPhone(slotIndex);
2637 if (phone == null) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002638 return null;
2639 }
Jeff Davidson913390f2018-02-23 17:11:49 -08002640 int subId = phone.getSubId();
2641 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002642 mApp, subId, callingPackage, callingFeatureId,
2643 "getDeviceSoftwareVersionForSlot")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08002644 return null;
2645 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002646
2647 final long identity = Binder.clearCallingIdentity();
2648 try {
2649 return phone.getDeviceSvn();
2650 } finally {
2651 Binder.restoreCallingIdentity(identity);
2652 }
Shishir Agrawala9f32182016-04-12 12:00:16 -07002653 }
2654
fionaxu43304da2017-11-27 22:51:16 -08002655 @Override
2656 public int getSubscriptionCarrierId(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002657 final long identity = Binder.clearCallingIdentity();
2658 try {
2659 final Phone phone = getPhone(subId);
2660 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId();
2661 } finally {
2662 Binder.restoreCallingIdentity(identity);
2663 }
fionaxu43304da2017-11-27 22:51:16 -08002664 }
2665
2666 @Override
2667 public String getSubscriptionCarrierName(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002668 final long identity = Binder.clearCallingIdentity();
2669 try {
2670 final Phone phone = getPhone(subId);
2671 return phone == null ? null : phone.getCarrierName();
2672 } finally {
2673 Binder.restoreCallingIdentity(identity);
2674 }
fionaxu43304da2017-11-27 22:51:16 -08002675 }
2676
calvinpanffe225e2018-11-01 19:43:06 +08002677 @Override
chen xu0026ca62019-03-06 15:28:50 -08002678 public int getSubscriptionSpecificCarrierId(int subId) {
chen xu25637222018-11-04 17:17:00 -08002679 final long identity = Binder.clearCallingIdentity();
2680 try {
2681 final Phone phone = getPhone(subId);
2682 return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID
chen xu0026ca62019-03-06 15:28:50 -08002683 : phone.getSpecificCarrierId();
chen xu25637222018-11-04 17:17:00 -08002684 } finally {
2685 Binder.restoreCallingIdentity(identity);
2686 }
2687 }
2688
2689 @Override
chen xu0026ca62019-03-06 15:28:50 -08002690 public String getSubscriptionSpecificCarrierName(int subId) {
chen xu25637222018-11-04 17:17:00 -08002691 final long identity = Binder.clearCallingIdentity();
2692 try {
2693 final Phone phone = getPhone(subId);
chen xu0026ca62019-03-06 15:28:50 -08002694 return phone == null ? null : phone.getSpecificCarrierName();
chen xu25637222018-11-04 17:17:00 -08002695 } finally {
2696 Binder.restoreCallingIdentity(identity);
2697 }
2698 }
2699
chen xu651eec72018-11-11 19:03:44 -08002700 @Override
chen xu864e11c2018-12-06 22:10:03 -08002701 public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) {
2702 if (!isSubscriptionMccMnc) {
2703 enforceReadPrivilegedPermission("getCarrierIdFromMccMnc");
2704 }
chen xu651eec72018-11-11 19:03:44 -08002705 final Phone phone = PhoneFactory.getPhone(slotIndex);
2706 if (phone == null) {
2707 return TelephonyManager.UNKNOWN_CARRIER_ID;
2708 }
2709 final long identity = Binder.clearCallingIdentity();
2710 try {
2711 return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc);
2712 } finally {
2713 Binder.restoreCallingIdentity(identity);
2714 }
2715 }
2716
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002717 //
2718 // Internal helper methods.
2719 //
2720
Sanket Padaweee13a9b2016-03-08 17:30:28 -08002721 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002722 * Make sure the caller has the MODIFY_PHONE_STATE permission.
2723 *
2724 * @throws SecurityException if the caller does not have the required permission
2725 */
2726 private void enforceModifyPermission() {
2727 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null);
2728 }
2729
Shuo Qian5bac1ee2020-01-16 20:51:11 -08002730 /**
2731 * Make sure the caller is system.
2732 *
2733 * @throws SecurityException if the caller is not system.
2734 */
2735 private void enforceSystemCaller() {
2736 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
2737 throw new SecurityException("Caller must be system");
2738 }
2739 }
2740
Shuo Qianf2b2df42019-11-13 17:43:31 -08002741 private void enforceActiveEmergencySessionPermission() {
2742 mApp.enforceCallingOrSelfPermission(
2743 android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null);
2744 }
2745
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002746 /**
2747 * Make sure the caller has the CALL_PHONE permission.
2748 *
2749 * @throws SecurityException if the caller does not have the required permission
2750 */
2751 private void enforceCallPermission() {
2752 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null);
2753 }
2754
paulhu423b5f22019-08-23 19:17:33 +08002755 private void enforceSettingsPermission() {
2756 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null);
Stuart Scott8eef64f2015-04-08 15:13:54 -07002757 }
2758
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002759 private String createTelUrl(String number) {
2760 if (TextUtils.isEmpty(number)) {
2761 return null;
2762 }
2763
Jake Hambye994d462014-02-03 13:10:13 -08002764 return "tel:" + number;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002765 }
2766
Ihab Awadf9e92732013-12-05 18:02:52 -08002767 private static void log(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002768 Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg);
2769 }
2770
Naveen Kalla1fd79bd2014-08-08 00:48:59 -07002771 private static void logv(String msg) {
2772 Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg);
2773 }
2774
Ihab Awadf9e92732013-12-05 18:02:52 -08002775 private static void loge(String msg) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002776 Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg);
2777 }
2778
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002779 @Override
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002780 public int getActivePhoneType() {
Shishir Agrawala9f32182016-04-12 12:00:16 -07002781 return getActivePhoneTypeForSlot(getSlotForDefaultSubscription());
Wink Saville36469e72014-06-11 15:17:00 -07002782 }
2783
Sanket Padawe356d7632015-06-22 14:03:32 -07002784 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07002785 public int getActivePhoneTypeForSlot(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002786 final long identity = Binder.clearCallingIdentity();
2787 try {
2788 final Phone phone = PhoneFactory.getPhone(slotIndex);
2789 if (phone == null) {
2790 return PhoneConstants.PHONE_TYPE_NONE;
2791 } else {
2792 return phone.getPhoneType();
2793 }
2794 } finally {
2795 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002796 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002797 }
2798
2799 /**
2800 * Returns the CDMA ERI icon index to display
2801 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002802 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002803 public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) {
2804 return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage,
2805 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002806 }
2807
Sanket Padawe356d7632015-06-22 14:03:32 -07002808 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002809 public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage,
2810 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002811 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002812 mApp, subId, callingPackage, callingFeatureId,
2813 "getCdmaEriIconIndexForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002814 return -1;
2815 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002816
2817 final long identity = Binder.clearCallingIdentity();
2818 try {
2819 final Phone phone = getPhone(subId);
2820 if (phone != null) {
2821 return phone.getCdmaEriIconIndex();
2822 } else {
2823 return -1;
2824 }
2825 } finally {
2826 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002827 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002828 }
2829
2830 /**
2831 * Returns the CDMA ERI icon mode,
2832 * 0 - ON
2833 * 1 - FLASHING
2834 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002835 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002836 public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) {
2837 return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage,
2838 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002839 }
2840
Sanket Padawe356d7632015-06-22 14:03:32 -07002841 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002842 public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage,
2843 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002844 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002845 mApp, subId, callingPackage, callingFeatureId,
2846 "getCdmaEriIconModeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002847 return -1;
2848 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002849
2850 final long identity = Binder.clearCallingIdentity();
2851 try {
2852 final Phone phone = getPhone(subId);
2853 if (phone != null) {
2854 return phone.getCdmaEriIconMode();
2855 } else {
2856 return -1;
2857 }
2858 } finally {
2859 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002860 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002861 }
2862
2863 /**
2864 * Returns the CDMA ERI text,
2865 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002866 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002867 public String getCdmaEriText(String callingPackage, String callingFeatureId) {
2868 return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage,
2869 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07002870 }
2871
Sanket Padawe356d7632015-06-22 14:03:32 -07002872 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002873 public String getCdmaEriTextForSubscriber(int subId, String callingPackage,
2874 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002875 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08002876 mApp, subId, callingPackage, callingFeatureId,
2877 "getCdmaEriIconTextForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07002878 return null;
2879 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002880
2881 final long identity = Binder.clearCallingIdentity();
2882 try {
2883 final Phone phone = getPhone(subId);
2884 if (phone != null) {
2885 return phone.getCdmaEriText();
2886 } else {
2887 return null;
2888 }
2889 } finally {
2890 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07002891 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002892 }
2893
2894 /**
Junda Liuca05d5d2014-08-14 22:36:34 -07002895 * Returns the CDMA MDN.
2896 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002897 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002898 public String getCdmaMdn(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002899 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2900 mApp, subId, "getCdmaMdn");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002901
2902 final long identity = Binder.clearCallingIdentity();
2903 try {
2904 final Phone phone = getPhone(subId);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002905 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002906 return phone.getLine1Number();
2907 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002908 loge("getCdmaMdn: no phone found. Invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002909 return null;
2910 }
2911 } finally {
2912 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002913 }
2914 }
2915
2916 /**
2917 * Returns the CDMA MIN.
2918 */
Sanket Padawe356d7632015-06-22 14:03:32 -07002919 @Override
Wink Savilleb564aae2014-10-23 10:18:09 -07002920 public String getCdmaMin(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08002921 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
2922 mApp, subId, "getCdmaMin");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002923
2924 final long identity = Binder.clearCallingIdentity();
2925 try {
2926 final Phone phone = getPhone(subId);
2927 if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) {
2928 return phone.getCdmaMin();
2929 } else {
2930 return null;
2931 }
2932 } finally {
2933 Binder.restoreCallingIdentity(identity);
Junda Liuca05d5d2014-08-14 22:36:34 -07002934 }
2935 }
2936
Hall Liud892bec2018-11-30 14:51:45 -08002937 @Override
2938 public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis,
2939 INumberVerificationCallback callback, String callingPackage) {
2940 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
2941 != PERMISSION_GRANTED) {
2942 throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission");
2943 }
2944 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
2945
2946 String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp);
2947 if (!TextUtils.equals(callingPackage, authorizedPackage)) {
2948 throw new SecurityException("Calling package must be configured in the device config");
2949 }
2950
2951 if (range == null) {
2952 throw new NullPointerException("Range must be non-null");
2953 }
2954
2955 timeoutMillis = Math.min(timeoutMillis,
Hall Liubd069e32019-02-28 18:56:30 -08002956 TelephonyManager.getMaxNumberVerificationTimeoutMillis());
Hall Liud892bec2018-11-30 14:51:45 -08002957
2958 NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis);
2959 }
2960
Junda Liuca05d5d2014-08-14 22:36:34 -07002961 /**
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002962 * Returns true if CDMA provisioning needs to run.
2963 */
2964 public boolean needsOtaServiceProvisioning() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002965 final long identity = Binder.clearCallingIdentity();
2966 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08002967 return getDefaultPhone().needsOtaServiceProvisioning();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002968 } finally {
2969 Binder.restoreCallingIdentity(identity);
2970 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07002971 }
2972
2973 /**
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002974 * Sets the voice mail number of a given subId.
2975 */
2976 @Override
2977 public boolean setVoiceMailNumber(int subId, String alphaTag, String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08002978 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
2979 mApp, subId, "setVoiceMailNumber");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002980
2981 final long identity = Binder.clearCallingIdentity();
2982 try {
2983 Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER,
2984 new Pair<String, String>(alphaTag, number), new Integer(subId));
2985 return success;
2986 } finally {
2987 Binder.restoreCallingIdentity(identity);
2988 }
Shishir Agrawal76d5da92014-11-09 16:17:25 -08002989 }
2990
Ta-wei Yen87c49842016-05-13 21:19:52 -07002991 @Override
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002992 public Bundle getVisualVoicemailSettings(String callingPackage, int subId) {
2993 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07002994 TelecomManager tm = mApp.getSystemService(TelecomManager.class);
2995 String systemDialer = tm.getSystemDialerPackage();
Ta-wei Yenc9df0432017-04-17 17:09:07 -07002996 if (!TextUtils.equals(callingPackage, systemDialer)) {
2997 throw new SecurityException("caller must be system dialer");
2998 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08002999
3000 final long identity = Binder.clearCallingIdentity();
3001 try {
3002 PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId);
3003 if (phoneAccountHandle == null) {
3004 return null;
3005 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003006 return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003007 } finally {
3008 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003009 }
Ta-wei Yenc9df0432017-04-17 17:09:07 -07003010 }
3011
3012 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003013 public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId,
3014 int subId) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003015 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jeff Davidson7e17e312018-02-13 18:17:36 -08003016 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003017 mApp, subId, callingPackage, callingFeatureId,
3018 "getVisualVoicemailPackageName")) {
Ta-wei Yendca928f2017-01-10 16:17:08 -08003019 return null;
3020 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003021
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003022 final long identity = Binder.clearCallingIdentity();
3023 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003024 return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName();
Jeff Davidsona8e4e242018-03-15 17:16:18 -07003025 } finally {
3026 Binder.restoreCallingIdentity(identity);
3027 }
Ta-wei Yendca928f2017-01-10 16:17:08 -08003028 }
3029
3030 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003031 public void enableVisualVoicemailSmsFilter(String callingPackage, int subId,
3032 VisualVoicemailSmsFilterSettings settings) {
3033 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003034
3035 final long identity = Binder.clearCallingIdentity();
3036 try {
3037 VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003038 mApp, callingPackage, subId, settings);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003039 } finally {
3040 Binder.restoreCallingIdentity(identity);
3041 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003042 }
3043
3044 @Override
Ta-wei Yenb6929602016-05-24 15:48:27 -07003045 public void disableVisualVoicemailSmsFilter(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 VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter(
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 Yenb6929602016-05-24 15:48:27 -07003058 public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings(
3059 String callingPackage, int subId) {
3060 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003061
3062 final long identity = Binder.clearCallingIdentity();
3063 try {
3064 return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003065 mApp, callingPackage, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003066 } finally {
3067 Binder.restoreCallingIdentity(identity);
3068 }
Ta-wei Yen87c49842016-05-13 21:19:52 -07003069 }
3070
3071 @Override
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003072 public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003073 enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003074
3075 final long identity = Binder.clearCallingIdentity();
3076 try {
3077 return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings(
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003078 mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003079 } finally {
3080 Binder.restoreCallingIdentity(identity);
3081 }
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003082 }
3083
3084 @Override
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003085 public void sendVisualVoicemailSmsForSubscriber(String callingPackage,
3086 String callingAttributionTag, int subId, String number, int port, String text,
3087 PendingIntent sentIntent) {
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003088 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Ta-wei Yen527a9c02017-01-06 15:29:25 -08003089 enforceVisualVoicemailPackage(callingPackage, subId);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08003090 enforceSendSmsPermission();
Amit Mahajandccb3f12019-05-13 13:48:32 -07003091 SmsController smsController = PhoneFactory.getSmsController();
Philip P. Moltmann2f6f8ce2020-03-18 18:17:02 -07003092 smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag,
3093 subId, number, port, text, sentIntent);
Ta-wei Yen87c49842016-05-13 21:19:52 -07003094 }
Amit Mahajandccb3f12019-05-13 13:48:32 -07003095
Shishir Agrawal76d5da92014-11-09 16:17:25 -08003096 /**
fionaxu0152e512016-11-14 13:36:14 -08003097 * Sets the voice activation state of a given subId.
3098 */
3099 @Override
3100 public void setVoiceActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003101 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3102 mApp, subId, "setVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003103
3104 final long identity = Binder.clearCallingIdentity();
3105 try {
3106 final Phone phone = getPhone(subId);
3107 if (phone != null) {
3108 phone.setVoiceActivationState(activationState);
3109 } else {
3110 loge("setVoiceActivationState fails with invalid subId: " + subId);
3111 }
3112 } finally {
3113 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003114 }
3115 }
3116
3117 /**
3118 * Sets the data activation state of a given subId.
3119 */
3120 @Override
3121 public void setDataActivationState(int subId, int activationState) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08003122 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
3123 mApp, subId, "setDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003124
3125 final long identity = Binder.clearCallingIdentity();
3126 try {
3127 final Phone phone = getPhone(subId);
3128 if (phone != null) {
3129 phone.setDataActivationState(activationState);
3130 } else {
Taesu Leef8fbed92019-10-07 18:47:02 +09003131 loge("setDataActivationState fails with invalid subId: " + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003132 }
3133 } finally {
3134 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003135 }
3136 }
3137
3138 /**
3139 * Returns the voice activation state of a given subId.
3140 */
3141 @Override
3142 public int getVoiceActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003143 enforceReadPrivilegedPermission("getVoiceActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003144
fionaxu0152e512016-11-14 13:36:14 -08003145 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003146 final long identity = Binder.clearCallingIdentity();
3147 try {
3148 if (phone != null) {
3149 return phone.getVoiceActivationState();
3150 } else {
3151 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3152 }
3153 } finally {
3154 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003155 }
3156 }
3157
3158 /**
3159 * Returns the data activation state of a given subId.
3160 */
3161 @Override
3162 public int getDataActivationState(int subId, String callingPackage) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003163 enforceReadPrivilegedPermission("getDataActivationState");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003164
fionaxu0152e512016-11-14 13:36:14 -08003165 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003166 final long identity = Binder.clearCallingIdentity();
3167 try {
3168 if (phone != null) {
3169 return phone.getDataActivationState();
3170 } else {
3171 return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN;
3172 }
3173 } finally {
3174 Binder.restoreCallingIdentity(identity);
fionaxu0152e512016-11-14 13:36:14 -08003175 }
3176 }
3177
3178 /**
Wink Saville36469e72014-06-11 15:17:00 -07003179 * Returns the unread count of voicemails for a subId
3180 */
Sanket Padawe356d7632015-06-22 14:03:32 -07003181 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003182 public int getVoiceMessageCountForSubscriber(int subId, String callingPackage,
3183 String callingFeatureId) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003184 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08003185 mApp, subId, callingPackage, callingFeatureId,
3186 "getVoiceMessageCountForSubscriber")) {
Brad Ebingerf7664ba2018-11-29 12:43:38 -08003187 return 0;
3188 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003189 final long identity = Binder.clearCallingIdentity();
3190 try {
3191 final Phone phone = getPhone(subId);
3192 if (phone != null) {
3193 return phone.getVoiceMessageCount();
3194 } else {
3195 return 0;
3196 }
3197 } finally {
3198 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07003199 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07003200 }
3201
3202 /**
pkanwar8a4dcfb2017-01-19 13:43:16 -08003203 * returns true, if the device is in a state where both voice and data
3204 * are supported simultaneously. This can change based on location or network condition.
3205 */
3206 @Override
3207 public boolean isConcurrentVoiceAndDataAllowed(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003208 final long identity = Binder.clearCallingIdentity();
3209 try {
3210 final Phone phone = getPhone(subId);
3211 return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed());
3212 } finally {
3213 Binder.restoreCallingIdentity(identity);
3214 }
pkanwar8a4dcfb2017-01-19 13:43:16 -08003215 }
3216
3217 /**
fionaxu235cc5e2017-03-06 22:25:57 -08003218 * Send the dialer code if called from the current default dialer or the caller has
3219 * carrier privilege.
3220 * @param inputCode The dialer code to send
3221 */
3222 @Override
3223 public void sendDialerSpecialCode(String callingPackage, String inputCode) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003224 final Phone defaultPhone = getDefaultPhone();
fionaxu235cc5e2017-03-06 22:25:57 -08003225 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07003226 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
3227 String defaultDialer = tm.getDefaultDialerPackage();
fionaxu235cc5e2017-03-06 22:25:57 -08003228 if (!TextUtils.equals(callingPackage, defaultDialer)) {
Shuo Qian6d927452019-12-05 11:40:37 -08003229 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08003230 getDefaultSubscription(), "sendDialerSpecialCode");
fionaxu235cc5e2017-03-06 22:25:57 -08003231 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003232
3233 final long identity = Binder.clearCallingIdentity();
3234 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003235 defaultPhone.sendDialerSpecialCode(inputCode);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08003236 } finally {
3237 Binder.restoreCallingIdentity(identity);
3238 }
fionaxu235cc5e2017-03-06 22:25:57 -08003239 }
3240
Pengquan Menga1bb6272018-09-06 09:59:22 -07003241 @Override
3242 public int getNetworkSelectionMode(int subId) {
shilufc958392020-01-20 11:36:01 -08003243 TelephonyPermissions
3244 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3245 mApp, subId, "getNetworkSelectionMode");
3246 final long identity = Binder.clearCallingIdentity();
3247 try {
3248 if (!isActiveSubscription(subId)) {
3249 return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN;
3250 }
3251 return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId);
3252 } finally {
3253 Binder.restoreCallingIdentity(identity);
Pengquan Menge92a50d2018-09-21 15:54:48 -07003254 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07003255 }
3256
Brad Ebinger35c841c2018-10-01 10:40:55 -07003257 @Override
Brad Ebingerb2b65522019-03-15 13:48:47 -07003258 public boolean isInEmergencySmsMode() {
3259 enforceReadPrivilegedPermission("isInEmergencySmsMode");
3260 final long identity = Binder.clearCallingIdentity();
3261 try {
3262 for (Phone phone : PhoneFactory.getPhones()) {
3263 if (phone.isInEmergencySmsMode()) {
3264 return true;
3265 }
3266 }
3267 } finally {
3268 Binder.restoreCallingIdentity(identity);
3269 }
3270 return false;
3271 }
3272
shilu366312e2019-12-17 09:28:10 -08003273 /**
3274 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3275 * @param subId The subscription to use to check the configuration.
3276 * @param c The callback that will be used to send the result.
3277 */
Brad Ebingerb2b65522019-03-15 13:48:47 -07003278 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003279 public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c)
3280 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003281 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3282 mApp, subId, "registerImsRegistrationCallback");
shilu366312e2019-12-17 09:28:10 -08003283
Brad Ebinger77b832e2019-10-17 17:03:22 -07003284 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3285 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3286 "IMS not available on device.");
3287 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003288 final long token = Binder.clearCallingIdentity();
3289 try {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003290 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003291 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003292 .addRegistrationCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003293 } catch (ImsException e) {
3294 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003295 } finally {
3296 Binder.restoreCallingIdentity(token);
3297 }
3298 }
3299
shilu366312e2019-12-17 09:28:10 -08003300 /**
3301 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3302 * @param subId The subscription to use to check the configuration.
3303 * @param c The callback that will be used to send the result.
3304 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003305 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003306 public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003307 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3308 mApp, subId, "unregisterImsRegistrationCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003309 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3310 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3311 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003312 final long token = Binder.clearCallingIdentity();
3313 try {
3314 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3315 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
3316 .removeRegistrationCallbackForSubscription(c, subId);
3317 } catch (ImsException e) {
3318 Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId
3319 + "is inactive, ignoring unregister.");
3320 // If the subscription is no longer active, just return, since the callback
3321 // will already have been removed internally.
3322 } finally {
3323 Binder.restoreCallingIdentity(token);
3324 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003325 }
3326
Brad Ebinger774ba362019-10-22 17:36:18 -07003327 /**
3328 * Get the IMS service registration state for the MmTelFeature associated with this sub id.
3329 */
3330 @Override
3331 public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) {
3332 enforceReadPrivilegedPermission("getImsMmTelRegistrationState");
3333 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3334 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3335 "IMS not available on device.");
3336 }
3337 final long token = Binder.clearCallingIdentity();
3338 try {
3339 Phone phone = getPhone(subId);
3340 if (phone == null) {
3341 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3342 + subId + "'");
3343 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3344 }
3345 phone.getImsRegistrationState(regState -> {
3346 try {
3347 consumer.accept((regState == null)
3348 ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState);
3349 } catch (RemoteException e) {
3350 // Ignore if the remote process is no longer available to call back.
3351 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3352 }
3353 });
3354 } finally {
3355 Binder.restoreCallingIdentity(token);
3356 }
3357 }
3358
3359 /**
3360 * Get the transport type for the IMS service registration state.
3361 */
3362 @Override
3363 public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003364 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3365 mApp, subId, "getImsMmTelRegistrationTransportType");
Brad Ebinger774ba362019-10-22 17:36:18 -07003366 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3367 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3368 "IMS not available on device.");
3369 }
3370 final long token = Binder.clearCallingIdentity();
3371 try {
3372 Phone phone = getPhone(subId);
3373 if (phone == null) {
3374 Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '"
3375 + subId + "'");
3376 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3377 }
3378 phone.getImsRegistrationTech(regTech -> {
3379 // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager
3380 int regTechConverted = (regTech == null)
3381 ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech;
3382 regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get(
3383 regTechConverted);
3384 try {
3385 consumer.accept(regTechConverted);
3386 } catch (RemoteException e) {
3387 // Ignore if the remote process is no longer available to call back.
3388 Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available.");
3389 }
3390 });
3391 } finally {
3392 Binder.restoreCallingIdentity(token);
3393 }
3394 }
3395
shilu366312e2019-12-17 09:28:10 -08003396 /**
3397 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3398 * @param subId The subscription to use to check the configuration.
3399 * @param c The callback that will be used to send the result.
3400 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003401 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003402 public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c)
3403 throws RemoteException {
Rambo Wang37f9c242020-02-10 14:45:28 -08003404 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3405 mApp, subId, "registerMmTelCapabilityCallback");
Brad Ebinger77b832e2019-10-17 17:03:22 -07003406 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3407 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3408 "IMS not available on device.");
3409 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003410 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3411 final long token = Binder.clearCallingIdentity();
3412 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003413 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger35c841c2018-10-01 10:40:55 -07003414 .addCapabilitiesCallbackForSubscription(c, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003415 } catch (ImsException e) {
3416 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003417 } finally {
3418 Binder.restoreCallingIdentity(token);
3419 }
3420 }
3421
shilu366312e2019-12-17 09:28:10 -08003422 /**
3423 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3424 * @param subId The subscription to use to check the configuration.
3425 * @param c The callback that will be used to send the result.
3426 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003427 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003428 public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003429 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3430 mApp, subId, "unregisterMmTelCapabilityCallback");
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003431 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3432 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3433 }
Meng Wangd20ad6b2019-09-19 17:37:13 -07003434
3435 final long token = Binder.clearCallingIdentity();
3436 try {
3437 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone.
3438 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003439 .removeCapabilitiesCallbackForSubscription(c, subId);
Meng Wangd20ad6b2019-09-19 17:37:13 -07003440 } catch (ImsException e) {
3441 Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId
3442 + "is inactive, ignoring unregister.");
3443 // If the subscription is no longer active, just return, since the callback
3444 // will already have been removed internally.
3445 } finally {
3446 Binder.restoreCallingIdentity(token);
3447 }
Brad Ebinger35c841c2018-10-01 10:40:55 -07003448 }
3449
3450 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003451 public boolean isCapable(int subId, int capability, int regTech) {
3452 enforceReadPrivilegedPermission("isCapable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003453 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3454 final long token = Binder.clearCallingIdentity();
3455 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003456 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003457 getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003458 } catch (com.android.ims.ImsException e) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003459 Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage());
3460 return false;
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003461 } catch (ImsException e) {
Brad Ebinger6b5ac222019-02-04 14:36:52 -08003462 Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false.");
3463 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003464 } finally {
3465 Binder.restoreCallingIdentity(token);
3466 }
3467 }
3468
3469 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003470 public boolean isAvailable(int subId, int capability, int regTech) {
3471 enforceReadPrivilegedPermission("isAvailable");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003472 final long token = Binder.clearCallingIdentity();
3473 try {
3474 Phone phone = getPhone(subId);
3475 if (phone == null) return false;
3476 return phone.isImsCapabilityAvailable(capability, regTech);
Daniel Bright32706d92020-03-11 16:35:39 -07003477 } catch (com.android.ims.ImsException e) {
3478 Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage());
3479 return false;
Brad Ebinger35c841c2018-10-01 10:40:55 -07003480 } finally {
3481 Binder.restoreCallingIdentity(token);
3482 }
3483 }
3484
Brad Ebinger77b832e2019-10-17 17:03:22 -07003485 /**
3486 * Determines if the MmTel feature capability is supported by the carrier configuration for this
3487 * subscription.
3488 * @param subId The subscription to use to check the configuration.
3489 * @param callback The callback that will be used to send the result.
3490 * @param capability The MmTelFeature capability that will be used to send the result.
3491 * @param transportType The transport type of the MmTelFeature capability.
3492 */
3493 @Override
3494 public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability,
3495 int transportType) {
3496 enforceReadPrivilegedPermission("isMmTelCapabilitySupported");
3497 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
3498 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3499 "IMS not available on device.");
3500 }
3501 final long token = Binder.clearCallingIdentity();
3502 try {
3503 int slotId = getSlotIndex(subId);
3504 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
3505 Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '"
3506 + subId + "'");
3507 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
3508 }
3509 ImsManager.getInstance(mApp, slotId).isSupported(capability,
3510 transportType, aBoolean -> {
3511 try {
3512 callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0));
3513 } catch (RemoteException e) {
3514 Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not "
3515 + "running. Ignore");
3516 }
3517 });
3518 } finally {
3519 Binder.restoreCallingIdentity(token);
3520 }
3521 }
3522
shilu366312e2019-12-17 09:28:10 -08003523 /**
3524 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3525 * @param subId The subscription to use to check the configuration.
3526 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003527 @Override
3528 public boolean isAdvancedCallingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003529 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3530 mApp, subId, "isAdvancedCallingSettingEnabled");
shilu366312e2019-12-17 09:28:10 -08003531
Brad Ebinger35c841c2018-10-01 10:40:55 -07003532 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3533 final long token = Binder.clearCallingIdentity();
3534 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003535 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003536 getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003537 } catch (ImsException e) {
3538 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003539 } finally {
3540 Binder.restoreCallingIdentity(token);
3541 }
3542 }
3543
3544 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003545 public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003546 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003547 "setAdvancedCallingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003548 final long identity = Binder.clearCallingIdentity();
3549 try {
3550 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003551 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003552 getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003553 } catch (ImsException e) {
3554 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003555 } finally {
3556 Binder.restoreCallingIdentity(identity);
3557 }
3558 }
3559
shilu366312e2019-12-17 09:28:10 -08003560 /**
3561 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3562 * @param subId The subscription to use to check the configuration.
3563 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003564 @Override
Brad Ebinger9878b0b2018-11-08 17:43:22 -08003565 public boolean isVtSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003566 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3567 mApp, subId, "isVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003568 final long identity = Binder.clearCallingIdentity();
3569 try {
3570 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003571 return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser();
3572 } catch (ImsException e) {
3573 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003574 } finally {
3575 Binder.restoreCallingIdentity(identity);
3576 }
3577 }
3578
3579 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003580 public void setVtSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003581 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003582 "setVtSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003583 final long identity = Binder.clearCallingIdentity();
3584 try {
3585 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003586 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003587 } catch (ImsException e) {
3588 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003589 } finally {
3590 Binder.restoreCallingIdentity(identity);
3591 }
3592 }
3593
shilu366312e2019-12-17 09:28:10 -08003594 /**
3595 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3596 * @param subId The subscription to use to check the configuration.
3597 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003598 @Override
3599 public boolean isVoWiFiSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003600 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3601 mApp, subId, "isVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003602 final long identity = Binder.clearCallingIdentity();
3603 try {
3604 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003605 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003606 getSlotIndexOrException(subId)).isWfcEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003607 } catch (ImsException e) {
3608 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003609 } finally {
3610 Binder.restoreCallingIdentity(identity);
3611 }
3612 }
3613
3614 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003615 public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003616 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003617 "setVoWiFiSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003618 final long identity = Binder.clearCallingIdentity();
3619 try {
3620 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003621 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003622 } catch (ImsException e) {
3623 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003624 } finally {
3625 Binder.restoreCallingIdentity(identity);
3626 }
3627 }
3628
shilu366312e2019-12-17 09:28:10 -08003629 /**
3630 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3631 * @param subId The subscription to use to check the configuration.
3632 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003633 @Override
3634 public boolean isVoWiFiRoamingSettingEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003635 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3636 mApp, subId, "isVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003637 final long identity = Binder.clearCallingIdentity();
3638 try {
3639 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003640 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003641 getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003642 } catch (ImsException e) {
3643 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003644 } finally {
3645 Binder.restoreCallingIdentity(identity);
3646 }
3647 }
3648
3649 @Override
Brad Ebinger1c162042019-02-21 14:49:10 -08003650 public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07003651 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
Brad Ebinger1c162042019-02-21 14:49:10 -08003652 "setVoWiFiRoamingSettingEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003653 final long identity = Binder.clearCallingIdentity();
3654 try {
3655 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003656 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003657 getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003658 } catch (ImsException e) {
3659 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003660 } finally {
3661 Binder.restoreCallingIdentity(identity);
3662 }
3663 }
3664
3665 @Override
3666 public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) {
3667 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3668 "setVoWiFiNonPersistent");
3669 final long identity = Binder.clearCallingIdentity();
3670 try {
3671 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003672 ImsManager.getInstance(mApp,
Brad Ebinger2d29c012019-05-07 18:33:46 -07003673 getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003674 } catch (ImsException e) {
3675 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003676 } finally {
3677 Binder.restoreCallingIdentity(identity);
3678 }
3679 }
3680
shilu366312e2019-12-17 09:28:10 -08003681 /**
3682 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3683 * @param subId The subscription to use to check the configuration.
3684 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003685 @Override
3686 public int getVoWiFiModeSetting(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003687 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3688 mApp, subId, "getVoWiFiModeSetting");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003689 final long identity = Binder.clearCallingIdentity();
3690 try {
3691 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003692 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003693 getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003694 } catch (ImsException e) {
3695 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003696 } finally {
3697 Binder.restoreCallingIdentity(identity);
3698 }
3699 }
3700
3701 @Override
3702 public void setVoWiFiModeSetting(int subId, int mode) {
3703 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3704 "setVoWiFiModeSetting");
3705 final long identity = Binder.clearCallingIdentity();
3706 try {
3707 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003708 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003709 getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003710 } catch (ImsException e) {
3711 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003712 } finally {
3713 Binder.restoreCallingIdentity(identity);
3714 }
3715 }
3716
3717 @Override
3718 public int getVoWiFiRoamingModeSetting(int subId) {
3719 enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting");
3720 final long identity = Binder.clearCallingIdentity();
3721 try {
3722 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003723 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003724 getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003725 } catch (ImsException e) {
3726 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003727 } finally {
3728 Binder.restoreCallingIdentity(identity);
3729 }
3730 }
3731
3732 @Override
3733 public void setVoWiFiRoamingModeSetting(int subId, int mode) {
3734 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3735 "setVoWiFiRoamingModeSetting");
3736 final long identity = Binder.clearCallingIdentity();
3737 try {
3738 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003739 ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003740 getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003741 } catch (ImsException e) {
3742 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003743 } finally {
3744 Binder.restoreCallingIdentity(identity);
3745 }
3746 }
3747
3748 @Override
3749 public void setRttCapabilitySetting(int subId, boolean isEnabled) {
3750 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3751 "setRttCapabilityEnabled");
3752 final long identity = Binder.clearCallingIdentity();
3753 try {
3754 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003755 ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled);
3756 } catch (ImsException e) {
3757 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003758 } finally {
3759 Binder.restoreCallingIdentity(identity);
3760 }
3761 }
3762
shilu366312e2019-12-17 09:28:10 -08003763 /**
3764 * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission.
3765 * @param subId The subscription to use to check the configuration.
3766 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07003767 @Override
3768 public boolean isTtyOverVolteEnabled(int subId) {
Rambo Wang37f9c242020-02-10 14:45:28 -08003769 TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
3770 mApp, subId, "isTtyOverVolteEnabled");
Brad Ebinger35c841c2018-10-01 10:40:55 -07003771 final long identity = Binder.clearCallingIdentity();
3772 try {
3773 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003774 return ImsManager.getInstance(mApp,
Brad Ebinger35c841c2018-10-01 10:40:55 -07003775 getSlotIndexOrException(subId)).isTtyOnVoLteCapable();
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003776 } catch (ImsException e) {
3777 throw new ServiceSpecificException(e.getCode());
Brad Ebinger35c841c2018-10-01 10:40:55 -07003778 } finally {
3779 Binder.restoreCallingIdentity(identity);
3780 }
3781 }
3782
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003783 @Override
3784 public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3785 enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback");
3786 final long identity = Binder.clearCallingIdentity();
3787 try {
Brad Ebinger6cf0f652020-01-16 11:21:18 -08003788 if (!isImsAvailableOnDevice()) {
3789 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
3790 "IMS not available on device.");
Peter Wang050bb052020-01-13 23:33:09 -08003791 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003792 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003793 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003794 .addProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003795 } catch (ImsException e) {
3796 throw new ServiceSpecificException(e.getCode());
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003797 } finally {
3798 Binder.restoreCallingIdentity(identity);
3799 }
3800 }
3801
3802 @Override
3803 public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) {
3804 enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback");
3805 final long identity = Binder.clearCallingIdentity();
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003806 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
3807 throw new IllegalArgumentException("Invalid Subscription ID: " + subId);
3808 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003809 try {
3810 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08003811 ImsManager.getInstance(mApp, getSlotIndexOrException(subId))
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003812 .removeProvisioningCallbackForSubscription(callback, subId);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003813 } catch (ImsException e) {
Brad Ebinger4ae57f92019-01-09 16:51:30 -08003814 Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId
3815 + "is inactive, ignoring unregister.");
3816 // If the subscription is no longer active, just return, since the callback will already
3817 // have been removed internally.
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003818 } finally {
3819 Binder.restoreCallingIdentity(identity);
3820 }
3821 }
3822
allenwtsu99c623b2020-01-03 18:24:23 +08003823
3824 private void checkModifyPhoneStatePermission(int subId, String message) {
3825 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
3826 message);
3827 }
3828
3829 private boolean isImsProvisioningRequired(int subId, int capability,
3830 boolean isMmtelCapability) {
3831 Phone phone = getPhone(subId);
3832 if (phone == null) {
3833 loge("phone instance null for subid " + subId);
3834 return false;
3835 }
3836 if (isMmtelCapability) {
3837 if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3838 return false;
3839 }
3840 } else {
3841 if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) {
3842 return false;
3843 }
3844 }
3845 return true;
3846 }
3847
3848 @Override
3849 public void setRcsProvisioningStatusForCapability(int subId, int capability,
3850 boolean isProvisioned) {
3851 checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability");
3852
3853 final long identity = Binder.clearCallingIdentity();
3854 try {
3855 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3856 if (!isImsProvisioningRequired(subId, capability, false)) {
3857 return;
3858 }
3859
3860 // this capability requires provisioning, route to the correct API.
3861 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3862 switch (capability) {
3863 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3864 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3865 ims.setEabProvisioned(isProvisioned);
3866 break;
3867 default: {
3868 throw new IllegalArgumentException("Tried to set provisioning for "
3869 + "rcs capability '" + capability + "', which does not require "
3870 + "provisioning.");
3871 }
3872 }
3873 } finally {
3874 Binder.restoreCallingIdentity(identity);
3875 }
3876
3877 }
3878
3879
3880 @Override
3881 public boolean getRcsProvisioningStatusForCapability(int subId, int capability) {
3882 enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability");
3883 final long identity = Binder.clearCallingIdentity();
3884 try {
3885 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
3886 if (!isImsProvisioningRequired(subId, capability, false)) {
3887 return true;
3888 }
3889
3890 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3891 switch (capability) {
3892 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE:
3893 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
3894 return ims.isEabProvisionedOnDevice();
3895
3896 default: {
3897 throw new IllegalArgumentException("Tried to get rcs provisioning for "
3898 + "capability '" + capability + "', which does not require "
3899 + "provisioning.");
3900 }
3901 }
3902
3903 } finally {
3904 Binder.restoreCallingIdentity(identity);
3905 }
3906 }
3907
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07003908 @Override
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003909 public void setImsProvisioningStatusForCapability(int subId, int capability, int tech,
3910 boolean isProvisioned) {
3911 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3912 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3913 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3914 }
allenwtsu99c623b2020-01-03 18:24:23 +08003915 checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003916 final long identity = Binder.clearCallingIdentity();
3917 try {
3918 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003919 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003920 return;
3921 }
3922
3923 // this capability requires provisioning, route to the correct API.
3924 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3925 switch (capability) {
3926 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3927 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3928 ims.setVolteProvisioned(isProvisioned);
3929 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3930 ims.setWfcProvisioned(isProvisioned);
3931 }
3932 break;
3933 }
3934 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3935 // There is currently no difference in VT provisioning type.
3936 ims.setVtProvisioned(isProvisioned);
3937 break;
3938 }
3939 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
3940 // There is no "deprecated" UT provisioning mechanism through ImsConfig, so
3941 // change the capability of the feature instead if needed.
3942 if (isMmTelCapabilityProvisionedInCache(subId, capability, tech)
3943 == isProvisioned) {
3944 // No change in provisioning.
3945 return;
3946 }
3947 cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned);
3948 try {
3949 ims.changeMmTelCapability(capability, tech, isProvisioned);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07003950 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003951 loge("setImsProvisioningStatusForCapability: couldn't change UT capability"
3952 + ", Exception" + e.getMessage());
3953 }
3954 break;
3955 }
3956 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08003957 throw new IllegalArgumentException("Tried to set provisioning for "
3958 + "MmTel capability '" + capability + "', which does not require "
3959 + "provisioning. ");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003960 }
3961 }
3962
3963 } finally {
3964 Binder.restoreCallingIdentity(identity);
3965 }
3966 }
3967
3968 @Override
3969 public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) {
3970 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
3971 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3972 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
3973 }
3974 enforceReadPrivilegedPermission("getProvisioningStatusForCapability");
3975 final long identity = Binder.clearCallingIdentity();
3976 try {
3977 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
allenwtsu99c623b2020-01-03 18:24:23 +08003978 if (!isImsProvisioningRequired(subId, capability, true)) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08003979 return true;
3980 }
3981
3982 ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId));
3983 switch (capability) {
3984 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: {
3985 if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
3986 return ims.isVolteProvisionedOnDevice();
3987 } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) {
3988 return ims.isWfcProvisionedOnDevice();
3989 }
3990 // This should never happen, since we are checking tech above to make sure it
3991 // is either LTE or IWLAN.
3992 throw new IllegalArgumentException("Invalid radio technology for voice "
3993 + "capability.");
3994 }
3995 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
3996 // There is currently no difference in VT provisioning type.
3997 return ims.isVtProvisionedOnDevice();
3998 }
3999 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4000 // There is no "deprecated" UT provisioning mechanism, so get from shared prefs.
4001 return isMmTelCapabilityProvisionedInCache(subId, capability, tech);
4002 }
4003 default: {
allenwtsu99c623b2020-01-03 18:24:23 +08004004 throw new IllegalArgumentException(
4005 "Tried to get provisioning for MmTel capability '" + capability
4006 + "', which does not require provisioning.");
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004007 }
4008 }
4009
4010 } finally {
4011 Binder.restoreCallingIdentity(identity);
4012 }
4013 }
4014
4015 @Override
4016 public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) {
4017 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4018 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4019 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4020 }
4021 enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache");
4022 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4023 return (provisionedBits & capability) > 0;
4024 }
4025
4026 @Override
4027 public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech,
4028 boolean isProvisioned) {
4029 if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN
4030 && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) {
4031 throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid");
4032 }
4033 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4034 "setProvisioningStatusForCapability");
4035 int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech);
4036 // If the current provisioning status for capability already matches isProvisioned,
4037 // do nothing.
4038 if (((provisionedBits & capability) > 0) == isProvisioned) {
4039 return;
4040 }
4041 if (isProvisioned) {
4042 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability));
4043 } else {
4044 setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability));
4045 }
4046 }
4047
4048 /**
4049 * @return the bitfield containing the MmTel provisioning for the provided subscription and
4050 * technology. The bitfield should mirror the bitfield defined by
4051 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}.
4052 */
4053 private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) {
4054 String key = getMmTelProvisioningKey(subId, tech);
4055 // Default is no capabilities are provisioned.
4056 return mTelephonySharedPreferences.getInt(key, 0 /*default*/);
4057 }
4058
4059 /**
4060 * Sets the MmTel capability provisioning bitfield (defined by
4061 * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and
4062 * technology specified.
4063 *
4064 * Note: This is a synchronous command and should not be called on UI thread.
4065 */
4066 private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) {
4067 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
4068 String key = getMmTelProvisioningKey(subId, tech);
4069 editor.putInt(key, newField);
4070 editor.commit();
4071 }
4072
4073 private static String getMmTelProvisioningKey(int subId, int tech) {
4074 // resulting key is provision_ims_mmtel_{subId}_{tech}
4075 return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech;
4076 }
4077
4078 /**
4079 * Query CarrierConfig to see if the specified capability requires provisioning for the
4080 * carrier associated with the subscription id.
4081 */
4082 private boolean doesImsCapabilityRequireProvisioning(Context context, int subId,
4083 int capability) {
4084 CarrierConfigManager configManager = new CarrierConfigManager(context);
4085 PersistableBundle c = configManager.getConfigForSubId(subId);
4086 boolean requireUtProvisioning = c.getBoolean(
Brad Ebinger076903f2019-05-13 10:00:22 -07004087 CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false)
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004088 && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL,
4089 false);
4090 boolean requireVoiceVtProvisioning = c.getBoolean(
4091 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false);
4092
4093 // First check to make sure that the capability requires provisioning.
4094 switch (capability) {
4095 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE:
4096 // intentional fallthrough
4097 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: {
4098 if (requireVoiceVtProvisioning) {
4099 // Voice and Video requires provisioning
4100 return true;
4101 }
4102 break;
4103 }
4104 case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: {
4105 if (requireUtProvisioning) {
4106 // UT requires provisioning
4107 return true;
4108 }
4109 break;
4110 }
4111 }
4112 return false;
4113 }
4114
allenwtsu99c623b2020-01-03 18:24:23 +08004115 private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId,
4116 int capability) {
4117 CarrierConfigManager configManager = new CarrierConfigManager(context);
4118 PersistableBundle c = configManager.getConfigForSubId(subId);
4119
4120 boolean requireRcsProvisioning = c.getBoolean(
4121 CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false);
4122
4123 // First check to make sure that the capability requires provisioning.
4124 switch (capability) {
4125 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE:
4126 // intentional fallthrough
4127 case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: {
4128 if (requireRcsProvisioning) {
4129 // OPTION or PRESENCE requires provisioning
4130 return true;
4131 }
4132 break;
4133 }
4134 }
4135 return false;
4136 }
4137
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004138 @Override
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004139 public int getImsProvisioningInt(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004140 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4141 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4142 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004143 enforceReadPrivilegedPermission("getImsProvisioningInt");
4144 final long identity = Binder.clearCallingIdentity();
4145 try {
4146 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004147 int slotId = getSlotIndex(subId);
4148 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4149 Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '"
4150 + subId + "' for key:" + key);
4151 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
4152 }
4153 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004154 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004155 Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '"
4156 + subId + "' for key:" + key);
4157 return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004158 } finally {
4159 Binder.restoreCallingIdentity(identity);
4160 }
4161 }
4162
4163 @Override
4164 public String getImsProvisioningString(int subId, int key) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004165 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4166 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4167 }
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004168 enforceReadPrivilegedPermission("getImsProvisioningString");
4169 final long identity = Binder.clearCallingIdentity();
4170 try {
4171 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004172 int slotId = getSlotIndex(subId);
4173 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4174 Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '"
4175 + subId + "' for key:" + key);
4176 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC;
4177 }
4178 return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004179 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004180 Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '"
4181 + subId + "' for key:" + key);
4182 return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004183 } finally {
4184 Binder.restoreCallingIdentity(identity);
4185 }
4186 }
4187
4188 @Override
4189 public int setImsProvisioningInt(int subId, int key, int value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004190 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4191 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4192 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004193 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4194 "setImsProvisioningInt");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004195 final long identity = Binder.clearCallingIdentity();
4196 try {
4197 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004198 int slotId = getSlotIndex(subId);
4199 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4200 Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '"
4201 + subId + "' for key:" + key);
4202 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4203 }
4204 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004205 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004206 Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId
4207 + "' for key:" + key);
4208 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004209 } finally {
4210 Binder.restoreCallingIdentity(identity);
4211 }
4212 }
4213
4214 @Override
4215 public int setImsProvisioningString(int subId, int key, String value) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004216 if (!SubscriptionManager.isValidSubscriptionId(subId)) {
4217 throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'");
4218 }
Brad Ebinger3d0b34e2018-11-15 14:13:12 -08004219 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId,
4220 "setImsProvisioningString");
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004221 final long identity = Binder.clearCallingIdentity();
4222 try {
4223 // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly.
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004224 int slotId = getSlotIndex(subId);
4225 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
4226 Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '"
4227 + subId + "' for key:" + key);
4228 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
4229 }
4230 return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value);
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004231 } catch (com.android.ims.ImsException e) {
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004232 Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId
4233 + "' for key:" + key);
4234 return ImsConfigImplBase.CONFIG_RESULT_FAILED;
Brad Ebingerdf5b4f02018-10-31 11:24:17 -07004235 } finally {
4236 Binder.restoreCallingIdentity(identity);
4237 }
4238 }
4239
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004240 private int getSlotIndexOrException(int subId) throws ImsException {
Brad Ebinger35c841c2018-10-01 10:40:55 -07004241 int slotId = SubscriptionManager.getSlotIndex(subId);
4242 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
Brad Ebinger1ce9c432019-07-16 13:19:44 -07004243 throw new ImsException("Invalid Subscription Id, subId=" + subId,
4244 ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
Brad Ebinger35c841c2018-10-01 10:40:55 -07004245 }
4246 return slotId;
4247 }
4248
Brad Ebinger1c8542e2019-01-14 13:43:14 -08004249 private int getSlotIndex(int subId) {
4250 int slotId = SubscriptionManager.getSlotIndex(subId);
4251 if (!SubscriptionManager.isValidSlotIndex(slotId)) {
4252 return SubscriptionManager.INVALID_SIM_SLOT_INDEX;
4253 }
4254 return slotId;
4255 }
4256
Wink Saville36469e72014-06-11 15:17:00 -07004257 /**
Nathan Harold9042f0b2019-05-21 15:51:27 -07004258 * Returns the data network type for a subId; does not throw SecurityException.
Wink Saville36469e72014-06-11 15:17:00 -07004259 */
4260 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004261 public int getNetworkTypeForSubscriber(int subId, String callingPackage,
4262 String callingFeatureId) {
Nathan Haroldef60dba2019-05-22 13:55:14 -07004263 final int targetSdk = getTargetSdk(callingPackage);
4264 if (targetSdk > android.os.Build.VERSION_CODES.Q) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004265 return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId);
Nathan Haroldef60dba2019-05-22 13:55:14 -07004266 } else if (targetSdk == android.os.Build.VERSION_CODES.Q
Nathan Harold9042f0b2019-05-21 15:51:27 -07004267 && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004268 mApp, subId, callingPackage, callingFeatureId,
4269 "getNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004270 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4271 }
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004272
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004273 final long identity = Binder.clearCallingIdentity();
4274 try {
4275 final Phone phone = getPhone(subId);
4276 if (phone != null) {
4277 return phone.getServiceState().getDataNetworkType();
4278 } else {
4279 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4280 }
4281 } finally {
4282 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004283 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004284 }
4285
4286 /**
4287 * Returns the data network type
4288 */
4289 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004290 public int getDataNetworkType(String callingPackage, String callingFeatureId) {
4291 return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage,
4292 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004293 }
4294
4295 /**
4296 * Returns the data network type for a subId
4297 */
4298 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004299 public int getDataNetworkTypeForSubscriber(int subId, String callingPackage,
4300 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004301 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004302 mApp, subId, callingPackage, callingFeatureId,
4303 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004304 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4305 }
4306
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004307 final long identity = Binder.clearCallingIdentity();
4308 try {
4309 final Phone phone = getPhone(subId);
4310 if (phone != null) {
4311 return phone.getServiceState().getDataNetworkType();
4312 } else {
4313 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4314 }
4315 } finally {
4316 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004317 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004318 }
4319
4320 /**
Wink Saville36469e72014-06-11 15:17:00 -07004321 * Returns the Voice network type for a subId
4322 */
4323 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004324 public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage,
4325 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004326 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004327 mApp, subId, callingPackage, callingFeatureId,
4328 "getDataNetworkTypeForSubscriber")) {
Robert Greenwalta5dcfcb2015-07-10 09:06:29 -07004329 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4330 }
4331
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004332 final long identity = Binder.clearCallingIdentity();
4333 try {
4334 final Phone phone = getPhone(subId);
4335 if (phone != null) {
4336 return phone.getServiceState().getVoiceNetworkType();
4337 } else {
4338 return TelephonyManager.NETWORK_TYPE_UNKNOWN;
4339 }
4340 } finally {
4341 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004342 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004343 }
4344
4345 /**
4346 * @return true if a ICC card is present
4347 */
4348 public boolean hasIccCard() {
Wink Saville36469e72014-06-11 15:17:00 -07004349 // FIXME Make changes to pass defaultSimId of type int
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004350 return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex(
4351 getDefaultSubscription()));
Wink Saville36469e72014-06-11 15:17:00 -07004352 }
4353
4354 /**
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004355 * @return true if a ICC card is present for a slotIndex
Wink Saville36469e72014-06-11 15:17:00 -07004356 */
Sanket Padawe356d7632015-06-22 14:03:32 -07004357 @Override
Sanket Padawe13bac7b2017-03-20 15:04:47 -07004358 public boolean hasIccCardUsingSlotIndex(int slotIndex) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004359 final long identity = Binder.clearCallingIdentity();
4360 try {
4361 final Phone phone = PhoneFactory.getPhone(slotIndex);
4362 if (phone != null) {
4363 return phone.getIccCard().hasIccCard();
4364 } else {
4365 return false;
4366 }
4367 } finally {
4368 Binder.restoreCallingIdentity(identity);
Amit Mahajana6fc2a82015-01-06 11:53:51 -08004369 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004370 }
4371
4372 /**
4373 * Return if the current radio is LTE on CDMA. This
4374 * is a tri-state return value as for a period of time
4375 * the mode may be unknown.
4376 *
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004377 * @param callingPackage the name of the package making the call.
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004378 * @return {@link Phone#LTE_ON_CDMA_UNKNOWN}, {@link Phone#LTE_ON_CDMA_FALSE}
Jake Hambye994d462014-02-03 13:10:13 -08004379 * or {@link Phone#LTE_ON_CDMA_TRUE}
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004380 */
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004381 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004382 public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) {
4383 return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage,
4384 callingFeatureId);
Wink Saville36469e72014-06-11 15:17:00 -07004385 }
4386
Sanket Padawe356d7632015-06-22 14:03:32 -07004387 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004388 public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage,
4389 String callingFeatureId) {
Sarah Chinf6656a62020-01-16 12:17:23 -08004390 try {
4391 enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber");
4392 } catch (SecurityException e) {
Robert Greenwalt36b23af2015-07-06 17:59:14 -07004393 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4394 }
4395
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004396 final long identity = Binder.clearCallingIdentity();
4397 try {
4398 final Phone phone = getPhone(subId);
4399 if (phone == null) {
4400 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
4401 } else {
Nathan Harold05ad6332020-07-10 11:54:36 -07004402 return TelephonyProperties.lte_on_cdma_device()
4403 .orElse(PhoneConstants.LTE_ON_CDMA_FALSE);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004404 }
4405 } finally {
4406 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07004407 }
Wink Saville36469e72014-06-11 15:17:00 -07004408 }
4409
Wink Saville36469e72014-06-11 15:17:00 -07004410 /**
4411 * {@hide}
4412 * Returns Default subId, 0 in the case of single standby.
4413 */
Wink Savilleb564aae2014-10-23 10:18:09 -07004414 private int getDefaultSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004415 return mSubscriptionController.getDefaultSubId();
Wink Saville36469e72014-06-11 15:17:00 -07004416 }
4417
Shishir Agrawala9f32182016-04-12 12:00:16 -07004418 private int getSlotForDefaultSubscription() {
4419 return mSubscriptionController.getPhoneId(getDefaultSubscription());
4420 }
4421
Wink Savilleb564aae2014-10-23 10:18:09 -07004422 private int getPreferredVoiceSubscription() {
Wink Savilleac1bdfd2014-11-20 23:04:44 -08004423 return mSubscriptionController.getDefaultVoiceSubId();
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004424 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004425
Pengquan Menge92a50d2018-09-21 15:54:48 -07004426 private boolean isActiveSubscription(int subId) {
4427 return mSubscriptionController.isActiveSubId(subId);
4428 }
4429
Ihab Awadf2177b72013-11-25 13:33:23 -08004430 /**
4431 * @see android.telephony.TelephonyManager.WifiCallingChoices
4432 */
4433 public int getWhenToMakeWifiCalls() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004434 final long identity = Binder.clearCallingIdentity();
4435 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004436 return Settings.System.getInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004437 Settings.System.WHEN_TO_MAKE_WIFI_CALLS,
4438 getWhenToMakeWifiCallsDefaultPreference());
4439 } finally {
4440 Binder.restoreCallingIdentity(identity);
4441 }
Ihab Awadf2177b72013-11-25 13:33:23 -08004442 }
4443
4444 /**
4445 * @see android.telephony.TelephonyManager.WifiCallingChoices
4446 */
4447 public void setWhenToMakeWifiCalls(int preference) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004448 final long identity = Binder.clearCallingIdentity();
4449 try {
4450 if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004451 Settings.System.putInt(mApp.getContentResolver(),
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004452 Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference);
4453 } finally {
4454 Binder.restoreCallingIdentity(identity);
4455 }
Ihab Awadf9e92732013-12-05 18:02:52 -08004456 }
4457
Sailesh Nepald1e68152013-12-12 19:08:02 -08004458 private static int getWhenToMakeWifiCallsDefaultPreference() {
Santos Cordonda120f42014-08-06 04:44:34 -07004459 // TODO: Use a build property to choose this value.
Evan Charlton9829e882013-12-19 15:30:38 -08004460 return TelephonyManager.WifiCallingChoices.ALWAYS_USE;
Ihab Awadf2177b72013-11-25 13:33:23 -08004461 }
Shishir Agrawal69f68122013-12-16 17:25:49 -08004462
Jordan Liu4c733742019-02-28 12:03:40 -08004463 private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) {
4464 int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex);
4465 if (phoneId == -1) {
4466 throw new IllegalArgumentException("Given slot index: " + slotIndex
4467 + " does not correspond to an active phone");
4468 }
4469 return PhoneFactory.getPhone(phoneId);
4470 }
4471
Shishir Agrawal566b7612013-10-28 14:41:00 -07004472 @Override
Derek Tan740e1672017-06-27 14:56:27 -07004473 public IccOpenLogicalChannelResponse iccOpenLogicalChannel(
4474 int subId, String callingPackage, String aid, int p2) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004475 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4476 mApp, subId, "iccOpenLogicalChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004477 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004478 if (DBG) {
4479 log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2);
4480 }
4481 return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid,
4482 p2);
4483 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004484
Jordan Liu4c733742019-02-28 12:03:40 -08004485
4486 @Override
4487 public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot(
4488 int slotIndex, String callingPackage, String aid, int p2) {
4489 enforceModifyPermission();
4490 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4491 if (DBG) {
4492 log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2);
4493 }
4494 return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4495 callingPackage, aid, p2);
4496 }
4497
4498 private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone,
4499 String callingPackage, String aid, int p2) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004500 final long identity = Binder.clearCallingIdentity();
4501 try {
4502 if (TextUtils.equals(ISDR_AID, aid)) {
4503 // Only allows LPA to open logical channel to ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004504 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4505 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004506 if (bestComponent == null
4507 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4508 loge("The calling package is not allowed to access ISD-R.");
4509 throw new SecurityException(
4510 "The calling package is not allowed to access ISD-R.");
4511 }
Derek Tan740e1672017-06-27 14:56:27 -07004512 }
Derek Tan740e1672017-06-27 14:56:27 -07004513
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004514 IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest(
Jordan Liu4c733742019-02-28 12:03:40 -08004515 CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone,
4516 null /* workSource */);
4517 if (DBG) log("iccOpenLogicalChannelWithPermission: " + response);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004518 return response;
4519 } finally {
4520 Binder.restoreCallingIdentity(identity);
4521 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004522 }
4523
4524 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004525 public boolean iccCloseLogicalChannel(int subId, int channel) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004526 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4527 mApp, subId, "iccCloseLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004528 if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel);
4529 return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel);
4530 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004531
Jordan Liu4c733742019-02-28 12:03:40 -08004532 @Override
4533 public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) {
4534 enforceModifyPermission();
4535 if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel);
4536 return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex),
4537 channel);
4538 }
4539
4540 private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004541 final long identity = Binder.clearCallingIdentity();
4542 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004543 if (channel < 0) {
4544 return false;
4545 }
Jordan Liu4c733742019-02-28 12:03:40 -08004546 Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone,
4547 null /* workSource */);
4548 if (DBG) log("iccCloseLogicalChannelWithPermission: " + success);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004549 return success;
4550 } finally {
4551 Binder.restoreCallingIdentity(identity);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004552 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004553 }
4554
4555 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004556 public String iccTransmitApduLogicalChannel(int subId, int channel, int cla,
Shishir Agrawal566b7612013-10-28 14:41:00 -07004557 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004558 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4559 mApp, subId, "iccTransmitApduLogicalChannel");
Jordan Liu4c733742019-02-28 12:03:40 -08004560 if (DBG) {
4561 log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel
4562 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4563 + p3 + " data=" + data);
4564 }
4565 return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla,
4566 command, p1, p2, p3, data);
4567 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004568
Jordan Liu4c733742019-02-28 12:03:40 -08004569 @Override
4570 public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla,
4571 int command, int p1, int p2, int p3, String data) {
4572 enforceModifyPermission();
4573 if (DBG) {
4574 log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel
4575 + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3="
4576 + p3 + " data=" + data);
4577 }
4578 return iccTransmitApduLogicalChannelWithPermission(
4579 getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3,
4580 data);
4581 }
4582
4583 private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla,
4584 int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004585 final long identity = Binder.clearCallingIdentity();
4586 try {
Hall Liu4fd771b2019-05-02 09:16:29 -07004587 if (channel <= 0) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004588 return "";
4589 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004590
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004591 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004592 new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone,
4593 null /* workSource */);
4594 if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response);
Shishir Agrawal566b7612013-10-28 14:41:00 -07004595
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004596 // Append the returned status code to the end of the response payload.
4597 String s = Integer.toHexString(
4598 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4599 if (response.payload != null) {
4600 s = IccUtils.bytesToHexString(response.payload) + s;
4601 }
4602 return s;
4603 } finally {
4604 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004605 }
Shishir Agrawal566b7612013-10-28 14:41:00 -07004606 }
Jake Hambye994d462014-02-03 13:10:13 -08004607
Evan Charltonc66da362014-05-16 14:06:40 -07004608 @Override
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004609 public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla,
4610 int command, int p1, int p2, int p3, String data) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004611 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4612 mApp, subId, "iccTransmitApduBasicChannel");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004613 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Jordan Liu4c733742019-02-28 12:03:40 -08004614 if (DBG) {
4615 log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd="
4616 + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data);
4617 }
4618 return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage,
4619 cla, command, p1, p2, p3, data);
4620 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004621
Jordan Liu4c733742019-02-28 12:03:40 -08004622 @Override
4623 public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla,
4624 int command, int p1, int p2, int p3, String data) {
4625 enforceModifyPermission();
4626 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
4627 if (DBG) {
4628 log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla
4629 + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3
4630 + " data=" + data);
4631 }
4632
4633 return iccTransmitApduBasicChannelWithPermission(
4634 getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1,
4635 p2, p3, data);
4636 }
4637
4638 // open APDU basic channel assuming the caller has sufficient permissions
4639 private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage,
4640 int cla, int command, int p1, int p2, int p3, String data) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004641 final long identity = Binder.clearCallingIdentity();
4642 try {
4643 if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3
4644 && TextUtils.equals(ISDR_AID, data)) {
4645 // Only allows LPA to select ISD-R.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004646 ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone()
4647 .getContext().getPackageManager());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004648 if (bestComponent == null
4649 || !TextUtils.equals(callingPackage, bestComponent.packageName)) {
4650 loge("The calling package is not allowed to select ISD-R.");
4651 throw new SecurityException(
4652 "The calling package is not allowed to select ISD-R.");
4653 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004654 }
Holly Jiuyu Sun1cc2d552018-01-26 15:51:16 -08004655
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004656 IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL,
Jordan Liu4c733742019-02-28 12:03:40 -08004657 new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone,
4658 null /* workSource */);
4659 if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004660
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004661 // Append the returned status code to the end of the response payload.
4662 String s = Integer.toHexString(
4663 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4664 if (response.payload != null) {
4665 s = IccUtils.bytesToHexString(response.payload) + s;
4666 }
4667 return s;
4668 } finally {
4669 Binder.restoreCallingIdentity(identity);
Shishir Agrawal5ec14172014-08-05 17:05:45 -07004670 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004671 }
4672
4673 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004674 public byte[] iccExchangeSimIO(int subId, int fileID, int command, int p1, int p2, int p3,
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004675 String filePath) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004676 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4677 mApp, subId, "iccExchangeSimIO");
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004678
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004679 final long identity = Binder.clearCallingIdentity();
4680 try {
4681 if (DBG) {
4682 log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " "
4683 + p1 + " " + p2 + " " + p3 + ":" + filePath);
4684 }
4685
4686 IccIoResult response =
4687 (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO,
4688 new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath),
4689 subId);
4690
4691 if (DBG) {
4692 log("Exchange SIM_IO [R]" + response);
4693 }
4694
4695 byte[] result = null;
4696 int length = 2;
4697 if (response.payload != null) {
4698 length = 2 + response.payload.length;
4699 result = new byte[length];
4700 System.arraycopy(response.payload, 0, result, 0, response.payload.length);
4701 } else {
4702 result = new byte[length];
4703 }
4704
4705 result[length - 1] = (byte) response.sw2;
4706 result[length - 2] = (byte) response.sw1;
4707 return result;
4708 } finally {
4709 Binder.restoreCallingIdentity(identity);
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004710 }
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004711 }
4712
Nathan Haroldb3014052017-01-25 15:57:32 -08004713 /**
4714 * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM)
4715 * on a particular subscription
4716 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004717 public String[] getForbiddenPlmns(int subId, int appType, String callingPackage,
4718 String callingFeatureId) {
sqianb6e41952018-03-12 14:54:01 -07004719 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004720 mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) {
sqianb6e41952018-03-12 14:54:01 -07004721 return null;
4722 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004723
4724 final long identity = Binder.clearCallingIdentity();
4725 try {
4726 if (appType != TelephonyManager.APPTYPE_USIM
4727 && appType != TelephonyManager.APPTYPE_SIM) {
4728 loge("getForbiddenPlmnList(): App Type must be USIM or SIM");
4729 return null;
4730 }
4731 Object response = sendRequest(
4732 CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId);
4733 if (response instanceof String[]) {
4734 return (String[]) response;
4735 }
yincheng zhaod698b842019-09-06 17:06:54 -07004736 // Response is an Exception of some kind
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004737 // which is signalled to the user as a NULL retval
Nathan Haroldb3014052017-01-25 15:57:32 -08004738 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004739 } finally {
4740 Binder.restoreCallingIdentity(identity);
Nathan Haroldb3014052017-01-25 15:57:32 -08004741 }
Nathan Haroldb3014052017-01-25 15:57:32 -08004742 }
4743
yincheng zhaod698b842019-09-06 17:06:54 -07004744 /**
4745 * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular
4746 * subscription.
4747 *
4748 * @param subId the id of the subscription.
4749 * @param appType the uicc app type, must be USIM or SIM.
4750 * @param fplmns the Forbiden plmns list that needed to be written to the SIM.
4751 * @param callingPackage the op Package name.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004752 * @param callingFeatureId the feature in the package.
yincheng zhaod698b842019-09-06 17:06:54 -07004753 * @return number of fplmns that is successfully written to the SIM.
4754 */
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004755 public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage,
4756 String callingFeatureId) {
4757 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage,
4758 callingFeatureId, "setForbiddenPlmns")) {
yincheng zhaod698b842019-09-06 17:06:54 -07004759 if (DBG) logv("no permissions for setForbiddenplmns");
4760 throw new IllegalStateException("No Permissions for setForbiddenPlmns");
4761 }
4762 if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) {
4763 loge("setForbiddenPlmnList(): App Type must be USIM or SIM");
4764 throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM");
4765 }
4766 if (fplmns == null) {
4767 throw new IllegalArgumentException("Fplmn List provided is null");
4768 }
4769 for (String fplmn : fplmns) {
4770 if (!CellIdentity.isValidPlmn(fplmn)) {
4771 throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn);
4772 }
4773 }
4774 final long identity = Binder.clearCallingIdentity();
4775 try {
4776 Object response = sendRequest(
4777 CMD_SET_FORBIDDEN_PLMNS,
4778 new Pair<Integer, List<String>>(new Integer(appType), fplmns),
4779 subId);
4780 return (int) response;
4781 } finally {
4782 Binder.restoreCallingIdentity(identity);
4783 }
4784 }
4785
Shishir Agrawalda0bb0d2014-07-29 21:18:53 -07004786 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08004787 public String sendEnvelopeWithStatus(int subId, String content) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004788 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4789 mApp, subId, "sendEnvelopeWithStatus");
Evan Charltonc66da362014-05-16 14:06:40 -07004790
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004791 final long identity = Binder.clearCallingIdentity();
4792 try {
4793 IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId);
4794 if (response.payload == null) {
4795 return "";
4796 }
Evan Charltonc66da362014-05-16 14:06:40 -07004797
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004798 // Append the returned status code to the end of the response payload.
4799 String s = Integer.toHexString(
4800 (response.sw1 << 8) + response.sw2 + 0x10000).substring(1);
4801 s = IccUtils.bytesToHexString(response.payload) + s;
4802 return s;
4803 } finally {
4804 Binder.restoreCallingIdentity(identity);
4805 }
Evan Charltonc66da362014-05-16 14:06:40 -07004806 }
4807
Jake Hambye994d462014-02-03 13:10:13 -08004808 /**
4809 * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4810 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4811 *
4812 * @param itemID the ID of the item to read
4813 * @return the NV item as a String, or null on error.
4814 */
4815 @Override
4816 public String nvReadItem(int itemID) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004817 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004818 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4819 mApp, getDefaultSubscription(), "nvReadItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004820
4821 final long identity = Binder.clearCallingIdentity();
4822 try {
4823 if (DBG) log("nvReadItem: item " + itemID);
vagdeviaf9a5b92018-08-15 16:01:53 -07004824 String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004825 if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"');
4826 return value;
4827 } finally {
4828 Binder.restoreCallingIdentity(identity);
4829 }
Jake Hambye994d462014-02-03 13:10:13 -08004830 }
4831
4832 /**
4833 * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems}
4834 * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators.
4835 *
4836 * @param itemID the ID of the item to read
4837 * @param itemValue the value to write, as a String
4838 * @return true on success; false on any failure
4839 */
4840 @Override
4841 public boolean nvWriteItem(int itemID, String itemValue) {
vagdeviaf9a5b92018-08-15 16:01:53 -07004842 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Jeff Davidson7e17e312018-02-13 18:17:36 -08004843 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4844 mApp, getDefaultSubscription(), "nvWriteItem");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004845
4846 final long identity = Binder.clearCallingIdentity();
4847 try {
4848 if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"');
4849 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM,
vagdeviaf9a5b92018-08-15 16:01:53 -07004850 new Pair<Integer, String>(itemID, itemValue), workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004851 if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail"));
4852 return success;
4853 } finally {
4854 Binder.restoreCallingIdentity(identity);
4855 }
Jake Hambye994d462014-02-03 13:10:13 -08004856 }
4857
4858 /**
4859 * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage.
4860 * Used for device configuration by some CDMA operators.
4861 *
4862 * @param preferredRoamingList byte array containing the new PRL
4863 * @return true on success; false on any failure
4864 */
4865 @Override
4866 public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08004867 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4868 mApp, getDefaultSubscription(), "nvWriteCdmaPrl");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004869
4870 final long identity = Binder.clearCallingIdentity();
4871 try {
4872 if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList));
4873 Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList);
4874 if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail"));
4875 return success;
4876 } finally {
4877 Binder.restoreCallingIdentity(identity);
4878 }
Jake Hambye994d462014-02-03 13:10:13 -08004879 }
4880
4881 /**
chen xu6dac5ab2018-10-26 17:39:23 -07004882 * Rollback modem configurations to factory default except some config which are in whitelist.
Jake Hambye994d462014-02-03 13:10:13 -08004883 * Used for device configuration by some CDMA operators.
4884 *
chen xu6dac5ab2018-10-26 17:39:23 -07004885 * @param slotIndex - device slot.
4886 *
Jake Hambye994d462014-02-03 13:10:13 -08004887 * @return true on success; false on any failure
4888 */
4889 @Override
chen xu6dac5ab2018-10-26 17:39:23 -07004890 public boolean resetModemConfig(int slotIndex) {
4891 Phone phone = PhoneFactory.getPhone(slotIndex);
4892 if (phone != null) {
4893 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4894 mApp, phone.getSubId(), "resetModemConfig");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004895
chen xu6dac5ab2018-10-26 17:39:23 -07004896 final long identity = Binder.clearCallingIdentity();
4897 try {
4898 Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null);
4899 if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail"));
4900 return success;
4901 } finally {
4902 Binder.restoreCallingIdentity(identity);
4903 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004904 }
chen xu6dac5ab2018-10-26 17:39:23 -07004905 return false;
4906 }
4907
4908 /**
4909 * Generate a radio modem reset. Used for device configuration by some CDMA operators.
4910 *
4911 * @param slotIndex - device slot.
4912 *
4913 * @return true on success; false on any failure
4914 */
4915 @Override
4916 public boolean rebootModem(int slotIndex) {
4917 Phone phone = PhoneFactory.getPhone(slotIndex);
4918 if (phone != null) {
4919 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
4920 mApp, phone.getSubId(), "rebootModem");
4921
4922 final long identity = Binder.clearCallingIdentity();
4923 try {
4924 Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null);
4925 if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail"));
4926 return success;
4927 } finally {
4928 Binder.restoreCallingIdentity(identity);
4929 }
4930 }
4931 return false;
Jake Hambye994d462014-02-03 13:10:13 -08004932 }
Jake Hamby7c27be32014-03-03 13:25:59 -08004933
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004934 public String[] getPcscfAddress(String apnType, String callingPackage,
4935 String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004936 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08004937 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
4938 callingPackage, callingFeatureId, "getPcscfAddress")) {
Svet Ganovb320e182015-04-16 12:30:10 -07004939 return new String[0];
4940 }
4941
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004942 final long identity = Binder.clearCallingIdentity();
4943 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08004944 return defaultPhone.getPcscfAddress(apnType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004945 } finally {
4946 Binder.restoreCallingIdentity(identity);
4947 }
Wink Saville36469e72014-06-11 15:17:00 -07004948 }
4949
Brad Ebinger51f743a2017-01-23 13:50:20 -08004950 /**
Grace Jiaaa2eb6b2020-01-09 16:26:08 -08004951 * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and
4952 * {@link #disableIms(int)}.
4953 * @param slotIndex device slot.
4954 */
4955 public void resetIms(int slotIndex) {
4956 enforceModifyPermission();
4957
4958 final long identity = Binder.clearCallingIdentity();
4959 try {
4960 if (mImsResolver == null) {
4961 // may happen if the does not support IMS.
4962 return;
4963 }
4964 mImsResolver.disableIms(slotIndex);
4965 mImsResolver.enableIms(slotIndex);
4966 } finally {
4967 Binder.restoreCallingIdentity(identity);
4968 }
4969 }
4970
4971 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004972 * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability
4973 * status updates, if not already enabled.
Brad Ebinger51f743a2017-01-23 13:50:20 -08004974 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004975 public void enableIms(int slotId) {
Brad Ebinger51f743a2017-01-23 13:50:20 -08004976 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004977
4978 final long identity = Binder.clearCallingIdentity();
4979 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004980 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08004981 // may happen if the device does not support IMS.
4982 return;
4983 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08004984 mImsResolver.enableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004985 } finally {
4986 Binder.restoreCallingIdentity(identity);
4987 }
Brad Ebinger34bef922017-11-09 10:27:08 -08004988 }
4989
4990 /**
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004991 * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature
4992 * status updates to disabled.
Brad Ebinger34bef922017-11-09 10:27:08 -08004993 */
Brad Ebinger22bc3e42018-01-16 09:39:35 -08004994 public void disableIms(int slotId) {
4995 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08004996
4997 final long identity = Binder.clearCallingIdentity();
4998 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08004999 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005000 // may happen if the device does not support IMS.
5001 return;
5002 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005003 mImsResolver.disableIms(slotId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005004 } finally {
5005 Binder.restoreCallingIdentity(identity);
5006 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005007 }
5008
5009 /**
5010 * Returns the {@link IImsMmTelFeature} that corresponds to the given slot Id for the MMTel
5011 * feature or {@link null} if the service is not available. If the feature is available, the
5012 * {@link IImsServiceFeatureCallback} callback is registered as a listener for feature updates.
5013 */
5014 public IImsMmTelFeature getMmTelFeatureAndListen(int slotId,
Brad Ebinger34bef922017-11-09 10:27:08 -08005015 IImsServiceFeatureCallback callback) {
5016 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005017
5018 final long identity = Binder.clearCallingIdentity();
5019 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005020 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005021 // may happen if the device does not support IMS.
5022 return null;
5023 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005024 return mImsResolver.getMmTelFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005025 } finally {
5026 Binder.restoreCallingIdentity(identity);
5027 }
Brad Ebinger34bef922017-11-09 10:27:08 -08005028 }
5029
5030 /**
5031 * Returns the {@link IImsRcsFeature} that corresponds to the given slot Id for the RCS
5032 * feature during emergency calling or {@link null} if the service is not available. If the
5033 * feature is available, the {@link IImsServiceFeatureCallback} callback is registered as a
5034 * listener for feature updates.
5035 */
5036 public IImsRcsFeature getRcsFeatureAndListen(int slotId, IImsServiceFeatureCallback callback) {
5037 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005038
5039 final long identity = Binder.clearCallingIdentity();
5040 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005041 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005042 // may happen if the device does not support IMS.
5043 return null;
5044 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005045 return mImsResolver.getRcsFeatureAndListen(slotId, callback);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005046 } finally {
5047 Binder.restoreCallingIdentity(identity);
5048 }
Brad Ebinger51f743a2017-01-23 13:50:20 -08005049 }
5050
Brad Ebinger5f64b052017-12-14 14:26:15 -08005051 /**
Brad Ebingerab47dd42020-05-18 17:52:58 -07005052 * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature.
5053 */
5054 public void unregisterImsFeatureCallback(int slotId, int featureType,
5055 IImsServiceFeatureCallback callback) {
5056 enforceModifyPermission();
5057
5058 final long identity = Binder.clearCallingIdentity();
5059 try {
5060 if (mImsResolver == null) return;
5061 mImsResolver.unregisterImsFeatureCallback(slotId, featureType, callback);
5062 } finally {
5063 Binder.restoreCallingIdentity(identity);
5064 }
5065 }
5066
5067 /**
Brad Ebinger5f64b052017-12-14 14:26:15 -08005068 * Returns the {@link IImsRegistration} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005069 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger5f64b052017-12-14 14:26:15 -08005070 */
5071 public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException {
5072 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005073
5074 final long identity = Binder.clearCallingIdentity();
5075 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005076 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005077 // may happen if the device does not support IMS.
5078 return null;
5079 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005080 return mImsResolver.getImsRegistration(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005081 } finally {
5082 Binder.restoreCallingIdentity(identity);
5083 }
Brad Ebinger5f64b052017-12-14 14:26:15 -08005084 }
5085
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005086 /**
5087 * Returns the {@link IImsConfig} structure associated with the slotId and feature
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005088 * specified or null if IMS is not supported on the slot specified.
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005089 */
5090 public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException {
5091 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005092
5093 final long identity = Binder.clearCallingIdentity();
5094 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005095 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005096 // may happen if the device does not support IMS.
5097 return null;
5098 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005099 return mImsResolver.getImsConfig(slotId, feature);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005100 } finally {
5101 Binder.restoreCallingIdentity(identity);
5102 }
Brad Ebinger22bc3e42018-01-16 09:39:35 -08005103 }
5104
Brad Ebinger884c07b2018-02-15 16:17:40 -08005105 /**
Brad Ebingerdac2f002018-04-03 15:17:52 -07005106 * Sets the ImsService Package Name that Telephony will bind to.
5107 *
Brad Ebinger05f52c22019-12-05 13:03:21 -08005108 * @param slotIndex the slot ID that the ImsService should bind for.
5109 * @param isCarrierService true if the ImsService is the carrier override, false if the
Brad Ebingerdac2f002018-04-03 15:17:52 -07005110 * ImsService is the device default ImsService.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005111 * @param featureTypes An integer array of feature types associated with a packageName.
5112 * @param packageName The name of the package that the current configuration will be replaced
5113 * with.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005114 * @return true if setting the ImsService to bind to succeeded, false if it did not.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005115 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005116 public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
5117 int[] featureTypes, String packageName) {
5118 int[] subIds = SubscriptionManager.getSubId(slotIndex);
5119 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005120 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
5121 (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
Brad Ebinger05f52c22019-12-05 13:03:21 -08005122 "setBoundImsServiceOverride");
Brad Ebingerde696de2018-04-06 09:56:40 -07005123
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005124 final long identity = Binder.clearCallingIdentity();
5125 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005126 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005127 // may happen if the device does not support IMS.
5128 return false;
5129 }
Brad Ebinger05f52c22019-12-05 13:03:21 -08005130 Map<Integer, String> featureConfig = new HashMap<>();
5131 for (int featureType : featureTypes) {
5132 featureConfig.put(featureType, packageName);
5133 }
5134 return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService,
5135 featureConfig);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005136 } finally {
5137 Binder.restoreCallingIdentity(identity);
5138 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005139 }
5140
5141 /**
Brad Ebinger05f52c22019-12-05 13:03:21 -08005142 * Return the package name of the currently bound ImsService.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005143 *
5144 * @param slotId The slot that the ImsService is associated with.
5145 * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is
5146 * the device default.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005147 * @param featureType The feature associated with the queried configuration.
Brad Ebingerdac2f002018-04-03 15:17:52 -07005148 * @return the package name of the ImsService configuration.
5149 */
Brad Ebinger05f52c22019-12-05 13:03:21 -08005150 public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
5151 @ImsFeature.FeatureType int featureType) {
Brad Ebingerde696de2018-04-06 09:56:40 -07005152 int[] subIds = SubscriptionManager.getSubId(slotId);
Brad Ebinger05f52c22019-12-05 13:03:21 -08005153 TelephonyPermissions
5154 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5155 mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
5156 "getBoundImsServicePackage");
Brad Ebingerde696de2018-04-06 09:56:40 -07005157
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005158 final long identity = Binder.clearCallingIdentity();
5159 try {
Brad Ebinger05f52c22019-12-05 13:03:21 -08005160 if (mImsResolver == null) {
Brad Ebinger9c0eb502019-01-23 15:06:19 -08005161 // may happen if the device does not support IMS.
5162 return "";
5163 }
Brad Ebingera80c3312019-12-02 10:59:39 -08005164 // TODO: change API to query RCS separately.
Brad Ebinger05f52c22019-12-05 13:03:21 -08005165 return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService,
5166 featureType);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005167 } finally {
5168 Binder.restoreCallingIdentity(identity);
5169 }
Brad Ebingerdac2f002018-04-03 15:17:52 -07005170 }
5171
Brad Ebinger77b832e2019-10-17 17:03:22 -07005172 /**
5173 * Get the MmTelFeature state associated with the requested subscription id.
5174 * @param subId The subscription that the MmTelFeature is associated with.
5175 * @param callback A callback with an integer containing the
5176 * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature.
5177 */
5178 @Override
5179 public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) {
5180 enforceReadPrivilegedPermission("getImsMmTelFeatureState");
5181 if (!ImsManager.isImsSupportedOnDevice(mApp)) {
5182 throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION,
5183 "IMS not available on device.");
5184 }
5185 final long token = Binder.clearCallingIdentity();
5186 try {
5187 int slotId = getSlotIndex(subId);
5188 if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
5189 Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '"
5190 + subId + "'");
5191 throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION);
5192 }
5193 ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> {
5194 try {
5195 callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger);
5196 } catch (RemoteException e) {
5197 Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. "
5198 + "Ignore");
5199 }
5200 });
5201 } finally {
5202 Binder.restoreCallingIdentity(token);
5203 }
5204 }
5205
Wink Saville36469e72014-06-11 15:17:00 -07005206 public void setImsRegistrationState(boolean registered) {
5207 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005208
5209 final long identity = Binder.clearCallingIdentity();
5210 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005211 getDefaultPhone().setImsRegistrationState(registered);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005212 } finally {
5213 Binder.restoreCallingIdentity(identity);
5214 }
Wink Saville36469e72014-06-11 15:17:00 -07005215 }
5216
5217 /**
Stuart Scott54788802015-03-30 13:18:01 -07005218 * Set the network selection mode to automatic.
5219 *
5220 */
5221 @Override
5222 public void setNetworkSelectionModeAutomatic(int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005223 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5224 mApp, subId, "setNetworkSelectionModeAutomatic");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005225
5226 final long identity = Binder.clearCallingIdentity();
5227 try {
shilufc958392020-01-20 11:36:01 -08005228 if (!isActiveSubscription(subId)) {
5229 return;
5230 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005231 if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId);
5232 sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId);
5233 } finally {
5234 Binder.restoreCallingIdentity(identity);
5235 }
Stuart Scott54788802015-03-30 13:18:01 -07005236 }
5237
Pengquan Mengea84e042018-09-20 14:57:26 -07005238 /**
5239 * Ask the radio to connect to the input network and change selection mode to manual.
5240 *
5241 * @param subId the id of the subscription.
5242 * @param operatorInfo the operator information, included the PLMN, long name and short name of
5243 * the operator to attach to.
5244 * @param persistSelection whether the selection will persist until reboot. If true, only allows
5245 * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume
5246 * normal network selection next time.
5247 * @return {@code true} on success; {@code true} on any failure.
Shishir Agrawal302c8692015-06-19 13:49:39 -07005248 */
5249 @Override
Pengquan Mengea84e042018-09-20 14:57:26 -07005250 public boolean setNetworkSelectionModeManual(
5251 int subId, OperatorInfo operatorInfo, boolean persistSelection) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005252 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5253 mApp, subId, "setNetworkSelectionModeManual");
Pengquan Menge92a50d2018-09-21 15:54:48 -07005254
5255 if (!isActiveSubscription(subId)) {
5256 return false;
5257 }
5258
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005259 final long identity = Binder.clearCallingIdentity();
5260 try {
Pengquan Mengea84e042018-09-20 14:57:26 -07005261 ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005262 persistSelection);
Pengquan Mengea84e042018-09-20 14:57:26 -07005263 if (DBG) {
5264 log("setNetworkSelectionModeManual: subId: " + subId
5265 + " operator: " + operatorInfo);
5266 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005267 return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId);
5268 } finally {
5269 Binder.restoreCallingIdentity(identity);
5270 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005271 }
shilu84f6e8b2019-12-19 13:58:01 -08005272 /**
5273 * Get the manual network selection
5274 *
5275 * @param subId the id of the subscription.
5276 *
5277 * @return the previously saved user selected PLMN
5278 */
5279 @Override
5280 public String getManualNetworkSelectionPlmn(int subId) {
5281 TelephonyPermissions
5282 .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege(
5283 mApp, subId, "getManualNetworkSelectionPlmn");
5284
5285 final long identity = Binder.clearCallingIdentity();
5286 try {
5287 if (!isActiveSubscription(subId)) {
5288 return "";
5289 }
5290
5291 final Phone phone = getPhone(subId);
5292 if (phone == null) {
5293 return "";
5294 }
5295 OperatorInfo networkSelection = phone.getSavedNetworkSelection();
5296 return TextUtils.isEmpty(networkSelection.getOperatorNumeric())
5297 ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric();
5298 } finally {
5299 Binder.restoreCallingIdentity(identity);
5300 }
5301 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005302
5303 /**
5304 * Scans for available networks.
5305 */
5306 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005307 public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage,
5308 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005309 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5310 mApp, subId, "getCellNetworkScanResults");
Hall Liuf19c44f2018-11-27 14:38:17 -08005311 LocationAccessPolicy.LocationPermissionResult locationResult =
5312 LocationAccessPolicy.checkLocationPermission(mApp,
5313 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5314 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005315 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005316 .setCallingPid(Binder.getCallingPid())
5317 .setCallingUid(Binder.getCallingUid())
5318 .setMethod("getCellNetworkScanResults")
5319 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5320 .build());
5321 switch (locationResult) {
5322 case DENIED_HARD:
5323 throw new SecurityException("Not allowed to access scan results -- location");
5324 case DENIED_SOFT:
5325 return null;
5326 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005327
Pengquan Menga1bb6272018-09-06 09:59:22 -07005328 long identity = Binder.clearCallingIdentity();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005329 try {
5330 if (DBG) log("getCellNetworkScanResults: subId " + subId);
Pengquan Menga1bb6272018-09-06 09:59:22 -07005331 return (CellNetworkScanResult) sendRequest(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005332 CMD_PERFORM_NETWORK_SCAN, null, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005333 } finally {
5334 Binder.restoreCallingIdentity(identity);
5335 }
Shishir Agrawal302c8692015-06-19 13:49:39 -07005336 }
5337
5338 /**
sqian80370722020-01-29 15:02:51 -08005339 * Get the call forwarding info, given the call forwarding reason.
5340 */
5341 @Override
5342 public CallForwardingInfo getCallForwarding(int subId, int callForwardingReason) {
5343 enforceReadPrivilegedPermission("getCallForwarding");
5344 long identity = Binder.clearCallingIdentity();
5345 try {
5346 if (DBG) {
5347 log("getCallForwarding: subId " + subId
5348 + " callForwardingReason" + callForwardingReason);
5349 }
5350 return (CallForwardingInfo) sendRequest(
5351 CMD_GET_CALL_FORWARDING, callForwardingReason, subId);
5352 } finally {
5353 Binder.restoreCallingIdentity(identity);
5354 }
5355 }
5356
5357 /**
5358 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5359 * reason, the number to forward, and the timeout before the forwarding is attempted.
5360 */
5361 @Override
5362 public boolean setCallForwarding(int subId, CallForwardingInfo callForwardingInfo) {
5363 enforceModifyPermission();
5364 long identity = Binder.clearCallingIdentity();
5365 try {
5366 if (DBG) {
5367 log("setCallForwarding: subId " + subId
5368 + " callForwardingInfo" + callForwardingInfo);
5369 }
5370 return (Boolean) sendRequest(CMD_SET_CALL_FORWARDING, callForwardingInfo, subId);
5371 } finally {
5372 Binder.restoreCallingIdentity(identity);
5373 }
5374 }
5375
5376 /**
5377 * Get the call forwarding info, given the call forwarding reason.
5378 */
5379 @Override
5380 public int getCallWaitingStatus(int subId) {
5381 enforceReadPrivilegedPermission("getCallForwarding");
5382 long identity = Binder.clearCallingIdentity();
5383 try {
5384 if (DBG) log("getCallWaitingStatus: subId " + subId);
5385 return (Integer) sendRequest(CMD_GET_CALL_WAITING, null, subId);
5386 } finally {
5387 Binder.restoreCallingIdentity(identity);
5388 }
5389 }
5390
5391 /**
5392 * Sets the voice call forwarding info including status (enable/disable), call forwarding
5393 * reason, the number to forward, and the timeout before the forwarding is attempted.
5394 */
5395 @Override
5396 public boolean setCallWaitingStatus(int subId, boolean isEnable) {
5397 enforceModifyPermission();
5398 long identity = Binder.clearCallingIdentity();
5399 try {
5400 if (DBG) log("setCallWaitingStatus: subId " + subId + " isEnable: " + isEnable);
5401 return (Boolean) sendRequest(CMD_SET_CALL_WAITING, isEnable, subId);
5402 } finally {
5403 Binder.restoreCallingIdentity(identity);
5404 }
5405 }
5406
5407 /**
yinxub1bed742017-04-17 11:45:04 -07005408 * Starts a new network scan and returns the id of this scan.
yinxu504e1392017-04-12 16:03:22 -07005409 *
yinxub1bed742017-04-17 11:45:04 -07005410 * @param subId id of the subscription
5411 * @param request contains the radio access networks with bands/channels to scan
5412 * @param messenger callback messenger for scan results or errors
5413 * @param binder for the purpose of auto clean when the user thread crashes
yinxu504e1392017-04-12 16:03:22 -07005414 * @return the id of the requested scan which can be used to stop the scan.
5415 */
5416 @Override
5417 public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005418 IBinder binder, String callingPackage, String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005419 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5420 mApp, subId, "requestNetworkScan");
Hall Liuf19c44f2018-11-27 14:38:17 -08005421 LocationAccessPolicy.LocationPermissionResult locationResult =
5422 LocationAccessPolicy.checkLocationPermission(mApp,
5423 new LocationAccessPolicy.LocationPermissionQuery.Builder()
5424 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005425 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08005426 .setCallingPid(Binder.getCallingPid())
5427 .setCallingUid(Binder.getCallingUid())
5428 .setMethod("requestNetworkScan")
5429 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
5430 .build());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005431 if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) {
Hall Liu558027f2019-05-15 19:14:05 -07005432 SecurityException e = checkNetworkRequestForSanitizedLocationAccess(request, subId);
Hall Liub2ac8ef2019-02-28 15:56:23 -08005433 if (e != null) {
5434 if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) {
5435 throw e;
5436 } else {
Hall Liu0e5abaf2019-04-04 01:25:30 -07005437 loge(e.getMessage());
Hall Liub2ac8ef2019-02-28 15:56:23 -08005438 return TelephonyScanManager.INVALID_SCAN_ID;
5439 }
5440 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005441 }
Hall Liu912dfd32019-04-25 14:02:26 -07005442 int callingUid = Binder.getCallingUid();
5443 int callingPid = Binder.getCallingPid();
Ying Xu94a46582019-04-18 17:14:56 -07005444 final long identity = Binder.clearCallingIdentity();
5445 try {
5446 return mNetworkScanRequestTracker.startNetworkScan(
5447 request, messenger, binder, getPhone(subId),
Hall Liu912dfd32019-04-25 14:02:26 -07005448 callingUid, callingPid, callingPackage);
Ying Xu94a46582019-04-18 17:14:56 -07005449 } finally {
5450 Binder.restoreCallingIdentity(identity);
5451 }
yinxu504e1392017-04-12 16:03:22 -07005452 }
5453
Hall Liub2ac8ef2019-02-28 15:56:23 -08005454 private SecurityException checkNetworkRequestForSanitizedLocationAccess(
Hall Liu558027f2019-05-15 19:14:05 -07005455 NetworkScanRequest request, int subId) {
5456 boolean hasCarrierPriv = getCarrierPrivilegeStatusForUid(subId, Binder.getCallingUid())
5457 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5458 boolean hasNetworkScanPermission =
5459 mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN)
5460 == PERMISSION_GRANTED;
5461
5462 if (!hasCarrierPriv && !hasNetworkScanPermission) {
5463 return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed"
5464 + " for network scans without location access.");
Hall Liub2ac8ef2019-02-28 15:56:23 -08005465 }
5466
5467 if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) {
5468 for (RadioAccessSpecifier ras : request.getSpecifiers()) {
Hall Liub2ac8ef2019-02-28 15:56:23 -08005469 if (ras.getChannels() != null && ras.getChannels().length > 0) {
5470 return new SecurityException("Specific channels must not be"
5471 + " scanned without location access.");
5472 }
5473 }
5474 }
5475
Hall Liub2ac8ef2019-02-28 15:56:23 -08005476 return null;
5477 }
5478
yinxu504e1392017-04-12 16:03:22 -07005479 /**
5480 * Stops an existing network scan with the given scanId.
yinxub1bed742017-04-17 11:45:04 -07005481 *
5482 * @param subId id of the subscription
5483 * @param scanId id of the scan that needs to be stopped
yinxu504e1392017-04-12 16:03:22 -07005484 */
5485 @Override
5486 public void stopNetworkScan(int subId, int scanId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005487 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5488 mApp, subId, "stopNetworkScan");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005489
Hall Liu912dfd32019-04-25 14:02:26 -07005490 int callingUid = Binder.getCallingUid();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005491 final long identity = Binder.clearCallingIdentity();
5492 try {
Hall Liu912dfd32019-04-25 14:02:26 -07005493 mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005494 } finally {
5495 Binder.restoreCallingIdentity(identity);
5496 }
yinxu504e1392017-04-12 16:03:22 -07005497 }
5498
5499 /**
Junda Liu84d15a22014-07-02 11:21:04 -07005500 * Get the calculated preferred network type.
5501 * Used for debugging incorrect network type.
5502 *
5503 * @return the preferred network type, defined in RILConstants.java.
5504 */
5505 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005506 public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005507 final Phone defaultPhone = getDefaultPhone();
5508 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08005509 callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) {
Svet Ganovb320e182015-04-16 12:30:10 -07005510 return RILConstants.PREFERRED_NETWORK_MODE;
5511 }
5512
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005513 final long identity = Binder.clearCallingIdentity();
5514 try {
5515 // FIXME: need to get SubId from somewhere.
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005516 return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005517 } finally {
5518 Binder.restoreCallingIdentity(identity);
5519 }
Junda Liu84d15a22014-07-02 11:21:04 -07005520 }
5521
5522 /**
Jake Hamby7c27be32014-03-03 13:25:59 -08005523 * Get the preferred network type.
5524 * Used for device configuration by some CDMA operators.
5525 *
5526 * @return the preferred network type, defined in RILConstants.java.
5527 */
5528 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005529 public int getPreferredNetworkType(int subId) {
Pengquan Menga4009cb2018-12-20 11:00:24 -08005530 TelephonyPermissions
5531 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5532 mApp, subId, "getPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005533
5534 final long identity = Binder.clearCallingIdentity();
5535 try {
5536 if (DBG) log("getPreferredNetworkType");
5537 int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId);
5538 int networkType = (result != null ? result[0] : -1);
5539 if (DBG) log("getPreferredNetworkType: " + networkType);
5540 return networkType;
5541 } finally {
5542 Binder.restoreCallingIdentity(identity);
5543 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005544 }
5545
5546 /**
5547 * Set the preferred network type.
Jake Hamby7c27be32014-03-03 13:25:59 -08005548 *
5549 * @param networkType the preferred network type, defined in RILConstants.java.
5550 * @return true on success; false on any failure.
5551 */
5552 @Override
Stuart Scott54788802015-03-30 13:18:01 -07005553 public boolean setPreferredNetworkType(int subId, int networkType) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005554 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5555 mApp, subId, "setPreferredNetworkType");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005556
5557 final long identity = Binder.clearCallingIdentity();
5558 try {
calvinpan677fc2b2020-01-14 20:42:55 +08005559 Settings.Global.putInt(mApp.getContentResolver(),
5560 Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType);
calvinpan089c2a62020-03-12 14:17:55 +08005561
5562 Boolean success = (Boolean) sendRequest(
5563 CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId);
5564 if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail"));
5565 return success;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005566 } finally {
5567 Binder.restoreCallingIdentity(identity);
Junda Liu80bc0d12014-07-14 16:36:44 -07005568 }
Jake Hamby7c27be32014-03-03 13:25:59 -08005569 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005570
5571 /**
calvinpan677fc2b2020-01-14 20:42:55 +08005572 * Get the allowed network types that store in the telephony provider.
5573 *
5574 * @param subId the id of the subscription.
5575 * @return allowedNetworkTypes the allowed network types.
5576 */
5577 @Override
5578 public long getAllowedNetworkTypes(int subId) {
5579 TelephonyPermissions
5580 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5581 mApp, subId, "getAllowedNetworkTypes");
5582
5583 final long identity = Binder.clearCallingIdentity();
5584 try {
5585 return SubscriptionManager.getLongSubscriptionProperty(
5586 subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp);
5587 } finally {
5588 Binder.restoreCallingIdentity(identity);
5589 }
5590 }
5591
5592 /**
5593 * Set the allowed network types.
5594 *
5595 * @param subId the id of the subscription.
5596 * @param allowedNetworkTypes the allowed network types.
5597 * @return true on success; false on any failure.
5598 */
5599 @Override
5600 public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) {
5601 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5602 mApp, subId, "setAllowedNetworkTypes");
calvinpan677fc2b2020-01-14 20:42:55 +08005603
calvinpan089c2a62020-03-12 14:17:55 +08005604 SubscriptionManager.setSubscriptionProperty(subId,
5605 SubscriptionManager.ALLOWED_NETWORK_TYPES,
5606 String.valueOf(allowedNetworkTypes));
calvinpan677fc2b2020-01-14 20:42:55 +08005607
calvinpan089c2a62020-03-12 14:17:55 +08005608 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5609 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5610 RILConstants.PREFERRED_NETWORK_MODE);
5611 return setPreferredNetworkType(subId, preferredNetworkMode);
calvinpan677fc2b2020-01-14 20:42:55 +08005612 }
5613
5614 /**
Sooraj Sasindran9e2be4e2020-06-03 01:06:00 -07005615 * Get the allowed network types for certain reason.
5616 *
5617 * @param subId the id of the subscription.
5618 * @param reason the reason the allowed network type change is taking place
5619 * @return the allowed network types.
5620 */
5621 @Override
5622 public long getAllowedNetworkTypesForReason(int subId,
5623 @TelephonyManager.AllowedNetworkTypesReason int reason) {
5624 TelephonyPermissions
5625 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5626 mApp, subId, "getAllowedNetworkTypesForReason");
5627 final long identity = Binder.clearCallingIdentity();
5628 try {
5629 return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason);
5630 } finally {
5631 Binder.restoreCallingIdentity(identity);
5632 }
5633 }
5634
5635 /**
5636 * Get the effective allowed network types on the device.
5637 * This API will return an intersection of allowed network types for all reasons,
5638 * including the configuration done through setAllowedNetworkTypes
5639 *
5640 * @param subId the id of the subscription.
5641 * @return the allowed network types
5642 */
5643 @Override
5644 public long getEffectiveAllowedNetworkTypes(int subId) {
5645 TelephonyPermissions
5646 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
5647 mApp, subId, "getEffectiveAllowedNetworkTypes");
5648 final long identity = Binder.clearCallingIdentity();
5649 try {
5650 return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes();
5651 } finally {
5652 Binder.restoreCallingIdentity(identity);
5653 }
5654 }
5655
5656 /**
5657 * Set the allowed network types of the device and
5658 * provide the reason triggering the allowed network change.
5659 *
5660 * @param subId the id of the subscription.
5661 * @param reason the reason the allowed network type change is taking place
5662 * @param allowedNetworkTypes the allowed network types.
5663 * @return true on success; false on any failure.
5664 */
5665 @Override
5666 public boolean setAllowedNetworkTypesForReason(int subId,
5667 @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) {
5668 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5669 mApp, subId, "setAllowedNetworkTypesForReason");
5670 final long identity = Binder.clearCallingIdentity();
5671 try {
5672 getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes);
5673 int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(),
5674 Settings.Global.PREFERRED_NETWORK_MODE + subId,
5675 RILConstants.PREFERRED_NETWORK_MODE);
5676 return setPreferredNetworkType(subId, preferredNetworkMode);
5677 } finally {
5678 Binder.restoreCallingIdentity(identity);
5679 }
5680 }
5681
5682 /**
Miaoa84611c2019-03-15 09:21:10 +08005683 * Check whether DUN APN is required for tethering with subId.
Junda Liu475951f2014-11-07 16:45:03 -08005684 *
Miaoa84611c2019-03-15 09:21:10 +08005685 * @param subId the id of the subscription to require tethering.
Amit Mahajanfe58cdf2017-07-11 12:01:53 -07005686 * @return {@code true} if DUN APN is required for tethering.
Junda Liu475951f2014-11-07 16:45:03 -08005687 * @hide
5688 */
5689 @Override
SongFerngWangf08d8122019-11-15 14:58:44 +08005690 public boolean isTetheringApnRequiredForSubscriber(int subId) {
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005691 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005692 final long identity = Binder.clearCallingIdentity();
Miaoa84611c2019-03-15 09:21:10 +08005693 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005694 try {
Miaoa84611c2019-03-15 09:21:10 +08005695 if (phone != null) {
5696 return phone.hasMatchedTetherApnSetting();
5697 } else {
5698 return false;
5699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005700 } finally {
5701 Binder.restoreCallingIdentity(identity);
Junda Liu475951f2014-11-07 16:45:03 -08005702 }
Junda Liu475951f2014-11-07 16:45:03 -08005703 }
5704
5705 /**
Robert Greenwalted86e582014-05-21 20:03:20 -07005706 * Set mobile data enabled
5707 * Used by the user through settings etc to turn on/off mobile data
5708 *
5709 * @param enable {@code true} turn turn data on, else {@code false}
5710 */
5711 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005712 public void setUserDataEnabled(int subId, boolean enable) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005713 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5714 mApp, subId, "setUserDataEnabled");
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("setUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5720 Phone phone = PhoneFactory.getPhone(phoneId);
5721 if (phone != null) {
5722 if (DBG) log("setUserDataEnabled: subId=" + subId + " enable=" + enable);
Jack Yud79fba22018-12-13 11:51:28 -08005723 phone.getDataEnabledSettings().setUserDataEnabled(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005724 } else {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005725 loge("setUserDataEnabled: no phone found. Invalid subId=" + subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005726 }
5727 } finally {
5728 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005729 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005730 }
5731
5732 /**
Shuo Qian5bac1ee2020-01-16 20:51:11 -08005733 * Enable or disable always reporting signal strength changes from radio.
5734 *
5735 * @param isEnable {@code true} for enabling; {@code false} for disabling.
5736 */
5737 @Override
5738 public void setAlwaysReportSignalStrength(int subId, boolean isEnable) {
5739 enforceModifyPermission();
5740 enforceSystemCaller();
5741
5742 final long identity = Binder.clearCallingIdentity();
5743 final Phone phone = getPhone(subId);
5744 try {
5745 if (phone != null) {
5746 if (DBG) {
5747 log("setAlwaysReportSignalStrength: subId=" + subId
5748 + " isEnable=" + isEnable);
5749 }
5750 phone.setAlwaysReportSignalStrength(isEnable);
5751 } else {
5752 loge("setAlwaysReportSignalStrength: no phone found for subId="
5753 + subId);
5754 }
5755 } finally {
5756 Binder.restoreCallingIdentity(identity);
5757 }
5758 }
5759
5760 /**
Malcolm Chen964682d2017-11-28 16:20:07 -08005761 * Get the user enabled state of Mobile Data.
5762 *
5763 * TODO: remove and use isUserDataEnabled.
5764 * This can't be removed now because some vendor codes
5765 * calls through ITelephony directly while they should
5766 * use TelephonyManager.
5767 *
5768 * @return true on enabled
5769 */
5770 @Override
5771 public boolean getDataEnabled(int subId) {
5772 return isUserDataEnabled(subId);
5773 }
5774
5775 /**
5776 * Get whether mobile data is enabled per user setting.
5777 *
5778 * There are other factors deciding whether mobile data is actually enabled, but they are
5779 * not considered here. See {@link #isDataEnabled(int)} for more details.
Robert Greenwalt646120a2014-05-23 11:54:03 -07005780 *
Jeff Davidsona1920712016-11-18 17:05:56 -08005781 * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges.
Robert Greenwalted86e582014-05-21 20:03:20 -07005782 *
5783 * @return {@code true} if data is enabled else {@code false}
5784 */
5785 @Override
Malcolm Chen964682d2017-11-28 16:20:07 -08005786 public boolean isUserDataEnabled(int subId) {
Robert Greenwalt646120a2014-05-23 11:54:03 -07005787 try {
5788 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
5789 null);
5790 } catch (Exception e) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08005791 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
5792 mApp, subId, "isUserDataEnabled");
Robert Greenwalt646120a2014-05-23 11:54:03 -07005793 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005794
5795 final long identity = Binder.clearCallingIdentity();
5796 try {
5797 int phoneId = mSubscriptionController.getPhoneId(subId);
5798 if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5799 Phone phone = PhoneFactory.getPhone(phoneId);
5800 if (phone != null) {
5801 boolean retVal = phone.isUserDataEnabled();
5802 if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal);
5803 return retVal;
5804 } else {
5805 if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false");
5806 return false;
5807 }
5808 } finally {
5809 Binder.restoreCallingIdentity(identity);
Malcolm Chen964682d2017-11-28 16:20:07 -08005810 }
5811 }
5812
5813 /**
Shuo Qian985d1232020-01-08 14:30:06 -08005814 * Checks if the device is capable of mobile data by considering whether whether the
5815 * user has enabled mobile data, whether the carrier has enabled mobile data, and
5816 * whether the network policy allows data connections.
Malcolm Chen964682d2017-11-28 16:20:07 -08005817 *
Shuo Qian985d1232020-01-08 14:30:06 -08005818 * @return {@code true} if the overall data connection is capable; {@code false} if not.
Malcolm Chen964682d2017-11-28 16:20:07 -08005819 */
5820 @Override
5821 public boolean isDataEnabled(int subId) {
Shuo Qian985d1232020-01-08 14:30:06 -08005822 enforceReadPrivilegedPermission("isDataEnabled");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005823
5824 final long identity = Binder.clearCallingIdentity();
5825 try {
5826 int phoneId = mSubscriptionController.getPhoneId(subId);
5827 if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId);
5828 Phone phone = PhoneFactory.getPhone(phoneId);
5829 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08005830 boolean retVal = phone.getDataEnabledSettings().isDataEnabled();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08005831 if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal);
5832 return retVal;
5833 } else {
5834 if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false");
5835 return false;
5836 }
5837 } finally {
5838 Binder.restoreCallingIdentity(identity);
Wink Savillee7353bb2014-12-05 14:21:41 -08005839 }
Robert Greenwalted86e582014-05-21 20:03:20 -07005840 }
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005841
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005842 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid,
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005843 Phone phone) {
Hall Liuce478d22020-07-13 12:13:03 -07005844 if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) {
5845 // Skip the check if it's one of these special uids
5846 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5847 }
5848
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005849 //load access rules from carrier configs, and check those as well: b/139133814
5850 SubscriptionController subController = SubscriptionController.getInstance();
5851 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5852 || subController == null) return privilegeFromSim;
5853
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005854 PackageManager pkgMgr = phone.getContext().getPackageManager();
5855 String[] packages = pkgMgr.getPackagesForUid(uid);
5856
5857 final long identity = Binder.clearCallingIdentity();
5858 try {
5859 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5860 SubscriptionManager subManager = (SubscriptionManager)
5861 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5862 for (String pkg : packages) {
5863 if (subManager.canManageSubscription(subInfo, pkg)) {
5864 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
5865 }
5866 }
5867 return privilegeFromSim;
5868 } finally {
5869 Binder.restoreCallingIdentity(identity);
5870 }
5871 }
5872
5873 private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone,
5874 String pkgName) {
5875 //load access rules from carrier configs, and check those as well: b/139133814
5876 SubscriptionController subController = SubscriptionController.getInstance();
5877 if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS
5878 || subController == null) return privilegeFromSim;
5879
5880 final long identity = Binder.clearCallingIdentity();
5881 try {
5882 SubscriptionInfo subInfo = subController.getSubscriptionInfo(phone.getSubId());
5883 SubscriptionManager subManager = (SubscriptionManager)
5884 phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
5885 return subManager.canManageSubscription(subInfo, pkgName)
5886 ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim;
5887 } finally {
5888 Binder.restoreCallingIdentity(identity);
5889 }
5890 }
5891
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005892 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08005893 public int getCarrierPrivilegeStatus(int subId) {
5894 final Phone phone = getPhone(subId);
5895 if (phone == null) {
5896 loge("getCarrierPrivilegeStatus: Invalid subId");
5897 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5898 }
5899 UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId());
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005900 if (card == null) {
Shishir Agrawal5e5becd2014-11-18 11:38:23 -08005901 loge("getCarrierPrivilegeStatus: No UICC");
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005902 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5903 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005904
5905 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5906 card.getCarrierPrivilegeStatusForCurrentTransaction(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005907 phone.getContext().getPackageManager()), Binder.getCallingUid(), phone);
Shishir Agrawal60f9c952014-06-23 12:00:43 -07005908 }
Junda Liu29340342014-07-10 15:23:27 -07005909
5910 @Override
Jeff Davidson7e17e312018-02-13 18:17:36 -08005911 public int getCarrierPrivilegeStatusForUid(int subId, int uid) {
Shuo Qian6d927452019-12-05 11:40:37 -08005912 enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005913 final Phone phone = getPhone(subId);
5914 if (phone == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005915 loge("getCarrierPrivilegeStatusForUid: Invalid subId");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005916 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
5917 }
5918 UiccProfile profile =
5919 UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId());
5920 if (profile == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005921 loge("getCarrierPrivilegeStatusForUid: No UICC");
Jeff Davidson7e17e312018-02-13 18:17:36 -08005922 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5923 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005924 return getCarrierPrivilegeStatusFromCarrierConfigRules(
Shuo Qian6d927452019-12-05 11:40:37 -08005925 profile.getCarrierPrivilegeStatusForUid(
Malcolm Chendf0b4cc2020-02-24 15:12:43 -08005926 phone.getContext().getPackageManager(), uid), uid, phone);
Jeff Davidson7e17e312018-02-13 18:17:36 -08005927 }
5928
5929 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005930 public int checkCarrierPrivilegesForPackage(int subId, String pkgName) {
5931 if (TextUtils.isEmpty(pkgName)) {
Junda Liu317d70b2016-03-08 09:33:53 -08005932 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
chen xuf7e9fe82019-05-09 19:31:02 -07005933 }
5934
5935 int phoneId = SubscriptionManager.getPhoneId(subId);
5936 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005937 if (card == null) {
chen xuf7e9fe82019-05-09 19:31:02 -07005938 loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId);
Shishir Agrawaleb8771e2014-07-22 11:24:08 -07005939 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5940 }
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005941 return getCarrierPrivilegeStatusFromCarrierConfigRules(
5942 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5943 getPhone(phoneId), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005944 }
5945
5946 @Override
5947 public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) {
Junda Liu317d70b2016-03-08 09:33:53 -08005948 if (TextUtils.isEmpty(pkgName))
5949 return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS;
Zach Johnson50ecba32015-05-19 00:24:21 -07005950 int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED;
5951 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
5952 UiccCard card = UiccController.getInstance().getUiccCard(i);
5953 if (card == null) {
Jonathan Basseri7d320df2015-06-16 12:17:08 -07005954 // No UICC in that slot.
Zach Johnson50ecba32015-05-19 00:24:21 -07005955 continue;
5956 }
5957
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005958 result = getCarrierPrivilegeStatusFromCarrierConfigRules(
5959 card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName),
5960 getPhone(i), pkgName);
Zach Johnson50ecba32015-05-19 00:24:21 -07005961 if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
5962 break;
5963 }
5964 }
5965
5966 return result;
Junda Liu29340342014-07-10 15:23:27 -07005967 }
Derek Tan89e89d42014-07-08 17:00:10 -07005968
5969 @Override
Junda Liue64de782015-04-16 17:19:16 -07005970 public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) {
5971 if (!SubscriptionManager.isValidPhoneId(phoneId)) {
5972 loge("phoneId " + phoneId + " is not valid.");
5973 return null;
5974 }
5975 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005976 if (card == null) {
Taesu Leef8fbed92019-10-07 18:47:02 +09005977 loge("getCarrierPackageNamesForIntentAndPhone: No UICC");
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005978 return null ;
5979 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005980 return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent);
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07005981 }
5982
Amith Yamasani6e118872016-02-19 12:53:51 -08005983 @Override
chen xuf7e9fe82019-05-09 19:31:02 -07005984 public List<String> getPackagesWithCarrierPrivileges(int phoneId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08005985 PackageManager pm = mApp.getPackageManager();
Amith Yamasani6e118872016-02-19 12:53:51 -08005986 List<String> privilegedPackages = new ArrayList<>();
5987 List<PackageInfo> packages = null;
chen xuf7e9fe82019-05-09 19:31:02 -07005988 UiccCard card = UiccController.getInstance().getUiccCard(phoneId);
5989 // has UICC in that slot.
5990 if (card != null) {
Amith Yamasani6e118872016-02-19 12:53:51 -08005991 if (card.hasCarrierPrivilegeRules()) {
5992 if (packages == null) {
5993 // Only check packages in user 0 for now
5994 packages = pm.getInstalledPackagesAsUser(
Nazanin Bakhshi5d0636e2019-08-19 16:29:37 -07005995 PackageManager.MATCH_DISABLED_COMPONENTS
5996 | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS
Cheonho Park17089c62019-08-01 15:23:12 +09005997 | PackageManager.GET_SIGNING_CERTIFICATES,
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08005998 UserHandle.SYSTEM.getIdentifier());
Amith Yamasani6e118872016-02-19 12:53:51 -08005999 }
6000 for (int p = packages.size() - 1; p >= 0; p--) {
6001 PackageInfo pkgInfo = packages.get(p);
6002 if (pkgInfo != null && pkgInfo.packageName != null
6003 && card.getCarrierPrivilegeStatus(pkgInfo)
chen xuf7e9fe82019-05-09 19:31:02 -07006004 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Amith Yamasani6e118872016-02-19 12:53:51 -08006005 privilegedPackages.add(pkgInfo.packageName);
6006 }
6007 }
6008 }
6009 }
6010 return privilegedPackages;
6011 }
6012
chen xuf7e9fe82019-05-09 19:31:02 -07006013 @Override
6014 public List<String> getPackagesWithCarrierPrivilegesForAllPhones() {
Shuo Qiand54f9f32019-12-03 23:40:18 +00006015 enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones");
6016
6017 final long identity = Binder.clearCallingIdentity();
6018
chen xuf7e9fe82019-05-09 19:31:02 -07006019 List<String> privilegedPackages = new ArrayList<>();
Shuo Qiand54f9f32019-12-03 23:40:18 +00006020 try {
6021 for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) {
6022 privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i));
6023 }
6024 } finally {
6025 Binder.restoreCallingIdentity(identity);
chen xuf7e9fe82019-05-09 19:31:02 -07006026 }
6027 return privilegedPackages;
6028 }
6029
Wink Savilleb564aae2014-10-23 10:18:09 -07006030 private String getIccId(int subId) {
Sanket Padawe356d7632015-06-22 14:03:32 -07006031 final Phone phone = getPhone(subId);
6032 UiccCard card = phone == null ? null : phone.getUiccCard();
Derek Tan97ebb422014-09-05 16:55:38 -07006033 if (card == null) {
6034 loge("getIccId: No UICC");
6035 return null;
6036 }
6037 String iccId = card.getIccId();
6038 if (TextUtils.isEmpty(iccId)) {
6039 loge("getIccId: ICC ID is null or empty.");
6040 return null;
6041 }
6042 return iccId;
6043 }
6044
Shishir Agrawaleb6439a2014-07-21 13:19:38 -07006045 @Override
Jeff Sharkey85190e62014-12-05 09:40:12 -08006046 public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag,
6047 String number) {
Shuo Qian6d927452019-12-05 11:40:37 -08006048 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006049 subId, "setLine1NumberForDisplayForSubscriber");
Derek Tan97ebb422014-09-05 16:55:38 -07006050
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006051 final long identity = Binder.clearCallingIdentity();
6052 try {
6053 final String iccId = getIccId(subId);
6054 final Phone phone = getPhone(subId);
6055 if (phone == null) {
6056 return false;
6057 }
6058 final String subscriberId = phone.getSubscriberId();
6059
6060 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006061 Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId="
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006062 + subscriberId + " to " + number);
6063 }
6064
6065 if (TextUtils.isEmpty(iccId)) {
6066 return false;
6067 }
6068
6069 final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit();
6070
6071 final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6072 if (alphaTag == null) {
6073 editor.remove(alphaTagPrefKey);
6074 } else {
6075 editor.putString(alphaTagPrefKey, alphaTag);
6076 }
6077
6078 // Record both the line number and IMSI for this ICCID, since we need to
6079 // track all merged IMSIs based on line number
6080 final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6081 final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6082 if (number == null) {
6083 editor.remove(numberPrefKey);
6084 editor.remove(subscriberPrefKey);
6085 } else {
6086 editor.putString(numberPrefKey, number);
6087 editor.putString(subscriberPrefKey, subscriberId);
6088 }
6089
6090 editor.commit();
6091 return true;
6092 } finally {
6093 Binder.restoreCallingIdentity(identity);
Sanket Padawe356d7632015-06-22 14:03:32 -07006094 }
Derek Tan7226c842014-07-02 17:42:23 -07006095 }
6096
6097 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006098 public String getLine1NumberForDisplay(int subId, String callingPackage,
6099 String callingFeatureId) {
Makoto Onukifee69342015-06-29 14:44:50 -07006100 // This is open to apps with WRITE_SMS.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006101 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006102 mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) {
Amit Mahajan9cf11512015-11-09 11:40:48 -08006103 if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission");
Svet Ganovb320e182015-04-16 12:30:10 -07006104 return null;
6105 }
Derek Tan97ebb422014-09-05 16:55:38 -07006106
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006107 final long identity = Binder.clearCallingIdentity();
6108 try {
6109 String iccId = getIccId(subId);
6110 if (iccId != null) {
6111 String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6112 if (DBG_MERGE) {
6113 log("getLine1NumberForDisplay returning "
6114 + mTelephonySharedPreferences.getString(numberPrefKey, null));
6115 }
6116 return mTelephonySharedPreferences.getString(numberPrefKey, null);
Amit Mahajan9cf11512015-11-09 11:40:48 -08006117 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006118 if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null");
6119 return null;
6120 } finally {
6121 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006122 }
Derek Tan7226c842014-07-02 17:42:23 -07006123 }
6124
6125 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006126 public String getLine1AlphaTagForDisplay(int subId, String callingPackage,
6127 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006128 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006129 mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) {
Svet Ganovb320e182015-04-16 12:30:10 -07006130 return null;
6131 }
Derek Tan97ebb422014-09-05 16:55:38 -07006132
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006133 final long identity = Binder.clearCallingIdentity();
6134 try {
6135 String iccId = getIccId(subId);
6136 if (iccId != null) {
6137 String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId;
6138 return mTelephonySharedPreferences.getString(alphaTagPrefKey, null);
6139 }
6140 return null;
6141 } finally {
6142 Binder.restoreCallingIdentity(identity);
Derek Tan7226c842014-07-02 17:42:23 -07006143 }
Derek Tan7226c842014-07-02 17:42:23 -07006144 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006145
6146 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006147 public String[] getMergedSubscriberIds(int subId, String callingPackage,
6148 String callingFeatureId) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006149 // This API isn't public, so no need to provide a valid subscription ID - we're not worried
6150 // about carrier-privileged callers not having access.
Jeff Davidson7e17e312018-02-13 18:17:36 -08006151 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Jeff Davidson913390f2018-02-23 17:11:49 -08006152 mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006153 callingFeatureId, "getMergedSubscriberIds")) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006154 return null;
6155 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006156
Jordan Liub49b04b2019-05-06 14:45:15 -07006157 // Clear calling identity, when calling TelephonyManager, because callerUid must be
6158 // the process, where TelephonyManager was instantiated.
6159 // Otherwise AppOps check will fail.
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006160 final long identity = Binder.clearCallingIdentity();
6161 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006162 final Context context = mApp;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006163 final TelephonyManager tele = TelephonyManager.from(context);
6164 final SubscriptionManager sub = SubscriptionManager.from(context);
6165
6166 // Figure out what subscribers are currently active
6167 final ArraySet<String> activeSubscriberIds = new ArraySet<>();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006168
Jordan Liub49b04b2019-05-06 14:45:15 -07006169 // Only consider subs which match the current subId
6170 // This logic can be simplified. See b/131189269 for progress.
6171 if (isActiveSubscription(subId)) {
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006172 activeSubscriberIds.add(tele.getSubscriberId(subId));
6173 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006174
6175 // First pass, find a number override for an active subscriber
6176 String mergeNumber = null;
6177 final Map<String, ?> prefs = mTelephonySharedPreferences.getAll();
6178 for (String key : prefs.keySet()) {
6179 if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) {
6180 final String subscriberId = (String) prefs.get(key);
6181 if (activeSubscriberIds.contains(subscriberId)) {
6182 final String iccId = key.substring(
6183 PREF_CARRIERS_SUBSCRIBER_PREFIX.length());
6184 final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId;
6185 mergeNumber = (String) prefs.get(numberKey);
6186 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006187 Rlog.d(LOG_TAG, "Found line number " + mergeNumber
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006188 + " for active subscriber " + subscriberId);
6189 }
6190 if (!TextUtils.isEmpty(mergeNumber)) {
6191 break;
6192 }
6193 }
6194 }
6195 }
6196
6197 // Shortcut when no active merged subscribers
6198 if (TextUtils.isEmpty(mergeNumber)) {
6199 return null;
6200 }
6201
6202 // Second pass, find all subscribers under that line override
6203 final ArraySet<String> result = new ArraySet<>();
6204 for (String key : prefs.keySet()) {
6205 if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) {
6206 final String number = (String) prefs.get(key);
6207 if (mergeNumber.equals(number)) {
6208 final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length());
6209 final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId;
6210 final String subscriberId = (String) prefs.get(subscriberKey);
6211 if (!TextUtils.isEmpty(subscriberId)) {
6212 result.add(subscriberId);
6213 }
6214 }
6215 }
6216 }
6217
6218 final String[] resultArray = result.toArray(new String[result.size()]);
6219 Arrays.sort(resultArray);
6220 if (DBG_MERGE) {
Amit Mahajan98bbd6e2020-01-27 18:16:07 -08006221 Rlog.d(LOG_TAG,
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006222 "Found subscribers " + Arrays.toString(resultArray) + " after merge");
6223 }
6224 return resultArray;
Fyodor Kupolov8e53b0b2015-06-17 13:17:50 -07006225 } finally {
6226 Binder.restoreCallingIdentity(identity);
Jeff Sharkey85190e62014-12-05 09:40:12 -08006227 }
Jeff Sharkey85190e62014-12-05 09:40:12 -08006228 }
6229
6230 @Override
zoey chen38003472019-12-13 17:16:31 +08006231 public String[] getMergedImsisFromGroup(int subId, String callingPackage) {
6232 enforceReadPrivilegedPermission("getMergedImsisFromGroup");
Malcolm Chen6ca97372019-07-01 16:28:21 -07006233
6234 final long identity = Binder.clearCallingIdentity();
6235 try {
6236 final TelephonyManager telephonyManager = mApp.getSystemService(
6237 TelephonyManager.class);
6238 String subscriberId = telephonyManager.getSubscriberId(subId);
6239 if (subscriberId == null) {
6240 if (DBG) {
zoey chen38003472019-12-13 17:16:31 +08006241 log("getMergedImsisFromGroup can't find subscriberId for subId "
Malcolm Chen6ca97372019-07-01 16:28:21 -07006242 + subId);
6243 }
6244 return null;
6245 }
6246
6247 final SubscriptionInfo info = SubscriptionController.getInstance()
6248 .getSubscriptionInfo(subId);
6249 final ParcelUuid groupUuid = info.getGroupUuid();
6250 // If it doesn't belong to any group, return just subscriberId of itself.
6251 if (groupUuid == null) {
6252 return new String[]{subscriberId};
6253 }
6254
6255 // Get all subscriberIds from the group.
6256 final List<String> mergedSubscriberIds = new ArrayList<>();
6257 final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance()
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006258 .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006259 mApp.getAttributionTag());
Malcolm Chen6ca97372019-07-01 16:28:21 -07006260 for (SubscriptionInfo subInfo : groupInfos) {
6261 subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId());
6262 if (subscriberId != null) {
6263 mergedSubscriberIds.add(subscriberId);
6264 }
6265 }
6266
6267 return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]);
6268 } finally {
6269 Binder.restoreCallingIdentity(identity);
6270
6271 }
6272 }
6273
6274 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006275 public boolean setOperatorBrandOverride(int subId, String brand) {
Shuo Qian6d927452019-12-05 11:40:37 -08006276 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp,
Jeff Davidson7e17e312018-02-13 18:17:36 -08006277 subId, "setOperatorBrandOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006278
6279 final long identity = Binder.clearCallingIdentity();
6280 try {
6281 final Phone phone = getPhone(subId);
6282 return phone == null ? false : phone.setOperatorBrandOverride(brand);
6283 } finally {
6284 Binder.restoreCallingIdentity(identity);
6285 }
Shishir Agrawalb1ebf8c2014-07-17 16:32:41 -07006286 }
Steven Liu4bf01bc2014-07-17 11:05:29 -05006287
6288 @Override
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006289 public boolean setRoamingOverride(int subId, List<String> gsmRoamingList,
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006290 List<String> gsmNonRoamingList, List<String> cdmaRoamingList,
6291 List<String> cdmaNonRoamingList) {
Shuo Qian6d927452019-12-05 11:40:37 -08006292 TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(
6293 mApp, subId, "setRoamingOverride");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006294
6295 final long identity = Binder.clearCallingIdentity();
6296 try {
6297 final Phone phone = getPhone(subId);
6298 if (phone == null) {
6299 return false;
6300 }
6301 return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList,
6302 cdmaNonRoamingList);
6303 } finally {
6304 Binder.restoreCallingIdentity(identity);
Shishir Agrawalc04d9752016-02-19 10:41:00 -08006305 }
Shishir Agrawal621a47c2014-12-01 10:25:09 -08006306 }
6307
6308 @Override
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006309 @Deprecated
6310 public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) {
6311 enforceModifyPermission();
6312
6313 int returnValue = 0;
6314 try {
vagdeviaf9a5b92018-08-15 16:01:53 -07006315 AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq);
Shuo Qian850e4d6a2018-04-25 21:02:08 +00006316 if(result.exception == null) {
6317 if (result.result != null) {
6318 byte[] responseData = (byte[])(result.result);
6319 if(responseData.length > oemResp.length) {
6320 Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " +
6321 responseData.length + "bytes. Buffer Size is " +
6322 oemResp.length + "bytes.");
6323 }
6324 System.arraycopy(responseData, 0, oemResp, 0, responseData.length);
6325 returnValue = responseData.length;
6326 }
6327 } else {
6328 CommandException ex = (CommandException) result.exception;
6329 returnValue = ex.getCommandError().ordinal();
6330 if(returnValue > 0) returnValue *= -1;
6331 }
6332 } catch (RuntimeException e) {
6333 Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception");
6334 returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal());
6335 if(returnValue > 0) returnValue *= -1;
6336 }
6337
6338 return returnValue;
6339 }
6340
6341 @Override
Wink Saville5d475dd2014-10-17 15:00:58 -07006342 public void setRadioCapability(RadioAccessFamily[] rafs) {
6343 try {
6344 ProxyController.getInstance().setRadioCapability(rafs);
6345 } catch (RuntimeException e) {
6346 Log.w(LOG_TAG, "setRadioCapability: Runtime Exception");
6347 }
6348 }
6349
6350 @Override
Robert Greenwalt36b23af2015-07-06 17:59:14 -07006351 public int getRadioAccessFamily(int phoneId, String callingPackage) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006352 Phone phone = PhoneFactory.getPhone(phoneId);
chen xub97461a2018-10-26 14:17:57 -07006353 int raf = RadioAccessFamily.RAF_UNKNOWN;
Jeff Davidson913390f2018-02-23 17:11:49 -08006354 if (phone == null) {
chen xub97461a2018-10-26 14:17:57 -07006355 return raf;
Jeff Davidson913390f2018-02-23 17:11:49 -08006356 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006357 final long identity = Binder.clearCallingIdentity();
6358 try {
chen xub97461a2018-10-26 14:17:57 -07006359 TelephonyPermissions
6360 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
6361 mApp, phone.getSubId(), "getRadioAccessFamily");
6362 raf = ProxyController.getInstance().getRadioAccessFamily(phoneId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006363 } finally {
6364 Binder.restoreCallingIdentity(identity);
6365 }
chen xub97461a2018-10-26 14:17:57 -07006366 return raf;
Wink Saville5d475dd2014-10-17 15:00:58 -07006367 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006368
6369 @Override
6370 public void enableVideoCalling(boolean enable) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006371 final Phone defaultPhone = getDefaultPhone();
Andrew Leedf14ead2014-10-17 14:22:52 -07006372 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006373
6374 final long identity = Binder.clearCallingIdentity();
6375 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006376 ImsManager.getInstance(defaultPhone.getContext(),
6377 defaultPhone.getPhoneId()).setVtSetting(enable);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006378 } finally {
6379 Binder.restoreCallingIdentity(identity);
6380 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006381 }
6382
6383 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006384 public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006385 final Phone defaultPhone = getDefaultPhone();
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006386 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(),
6387 callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Amit Mahajan578e53d2018-03-20 16:18:38 +00006388 return false;
6389 }
Svet Ganovb320e182015-04-16 12:30:10 -07006390
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006391 final long identity = Binder.clearCallingIdentity();
6392 try {
6393 // Check the user preference and the system-level IMS setting. Even if the user has
6394 // enabled video calling, if IMS is disabled we aren't able to support video calling.
6395 // In the long run, we may instead need to check if there exists a connection service
6396 // which can support video calling.
6397 ImsManager imsManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006398 ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006399 return imsManager.isVtEnabledByPlatform()
6400 && imsManager.isEnhanced4gLteModeSettingEnabledByUser()
6401 && imsManager.isVtEnabledByUser();
6402 } finally {
6403 Binder.restoreCallingIdentity(identity);
6404 }
Andrew Leedf14ead2014-10-17 14:22:52 -07006405 }
Libin.Tang@motorola.comafe82642014-12-18 13:27:53 -06006406
Andrew Leea1239f22015-03-02 17:44:07 -08006407 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006408 public boolean canChangeDtmfToneLength(int subId, String callingPackage,
6409 String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006410 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006411 mApp, subId, callingPackage, callingFeatureId,
6412 "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006413 return false;
6414 }
6415
6416 final long identity = Binder.clearCallingIdentity();
6417 try {
6418 CarrierConfigManager configManager =
6419 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006420 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006421 .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL);
6422 } finally {
6423 Binder.restoreCallingIdentity(identity);
6424 }
Andrew Leea1239f22015-03-02 17:44:07 -08006425 }
6426
6427 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006428 public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006429 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006430 mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006431 return false;
6432 }
6433
6434 final long identity = Binder.clearCallingIdentity();
6435 try {
6436 CarrierConfigManager configManager =
6437 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006438 return configManager.getConfigForSubId(subId)
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006439 .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL);
6440 } finally {
6441 Binder.restoreCallingIdentity(identity);
6442 }
Andrew Leea1239f22015-03-02 17:44:07 -08006443 }
6444
Andrew Lee9431b832015-03-09 18:46:45 -07006445 @Override
6446 public boolean isTtyModeSupported() {
Tyler Gunn77ee9382019-10-31 13:08:23 -07006447 TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class);
Wooki Wu1f82f7a2016-02-15 15:59:58 +08006448 return telecomManager.isTtySupported();
Andrew Lee9431b832015-03-09 18:46:45 -07006449 }
6450
6451 @Override
6452 public boolean isHearingAidCompatibilitySupported() {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006453 final long identity = Binder.clearCallingIdentity();
6454 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006455 return mApp.getResources().getBoolean(R.bool.hac_enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006456 } finally {
6457 Binder.restoreCallingIdentity(identity);
6458 }
Andrew Lee9431b832015-03-09 18:46:45 -07006459 }
6460
Hall Liuf6668912018-10-31 17:05:23 -07006461 /**
6462 * Determines whether the device currently supports RTT (Real-time text). Based both on carrier
6463 * support for the feature and device firmware support.
6464 *
6465 * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise.
6466 */
6467 @Override
6468 public boolean isRttSupported(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006469 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006470 final Phone phone = getPhone(subscriptionId);
6471 if (phone == null) {
6472 loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId);
6473 return false;
6474 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006475 try {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006476 boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean(
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006477 CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL);
6478 boolean isDeviceSupported =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006479 phone.getContext().getResources().getBoolean(R.bool.config_support_rtt);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006480 return isCarrierSupported && isDeviceSupported;
6481 } finally {
6482 Binder.restoreCallingIdentity(identity);
6483 }
Hall Liu98187582018-01-22 19:15:32 -08006484 }
6485
Hall Liuf6668912018-10-31 17:05:23 -07006486 /**
Hall Liu6a06be62019-07-23 18:39:00 -07006487 * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set
6488 * RTT setting, will return true if the device and carrier both support RTT.
6489 * Otherwise. only returns true if the device and carrier both also support RTT.
Hall Liuf6668912018-10-31 17:05:23 -07006490 */
6491 public boolean isRttEnabled(int subscriptionId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006492 final long identity = Binder.clearCallingIdentity();
6493 try {
Hall Liu63767ec2019-12-11 23:58:20 +00006494 boolean isRttSupported = isRttSupported(subscriptionId);
6495 boolean isUserRttSettingOn = Settings.Secure.getInt(
6496 mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0;
6497 boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId)
6498 .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL);
6499 return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006500 } finally {
6501 Binder.restoreCallingIdentity(identity);
6502 }
Hall Liu3ad5f012018-04-06 16:23:39 -07006503 }
6504
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006505 @Deprecated
6506 @Override
6507 public String getDeviceId(String callingPackage) {
6508 return getDeviceIdWithFeature(callingPackage, null);
6509 }
6510
Sanket Padawe7310cc72015-01-14 09:53:20 -08006511 /**
6512 * Returns the unique device ID of phone, for example, the IMEI for
6513 * GSM and the MEID for CDMA phones. Return null if device ID is not available.
6514 *
6515 * <p>Requires Permission:
6516 * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE}
6517 */
6518 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006519 public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006520 final Phone phone = PhoneFactory.getPhone(0);
Jeff Davidson913390f2018-02-23 17:11:49 -08006521 if (phone == null) {
Sanket Padawe7310cc72015-01-14 09:53:20 -08006522 return null;
6523 }
Jeff Davidson913390f2018-02-23 17:11:49 -08006524 int subId = phone.getSubId();
Michael Groover70af6dc2018-10-01 16:23:15 -07006525 if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006526 callingPackage, callingFeatureId, "getDeviceId")) {
Jeff Davidson913390f2018-02-23 17:11:49 -08006527 return null;
6528 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006529
6530 final long identity = Binder.clearCallingIdentity();
6531 try {
6532 return phone.getDeviceId();
6533 } finally {
6534 Binder.restoreCallingIdentity(identity);
6535 }
Sanket Padawe7310cc72015-01-14 09:53:20 -08006536 }
6537
Ping Sunc67b7c22016-03-02 19:16:45 +08006538 /**
6539 * {@hide}
6540 * Returns the IMS Registration Status on a particular subid
6541 *
6542 * @param subId
6543 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006544 public boolean isImsRegistered(int subId) {
Ping Sunc67b7c22016-03-02 19:16:45 +08006545 Phone phone = getPhone(subId);
6546 if (phone != null) {
6547 return phone.isImsRegistered();
6548 } else {
6549 return false;
6550 }
6551 }
6552
Santos Cordon7a1885b2015-02-03 11:15:19 -08006553 @Override
6554 public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006555 final long identity = Binder.clearCallingIdentity();
6556 try {
6557 return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
6558 } finally {
6559 Binder.restoreCallingIdentity(identity);
6560 }
Santos Cordon7a1885b2015-02-03 11:15:19 -08006561 }
Nathan Harolddcfc7932015-03-18 10:01:20 -07006562
Tyler Gunnf70ed162019-04-03 15:28:53 -07006563 @Override
Shuo Qian0762a782019-10-30 16:33:31 -07006564 public int getSubIdForPhoneAccountHandle(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006565 PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) {
Shuo Qian0762a782019-10-30 16:33:31 -07006566 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(),
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006567 callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) {
Shuo Qian0762a782019-10-30 16:33:31 -07006568 throw new SecurityException("Requires READ_PHONE_STATE permission.");
6569 }
6570 final long identity = Binder.clearCallingIdentity();
6571 try {
6572 return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle);
6573 } finally {
6574 Binder.restoreCallingIdentity(identity);
6575 }
6576 }
6577
6578 @Override
Tyler Gunnf70ed162019-04-03 15:28:53 -07006579 public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) {
duki.hongfd96bde2020-07-22 17:32:19 +09006580 enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, "
6581 + "subscriptionId: " + subscriptionId);
Tyler Gunnf70ed162019-04-03 15:28:53 -07006582 final long identity = Binder.clearCallingIdentity();
6583 try {
6584 Phone phone = getPhone(subscriptionId);
6585 if (phone == null) {
6586 return null;
6587 }
6588 return PhoneUtils.makePstnPhoneAccountHandle(phone);
6589 } finally {
6590 Binder.restoreCallingIdentity(identity);
6591 }
6592 }
6593
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006594 /**
6595 * @return the VoWiFi calling availability.
Nathan Haroldc55097a2015-03-11 18:14:50 -07006596 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006597 public boolean isWifiCallingAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006598 final long identity = Binder.clearCallingIdentity();
6599 try {
6600 Phone phone = getPhone(subId);
6601 if (phone != null) {
6602 return phone.isWifiCallingEnabled();
6603 } else {
6604 return false;
6605 }
6606 } finally {
6607 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006608 }
Nathan Haroldc55097a2015-03-11 18:14:50 -07006609 }
6610
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006611 /**
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006612 * @return the VT calling availability.
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006613 */
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006614 public boolean isVideoTelephonyAvailable(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006615 final long identity = Binder.clearCallingIdentity();
6616 try {
6617 Phone phone = getPhone(subId);
6618 if (phone != null) {
6619 return phone.isVideoEnabled();
6620 } else {
6621 return false;
6622 }
6623 } finally {
6624 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006625 }
6626 }
6627
6628 /**
6629 * @return the IMS registration technology for the MMTEL feature. Valid return values are
6630 * defined in {@link ImsRegistrationImplBase}.
6631 */
6632 public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006633 final long identity = Binder.clearCallingIdentity();
6634 try {
6635 Phone phone = getPhone(subId);
6636 if (phone != null) {
6637 return phone.getImsRegistrationTech();
6638 } else {
6639 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
6640 }
6641 } finally {
6642 Binder.restoreCallingIdentity(identity);
Brad Ebinger1f2b5082018-02-08 16:11:32 -08006643 }
Etan Cohen3b7a1bc2015-05-28 15:57:13 -07006644 }
6645
Stuart Scott8eef64f2015-04-08 15:13:54 -07006646 @Override
6647 public void factoryReset(int subId) {
paulhu423b5f22019-08-23 19:17:33 +08006648 enforceSettingsPermission();
Stuart Scott981d8582015-04-21 14:09:50 -07006649 if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) {
6650 return;
6651 }
6652
Svet Ganovcc087f82015-05-12 20:35:54 -07006653 final long identity = Binder.clearCallingIdentity();
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006654
Svet Ganovcc087f82015-05-12 20:35:54 -07006655 try {
Stuart Scott981d8582015-04-21 14:09:50 -07006656 if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction(
6657 UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) {
Pengquan Meng85728fb2018-03-12 16:31:21 -07006658 setUserDataEnabled(subId, getDefaultDataEnabled());
Svet Ganovcc087f82015-05-12 20:35:54 -07006659 setNetworkSelectionModeAutomatic(subId);
Pengquan Meng85728fb2018-03-12 16:31:21 -07006660 setPreferredNetworkType(subId, getDefaultNetworkType(subId));
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006661 setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId));
6662 CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp);
Svet Ganovcc087f82015-05-12 20:35:54 -07006663 }
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006664 // There has been issues when Sms raw table somehow stores orphan
6665 // fragments. They lead to garbled message when new fragments come
6666 // in and combined with those stale ones. In case this happens again,
6667 // user can reset all network settings which will clean up this table.
6668 cleanUpSmsRawTable(getDefaultPhone().getContext());
Brad Ebinger77b832e2019-10-17 17:03:22 -07006669 // Clean up IMS settings as well here.
6670 int slotId = getSlotIndex(subId);
6671 if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) {
6672 ImsManager.getInstance(mApp, slotId).factoryReset();
6673 }
Naina Nalluri8ff344d2019-09-17 14:10:30 -07006674
6675 // Erase modem config if erase modem on network setting is enabled.
6676 String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY,
6677 RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED);
6678 if (configValue != null && Boolean.parseBoolean(configValue)) {
6679 sendEraseModemConfig(getDefaultPhone());
6680 }
Svet Ganovcc087f82015-05-12 20:35:54 -07006681 } finally {
6682 Binder.restoreCallingIdentity(identity);
Stuart Scott8eef64f2015-04-08 15:13:54 -07006683 }
6684 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006685
Amit Mahajan7dbbd822019-03-13 17:33:47 -07006686 private void cleanUpSmsRawTable(Context context) {
6687 ContentResolver resolver = context.getContentResolver();
6688 Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
6689 resolver.delete(uri, null, null);
6690 }
6691
Narayan Kamath1c496c22015-04-16 14:40:19 +01006692 @Override
chen xu5d3637b2019-01-21 23:31:38 -08006693 public String getSimLocaleForSubscriber(int subId) {
6694 enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId);
6695 final Phone phone = getPhone(subId);
6696 if (phone == null) {
6697 log("getSimLocaleForSubscriber, invalid subId");
chen xu2bb91e42019-01-24 14:35:54 -08006698 return null;
chen xu5d3637b2019-01-21 23:31:38 -08006699 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006700 final long identity = Binder.clearCallingIdentity();
6701 try {
chen xu5d3637b2019-01-21 23:31:38 -08006702 final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId,
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006703 phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag());
chen xu6291c472019-02-04 12:55:53 -08006704 if (info == null) {
6705 log("getSimLocaleForSubscriber, inactive subId: " + subId);
6706 return null;
6707 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006708 // Try and fetch the locale from the carrier properties or from the SIM language
6709 // preferences (EF-PL and EF-LI)...
6710 final int mcc = info.getMcc();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006711 String simLanguage = null;
chen xu5d3637b2019-01-21 23:31:38 -08006712 final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs();
6713 if (localeFromDefaultSim != null) {
6714 if (!localeFromDefaultSim.getCountry().isEmpty()) {
6715 if (DBG) log("Using locale from subId: " + subId + " locale: "
6716 + localeFromDefaultSim);
6717 return localeFromDefaultSim.toLanguageTag();
6718 } else {
6719 simLanguage = localeFromDefaultSim.getLanguage();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006720 }
6721 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006722
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006723 // The SIM language preferences only store a language (e.g. fr = French), not an
6724 // exact locale (e.g. fr_FR = French/France). So, if the locale returned from
6725 // the SIM and carrier preferences does not include a country we add the country
6726 // determined from the SIM MCC to provide an exact locale.
zoey chen84e2b212019-12-18 17:07:20 +08006727 final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006728 if (mccLocale != null) {
chen xu5d3637b2019-01-21 23:31:38 -08006729 if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006730 return mccLocale.toLanguageTag();
6731 }
6732
6733 if (DBG) log("No locale found - returning null");
6734 return null;
6735 } finally {
6736 Binder.restoreCallingIdentity(identity);
6737 }
Narayan Kamath1c496c22015-04-16 14:40:19 +01006738 }
6739
6740 private List<SubscriptionInfo> getAllSubscriptionInfoList() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006741 return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006742 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006743 }
6744
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006745 /**
6746 * NOTE: this method assumes permission checks are done and caller identity has been cleared.
6747 */
6748 private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006749 return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(),
Philip P. Moltmann0079aae2020-03-05 16:24:02 -08006750 mApp.getAttributionTag());
Narayan Kamath1c496c22015-04-16 14:40:19 +01006751 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006752
Chenjie Yu1ba97252018-01-11 18:16:20 -08006753 private final ModemActivityInfo mLastModemActivityInfo =
Chen Xu13851032019-09-10 18:49:52 -07006754 new ModemActivityInfo(0, 0, 0, new int[0], 0);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006755
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006756 /**
Adam Lesinski903a54c2016-04-11 14:49:52 -07006757 * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object
6758 * representing the state of the modem.
6759 *
Chenjie Yu1ba97252018-01-11 18:16:20 -08006760 * NOTE: The underlying implementation clears the modem state, so there should only ever be one
6761 * caller to it. Everyone should call this class to get cumulative data.
Adam Lesinski903a54c2016-04-11 14:49:52 -07006762 * @hide
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006763 */
6764 @Override
Adam Lesinski903a54c2016-04-11 14:49:52 -07006765 public void requestModemActivityInfo(ResultReceiver result) {
6766 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07006767 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006768
6769 final long identity = Binder.clearCallingIdentity();
6770 try {
sqian1a1be542020-03-05 11:37:28 -08006771 sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006772 } finally {
6773 Binder.restoreCallingIdentity(identity);
Chenjie Yu1ba97252018-01-11 18:16:20 -08006774 }
Prerepa Viswanadham7fcff692015-06-03 11:20:55 -07006775 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006776
Siddharth Rayb8114062018-06-17 15:02:38 -07006777 // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be
6778 // less than total activity duration.
6779 private boolean isModemActivityInfoValid(ModemActivityInfo info) {
6780 if (info == null) {
6781 return false;
6782 }
6783 int activityDurationMs =
6784 (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp());
6785 int totalTxTimeMs = 0;
Chen Xu13851032019-09-10 18:49:52 -07006786 int[] txTimeMs = info.getTransmitTimeMillis();
6787 for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) {
6788 totalTxTimeMs += txTimeMs[i];
Siddharth Rayb8114062018-06-17 15:02:38 -07006789 }
6790 return (info.isValid()
6791 && (info.getSleepTimeMillis() <= activityDurationMs)
6792 && (info.getIdleTimeMillis() <= activityDurationMs)
Chen Xu13851032019-09-10 18:49:52 -07006793 && (info.getReceiveTimeMillis() <= activityDurationMs)
Siddharth Rayb8114062018-06-17 15:02:38 -07006794 && (totalTxTimeMs <= activityDurationMs));
6795 }
6796
Jack Yu85bd38a2015-11-09 11:34:32 -08006797 /**
6798 * {@hide}
6799 * Returns the service state information on specified subscription.
6800 */
6801 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006802 public ServiceState getServiceStateForSubscriber(int subId, String callingPackage,
6803 String callingFeatureId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006804 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006805 mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) {
Jack Yu85bd38a2015-11-09 11:34:32 -08006806 return null;
6807 }
6808
Hall Liuf19c44f2018-11-27 14:38:17 -08006809 LocationAccessPolicy.LocationPermissionResult fineLocationResult =
6810 LocationAccessPolicy.checkLocationPermission(mApp,
6811 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6812 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006813 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006814 .setCallingPid(Binder.getCallingPid())
6815 .setCallingUid(Binder.getCallingUid())
6816 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006817 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006818 .setMinSdkVersionForFine(Build.VERSION_CODES.Q)
6819 .build());
6820
6821 LocationAccessPolicy.LocationPermissionResult coarseLocationResult =
6822 LocationAccessPolicy.checkLocationPermission(mApp,
6823 new LocationAccessPolicy.LocationPermissionQuery.Builder()
6824 .setCallingPackage(callingPackage)
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08006825 .setCallingFeatureId(callingFeatureId)
Hall Liuf19c44f2018-11-27 14:38:17 -08006826 .setCallingPid(Binder.getCallingPid())
6827 .setCallingUid(Binder.getCallingUid())
6828 .setMethod("getServiceStateForSubscriber")
Hall Liuf18a0cf2019-04-17 13:37:11 -07006829 .setLogAsInfo(true)
Hall Liuf19c44f2018-11-27 14:38:17 -08006830 .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q)
6831 .build());
6832 // We don't care about hard or soft here -- all we need to know is how much info to scrub.
6833 boolean hasFinePermission =
6834 fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6835 boolean hasCoarsePermission =
6836 coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED;
6837
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006838 final long identity = Binder.clearCallingIdentity();
6839 try {
6840 final Phone phone = getPhone(subId);
6841 if (phone == null) {
6842 return null;
6843 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006844
Hall Liuf19c44f2018-11-27 14:38:17 -08006845 ServiceState ss = phone.getServiceState();
6846
6847 // Scrub out the location info in ServiceState depending on what level of access
6848 // the caller has.
6849 if (hasFinePermission) return ss;
Malcolm Chendb337972019-12-30 13:56:38 -08006850 if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false);
6851 return ss.createLocationInfoSanitizedCopy(true);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006852 } finally {
6853 Binder.restoreCallingIdentity(identity);
6854 }
Jack Yu85bd38a2015-11-09 11:34:32 -08006855 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006856
6857 /**
6858 * Returns the URI for the per-account voicemail ringtone set in Phone settings.
6859 *
6860 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6861 * voicemail ringtone.
6862 * @return The URI for the ringtone to play when receiving a voicemail from a specific
6863 * PhoneAccount.
6864 */
6865 @Override
6866 public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006867 final long identity = Binder.clearCallingIdentity();
6868 try {
6869 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6870 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006871 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006872 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006873
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006874 return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext());
6875 } finally {
6876 Binder.restoreCallingIdentity(identity);
6877 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006878 }
6879
6880 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006881 * Sets the per-account voicemail ringtone.
6882 *
6883 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6884 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6885 *
6886 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6887 * voicemail ringtone.
6888 * @param uri The URI for the ringtone to play when receiving a voicemail from a specific
6889 * PhoneAccount.
6890 */
6891 @Override
6892 public void setVoicemailRingtoneUri(String callingPackage,
6893 PhoneAccountHandle phoneAccountHandle, Uri uri) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006894 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006895 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006896 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6897 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006898 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6899 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6900 "setVoicemailRingtoneUri");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006901 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006902
6903 final long identity = Binder.clearCallingIdentity();
6904 try {
6905 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6906 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006907 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006908 }
6909 VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri);
6910 } finally {
6911 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006912 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006913 }
6914
6915 /**
Nancy Chen31f9ba12016-01-06 11:42:12 -08006916 * Returns whether vibration is set for voicemail notification in Phone settings.
6917 *
6918 * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the
6919 * voicemail vibration setting.
6920 * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise.
6921 */
6922 @Override
6923 public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006924 final long identity = Binder.clearCallingIdentity();
6925 try {
6926 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle);
6927 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006928 phone = getDefaultPhone();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006929 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006930
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006931 return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext());
6932 } finally {
6933 Binder.restoreCallingIdentity(identity);
6934 }
Nancy Chen31f9ba12016-01-06 11:42:12 -08006935 }
6936
Youhan Wange64578a2016-05-02 15:32:42 -07006937 /**
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006938 * Sets the per-account voicemail vibration.
6939 *
6940 * <p>Requires that the calling app is the default dialer, or has carrier privileges, or
6941 * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
6942 *
6943 * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the
6944 * voicemail vibration setting.
6945 * @param enabled Whether to enable or disable vibration for voicemail notifications from a
6946 * specific PhoneAccount.
6947 */
6948 @Override
6949 public void setVoicemailVibrationEnabled(String callingPackage,
6950 PhoneAccountHandle phoneAccountHandle, boolean enabled) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006951 final Phone defaultPhone = getDefaultPhone();
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006952 mAppOps.checkPackage(Binder.getCallingUid(), callingPackage);
Tyler Gunn77ee9382019-10-31 13:08:23 -07006953 TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class);
6954 if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08006955 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
6956 mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle),
6957 "setVoicemailVibrationEnabled");
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006958 }
6959
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006960 final long identity = Binder.clearCallingIdentity();
6961 try {
6962 Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle);
6963 if (phone == null) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08006964 phone = defaultPhone;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006965 }
6966 VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled);
6967 } finally {
6968 Binder.restoreCallingIdentity(identity);
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006969 }
Ta-wei Yenc33877d2017-01-23 18:11:21 -08006970 }
6971
6972 /**
Youhan Wange64578a2016-05-02 15:32:42 -07006973 * Make sure either called from same process as self (phone) or IPC caller has read privilege.
6974 *
6975 * @throws SecurityException if the caller does not have the required permission
6976 */
Brad Ebinger35c841c2018-10-01 10:40:55 -07006977 private void enforceReadPrivilegedPermission(String message) {
Youhan Wange64578a2016-05-02 15:32:42 -07006978 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
Brad Ebinger35c841c2018-10-01 10:40:55 -07006979 message);
Youhan Wange64578a2016-05-02 15:32:42 -07006980 }
6981
6982 /**
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006983 * Make sure either called from same process as self (phone) or IPC caller has send SMS
6984 * permission.
6985 *
6986 * @throws SecurityException if the caller does not have the required permission
6987 */
6988 private void enforceSendSmsPermission() {
6989 mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null);
6990 }
6991
6992 /**
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006993 * Make sure called from the package in charge of visual voicemail.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006994 *
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006995 * @throws SecurityException if the caller is not the visual voicemail package.
Ta-wei Yen30a69c82016-12-27 14:52:32 -08006996 */
Ta-wei Yen527a9c02017-01-06 15:29:25 -08006997 private void enforceVisualVoicemailPackage(String callingPackage, int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08006998 final long identity = Binder.clearCallingIdentity();
6999 try {
7000 ComponentName componentName =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007001 RemoteVvmTaskManager.getRemotePackage(mApp, subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007002 if (componentName == null) {
7003 throw new SecurityException(
7004 "Caller not current active visual voicemail package[null]");
7005 }
7006 String vvmPackage = componentName.getPackageName();
7007 if (!callingPackage.equals(vvmPackage)) {
7008 throw new SecurityException("Caller not current active visual voicemail package["
7009 + vvmPackage + "]");
7010 }
7011 } finally {
7012 Binder.restoreCallingIdentity(identity);
Ta-wei Yen30a69c82016-12-27 14:52:32 -08007013 }
7014 }
7015
7016 /**
Youhan Wange64578a2016-05-02 15:32:42 -07007017 * Return the application ID for the app type.
7018 *
7019 * @param subId the subscription ID that this request applies to.
7020 * @param appType the uicc app type.
7021 * @return Application ID for specificied app type, or null if no uicc.
7022 */
7023 @Override
7024 public String getAidForAppType(int subId, int appType) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007025 enforceReadPrivilegedPermission("getAidForAppType");
Youhan Wange64578a2016-05-02 15:32:42 -07007026 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007027
7028 final long identity = Binder.clearCallingIdentity();
Youhan Wange64578a2016-05-02 15:32:42 -07007029 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007030 if (phone == null) {
7031 return null;
7032 }
7033 String aid = null;
7034 try {
7035 aid = UiccController.getInstance().getUiccCard(phone.getPhoneId())
7036 .getApplicationByType(appType).getAid();
7037 } catch (Exception e) {
7038 Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e);
7039 }
7040 return aid;
7041 } finally {
7042 Binder.restoreCallingIdentity(identity);
Youhan Wange64578a2016-05-02 15:32:42 -07007043 }
Youhan Wange64578a2016-05-02 15:32:42 -07007044 }
7045
Youhan Wang4001d252016-05-11 10:29:41 -07007046 /**
7047 * Return the Electronic Serial Number.
7048 *
7049 * @param subId the subscription ID that this request applies to.
7050 * @return ESN or null if error.
7051 */
7052 @Override
7053 public String getEsn(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007054 enforceReadPrivilegedPermission("getEsn");
Youhan Wang4001d252016-05-11 10:29:41 -07007055 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007056
7057 final long identity = Binder.clearCallingIdentity();
Youhan Wang4001d252016-05-11 10:29:41 -07007058 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007059 if (phone == null) {
7060 return null;
7061 }
7062 String esn = null;
7063 try {
7064 esn = phone.getEsn();
7065 } catch (Exception e) {
7066 Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e);
7067 }
7068 return esn;
7069 } finally {
7070 Binder.restoreCallingIdentity(identity);
Youhan Wang4001d252016-05-11 10:29:41 -07007071 }
Youhan Wang4001d252016-05-11 10:29:41 -07007072 }
7073
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007074 /**
Youhan Wang66ad5d72016-07-18 17:56:58 -07007075 * Return the Preferred Roaming List Version.
7076 *
7077 * @param subId the subscription ID that this request applies to.
7078 * @return PRLVersion or null if error.
7079 */
7080 @Override
7081 public String getCdmaPrlVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007082 enforceReadPrivilegedPermission("getCdmaPrlVersion");
Youhan Wang66ad5d72016-07-18 17:56:58 -07007083 Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007084
7085 final long identity = Binder.clearCallingIdentity();
Youhan Wang66ad5d72016-07-18 17:56:58 -07007086 try {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007087 if (phone == null) {
7088 return null;
7089 }
7090 String cdmaPrlVersion = null;
7091 try {
7092 cdmaPrlVersion = phone.getCdmaPrlVersion();
7093 } catch (Exception e) {
7094 Log.e(LOG_TAG, "Not getting PRLVersion", e);
7095 }
7096 return cdmaPrlVersion;
7097 } finally {
7098 Binder.restoreCallingIdentity(identity);
Youhan Wang66ad5d72016-07-18 17:56:58 -07007099 }
Youhan Wang66ad5d72016-07-18 17:56:58 -07007100 }
7101
7102 /**
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007103 * Get snapshot of Telephony histograms
7104 * @return List of Telephony histograms
7105 * @hide
7106 */
7107 @Override
7108 public List<TelephonyHistogram> getTelephonyHistograms() {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007109 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7110 mApp, getDefaultSubscription(), "getTelephonyHistograms");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007111
7112 final long identity = Binder.clearCallingIdentity();
7113 try {
7114 return RIL.getTelephonyRILTimingHistograms();
7115 } finally {
7116 Binder.restoreCallingIdentity(identity);
7117 }
Sanket Padawe99ef1e32016-05-18 16:12:33 -07007118 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007119
7120 /**
7121 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007122 * Set the allowed carrier list and the excluded carrier list, indicating the priority between
7123 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007124 * Require system privileges. In the future we may add this to carrier APIs.
7125 *
Michele Berionne482f8202018-11-27 18:57:59 -08007126 * @return Integer with the result of the operation, as defined in {@link TelephonyManager}.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007127 */
7128 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007129 @TelephonyManager.SetCarrierRestrictionResult
7130 public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) {
Meng Wang1a7c35a2016-05-05 20:56:15 -07007131 enforceModifyPermission();
vagdeviaf9a5b92018-08-15 16:01:53 -07007132 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007133
Michele Berionne482f8202018-11-27 18:57:59 -08007134 if (carrierRestrictionRules == null) {
7135 throw new NullPointerException("carrier restriction cannot be null");
Meng Wang9b7c4e92017-02-17 11:41:27 -08007136 }
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007137
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007138 final long identity = Binder.clearCallingIdentity();
7139 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007140 return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules,
vagdeviaf9a5b92018-08-15 16:01:53 -07007141 workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007142 } finally {
7143 Binder.restoreCallingIdentity(identity);
7144 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007145 }
7146
7147 /**
7148 * {@hide}
Michele Berionne482f8202018-11-27 18:57:59 -08007149 * Get the allowed carrier list and the excluded carrier list, including the priority between
7150 * the two lists.
Meng Wang1a7c35a2016-05-05 20:56:15 -07007151 * Require system privileges. In the future we may add this to carrier APIs.
7152 *
Michele Berionne482f8202018-11-27 18:57:59 -08007153 * @return {@link android.telephony.CarrierRestrictionRules}
Meng Wang1a7c35a2016-05-05 20:56:15 -07007154 */
7155 @Override
Michele Berionne482f8202018-11-27 18:57:59 -08007156 public CarrierRestrictionRules getAllowedCarriers() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007157 enforceReadPrivilegedPermission("getAllowedCarriers");
vagdeviaf9a5b92018-08-15 16:01:53 -07007158 WorkSource workSource = getWorkSource(Binder.getCallingUid());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007159
7160 final long identity = Binder.clearCallingIdentity();
7161 try {
Michele Berionne482f8202018-11-27 18:57:59 -08007162 Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource);
7163 if (response instanceof CarrierRestrictionRules) {
7164 return (CarrierRestrictionRules) response;
7165 }
7166 // Response is an Exception of some kind,
7167 // which is signalled to the user as a NULL retval
7168 return null;
7169 } catch (Exception e) {
7170 Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e);
7171 return null;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007172 } finally {
7173 Binder.restoreCallingIdentity(identity);
7174 }
Meng Wang1a7c35a2016-05-05 20:56:15 -07007175 }
7176
fionaxu59545b42016-05-25 15:53:37 -07007177 /**
7178 * Action set from carrier signalling broadcast receivers to enable/disable metered apns
7179 * @param subId the subscription ID that this action applies to.
7180 * @param enabled control enable or disable metered apns.
7181 * {@hide}
7182 */
7183 @Override
7184 public void carrierActionSetMeteredApnsEnabled(int subId, boolean enabled) {
7185 enforceModifyPermission();
7186 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007187
7188 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007189 if (phone == null) {
7190 loge("carrierAction: SetMeteredApnsEnabled fails with invalid subId: " + subId);
7191 return;
7192 }
7193 try {
7194 phone.carrierActionSetMeteredApnsEnabled(enabled);
7195 } catch (Exception e) {
7196 Log.e(LOG_TAG, "carrierAction: SetMeteredApnsEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007197 } finally {
7198 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007199 }
7200 }
7201
7202 /**
7203 * Action set from carrier signalling broadcast receivers to enable/disable radio
7204 * @param subId the subscription ID that this action applies to.
7205 * @param enabled control enable or disable radio.
7206 * {@hide}
7207 */
7208 @Override
7209 public void carrierActionSetRadioEnabled(int subId, boolean enabled) {
7210 enforceModifyPermission();
7211 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007212
7213 final long identity = Binder.clearCallingIdentity();
fionaxu59545b42016-05-25 15:53:37 -07007214 if (phone == null) {
7215 loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId);
7216 return;
7217 }
7218 try {
7219 phone.carrierActionSetRadioEnabled(enabled);
7220 } catch (Exception e) {
7221 Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007222 } finally {
7223 Binder.restoreCallingIdentity(identity);
fionaxu59545b42016-05-25 15:53:37 -07007224 }
7225 }
7226
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007227 /**
fionaxu8da9cb12017-05-23 15:02:46 -07007228 * Action set from carrier signalling broadcast receivers to start/stop reporting the default
7229 * network status based on which carrier apps could apply actions accordingly,
7230 * enable/disable default url handler for example.
7231 *
7232 * @param subId the subscription ID that this action applies to.
7233 * @param report control start/stop reporting the default network status.
7234 * {@hide}
7235 */
7236 @Override
7237 public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) {
7238 enforceModifyPermission();
7239 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007240
7241 final long identity = Binder.clearCallingIdentity();
fionaxu8da9cb12017-05-23 15:02:46 -07007242 if (phone == null) {
7243 loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId);
7244 return;
7245 }
7246 try {
7247 phone.carrierActionReportDefaultNetworkStatus(report);
7248 } catch (Exception e) {
7249 Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007250 } finally {
7251 Binder.restoreCallingIdentity(identity);
fionaxu8da9cb12017-05-23 15:02:46 -07007252 }
7253 }
7254
7255 /**
fionaxud9622282017-07-17 17:51:30 -07007256 * Action set from carrier signalling broadcast receivers to reset all carrier actions
7257 * @param subId the subscription ID that this action applies to.
7258 * {@hide}
7259 */
7260 @Override
7261 public void carrierActionResetAll(int subId) {
7262 enforceModifyPermission();
7263 final Phone phone = getPhone(subId);
7264 if (phone == null) {
7265 loge("carrierAction: ResetAll fails with invalid sibId: " + subId);
7266 return;
7267 }
7268 try {
7269 phone.carrierActionResetAll();
7270 } catch (Exception e) {
7271 Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e);
7272 }
7273 }
7274
7275 /**
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007276 * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a
7277 * bug report is being generated.
7278 */
7279 @Override
Ta-wei Yen99282e02016-06-21 18:19:35 -07007280 protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007281 if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
7282 != PackageManager.PERMISSION_GRANTED) {
dcashman22b950d2016-06-27 11:39:02 -07007283 writer.println("Permission Denial: can't dump Phone from pid="
7284 + Binder.getCallingPid()
7285 + ", uid=" + Binder.getCallingUid()
7286 + "without permission "
7287 + android.Manifest.permission.DUMP);
7288 return;
7289 }
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007290 DumpsysHandler.dump(mApp, fd, writer, args);
Ta-wei Yenc236d6b2016-06-21 13:33:12 -07007291 }
Jack Yueb89b242016-06-22 13:27:47 -07007292
Brad Ebingerdac2f002018-04-03 15:17:52 -07007293 @Override
Hall Liua1548bd2019-12-24 14:14:12 -08007294 public int handleShellCommand(@NonNull ParcelFileDescriptor in,
7295 @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err,
7296 @NonNull String[] args) {
7297 return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec(
7298 this, in.getFileDescriptor(), out.getFileDescriptor(),
7299 err.getFileDescriptor(), args);
Brad Ebingerdac2f002018-04-03 15:17:52 -07007300 }
7301
Jack Yueb89b242016-06-22 13:27:47 -07007302 /**
Jack Yu75ab2952016-07-08 14:29:33 -07007303 * Policy control of data connection. Usually used when data limit is passed.
7304 * @param enabled True if enabling the data, otherwise disabling.
7305 * @param subId Subscription index
7306 * {@hide}
7307 */
7308 @Override
7309 public void setPolicyDataEnabled(boolean enabled, int subId) {
7310 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007311
7312 final long identity = Binder.clearCallingIdentity();
7313 try {
7314 Phone phone = getPhone(subId);
7315 if (phone != null) {
Jack Yud79fba22018-12-13 11:51:28 -08007316 phone.getDataEnabledSettings().setPolicyDataEnabled(enabled);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007317 }
7318 } finally {
7319 Binder.restoreCallingIdentity(identity);
Jack Yu75ab2952016-07-08 14:29:33 -07007320 }
7321 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007322
7323 /**
7324 * Get Client request stats
7325 * @return List of Client Request Stats
7326 * @hide
7327 */
7328 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007329 public List<ClientRequestStats> getClientRequestStats(String callingPackage,
7330 String callingFeatureId, int subId) {
Jeff Davidson7e17e312018-02-13 18:17:36 -08007331 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007332 mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) {
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007333 return null;
7334 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007335 Phone phone = getPhone(subId);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007336
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007337 final long identity = Binder.clearCallingIdentity();
7338 try {
7339 if (phone != null) {
7340 return phone.getClientRequestStats();
7341 }
7342
7343 return null;
7344 } finally {
7345 Binder.restoreCallingIdentity(identity);
7346 }
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007347 }
7348
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007349 private WorkSource getWorkSource(int uid) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007350 String packageName = mApp.getPackageManager().getNameForUid(uid);
Narayan Kamathf04b5a12018-01-09 11:47:15 +00007351 return new WorkSource(uid, packageName);
Sooraj Sasindran9a909312016-07-18 11:57:25 -07007352 }
Jack Yueb4124c2017-02-16 15:32:43 -08007353
7354 /**
Grace Chen70990072017-03-24 17:21:30 -07007355 * Set SIM card power state.
Jack Yueb4124c2017-02-16 15:32:43 -08007356 *
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007357 * @param slotIndex SIM slot id.
Grace Chen70990072017-03-24 17:21:30 -07007358 * @param state State of SIM (power down, power up, pass through)
7359 * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN}
7360 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP}
7361 * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH}
Jack Yueb4124c2017-02-16 15:32:43 -08007362 *
7363 **/
7364 @Override
Grace Chen70990072017-03-24 17:21:30 -07007365 public void setSimPowerStateForSlot(int slotIndex, int state) {
Jack Yueb4124c2017-02-16 15:32:43 -08007366 enforceModifyPermission();
Sanket Padawe13bac7b2017-03-20 15:04:47 -07007367 Phone phone = PhoneFactory.getPhone(slotIndex);
7368
vagdeviaf9a5b92018-08-15 16:01:53 -07007369 WorkSource workSource = getWorkSource(Binder.getCallingUid());
7370
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007371 final long identity = Binder.clearCallingIdentity();
7372 try {
7373 if (phone != null) {
vagdeviaf9a5b92018-08-15 16:01:53 -07007374 phone.setSimPowerState(state, workSource);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007375 }
7376 } finally {
7377 Binder.restoreCallingIdentity(identity);
Jack Yueb4124c2017-02-16 15:32:43 -08007378 }
7379 }
Shuo Qiandd210312017-04-12 22:11:33 +00007380
Tyler Gunn65d45c22017-06-05 11:22:26 -07007381 private boolean isUssdApiAllowed(int subId) {
7382 CarrierConfigManager configManager =
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007383 (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Tyler Gunn65d45c22017-06-05 11:22:26 -07007384 if (configManager == null) {
7385 return false;
7386 }
7387 PersistableBundle pb = configManager.getConfigForSubId(subId);
7388 if (pb == null) {
7389 return false;
7390 }
7391 return pb.getBoolean(
7392 CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL);
7393 }
7394
Shuo Qiandd210312017-04-12 22:11:33 +00007395 /**
7396 * Check if phone is in emergency callback mode
7397 * @return true if phone is in emergency callback mode
7398 * @param subId sub id
7399 */
goneil9c5f4872017-12-05 14:07:56 -08007400 @Override
Shuo Qiandd210312017-04-12 22:11:33 +00007401 public boolean getEmergencyCallbackMode(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007402 enforceReadPrivilegedPermission("getEmergencyCallbackMode");
Shuo Qiandd210312017-04-12 22:11:33 +00007403 final Phone phone = getPhone(subId);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007404
7405 final long identity = Binder.clearCallingIdentity();
7406 try {
7407 if (phone != null) {
7408 return phone.isInEcm();
7409 } else {
7410 return false;
7411 }
7412 } finally {
7413 Binder.restoreCallingIdentity(identity);
Shuo Qiandd210312017-04-12 22:11:33 +00007414 }
7415 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007416
7417 /**
7418 * Get the current signal strength information for the given subscription.
7419 * Because this information is not updated when the device is in a low power state
7420 * it should not be relied-upon to be current.
7421 * @param subId Subscription index
7422 * @return the most recent cached signal strength info from the modem
7423 */
7424 @Override
7425 public SignalStrength getSignalStrength(int subId) {
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007426 final long identity = Binder.clearCallingIdentity();
7427 try {
7428 Phone p = getPhone(subId);
7429 if (p == null) {
7430 return null;
7431 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007432
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007433 return p.getSignalStrength();
7434 } finally {
7435 Binder.restoreCallingIdentity(identity);
7436 }
Nathan Harold46b42aa2017-03-10 19:38:22 -08007437 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007438
Pengquan Meng77b7f132018-08-22 14:49:57 -07007439 /**
Chen Xuf792fd62018-10-17 17:54:36 +00007440 * Get the current modem radio state for the given slot.
7441 * @param slotIndex slot index.
7442 * @param callingPackage the name of the package making the call.
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007443 * @param callingFeatureId The feature in the package.
Chen Xuf792fd62018-10-17 17:54:36 +00007444 * @return the current radio power state from the modem
7445 */
7446 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007447 public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) {
Chen Xuf792fd62018-10-17 17:54:36 +00007448 Phone phone = PhoneFactory.getPhone(slotIndex);
7449 if (phone != null) {
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007450 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(),
7451 callingPackage, callingFeatureId, "getRadioPowerState")) {
Chen Xuf792fd62018-10-17 17:54:36 +00007452 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7453 }
7454
7455 final long identity = Binder.clearCallingIdentity();
7456 try {
7457 return phone.getRadioPowerState();
7458 } finally {
7459 Binder.restoreCallingIdentity(identity);
7460 }
7461 }
7462 return TelephonyManager.RADIO_POWER_UNAVAILABLE;
7463 }
7464
7465 /**
Pengquan Meng77b7f132018-08-22 14:49:57 -07007466 * Checks if data roaming is enabled on the subscription with id {@code subId}.
7467 *
7468 * <p>Requires one of the following permissions:
7469 * {@link android.Manifest.permission#ACCESS_NETWORK_STATE},
7470 * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier
7471 * privileges.
7472 *
7473 * @param subId subscription id
7474 * @return {@code true} if data roaming is enabled on this subscription, otherwise return
7475 * {@code false}.
7476 */
7477 @Override
7478 public boolean isDataRoamingEnabled(int subId) {
Shuo Qian11263f32020-08-13 15:42:55 -07007479 try {
7480 mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE,
7481 null);
7482 } catch (Exception e) {
7483 TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege(
7484 mApp, subId, "isDataRoamingEnabled");
7485 }
Pengquan Meng44e66f12019-04-01 10:48:20 -07007486
Pengquan Menga1bb6272018-09-06 09:59:22 -07007487 boolean isEnabled = false;
7488 final long identity = Binder.clearCallingIdentity();
Pengquan Meng77b7f132018-08-22 14:49:57 -07007489 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007490 Phone phone = getPhone(subId);
7491 isEnabled = phone != null ? phone.getDataRoamingEnabled() : false;
Pengquan Menga1bb6272018-09-06 09:59:22 -07007492 } finally {
7493 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007494 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007495 return isEnabled;
Pengquan Meng77b7f132018-08-22 14:49:57 -07007496 }
7497
7498
7499 /**
7500 * Enables/Disables the data roaming on the subscription with id {@code subId}.
7501 *
7502 * <p> Requires permission:
7503 * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier
7504 * privileges.
7505 *
7506 * @param subId subscription id
7507 * @param isEnabled {@code true} means enable, {@code false} means disable.
7508 */
7509 @Override
7510 public void setDataRoamingEnabled(int subId, boolean isEnabled) {
Pengquan Meng44e66f12019-04-01 10:48:20 -07007511 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7512 mApp, subId, "setDataRoamingEnabled");
7513
Pengquan Menga1bb6272018-09-06 09:59:22 -07007514 final long identity = Binder.clearCallingIdentity();
7515 try {
Pengquan Menga1bb6272018-09-06 09:59:22 -07007516 Phone phone = getPhone(subId);
7517 if (phone != null) {
7518 phone.setDataRoamingEnabled(isEnabled);
7519 }
7520 } finally {
7521 Binder.restoreCallingIdentity(identity);
Pengquan Meng77b7f132018-08-22 14:49:57 -07007522 }
7523 }
7524
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007525 @Override
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007526 public boolean isManualNetworkSelectionAllowed(int subId) {
tom hsuc91afc72020-01-06 23:46:07 +08007527 TelephonyPermissions
7528 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Meng44e66f12019-04-01 10:48:20 -07007529 mApp, subId, "isManualNetworkSelectionAllowed");
7530
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007531 boolean isAllowed = true;
7532 final long identity = Binder.clearCallingIdentity();
7533 try {
Pengquan Meng6884a2c2018-10-03 12:19:13 -07007534 Phone phone = getPhone(subId);
7535 if (phone != null) {
7536 isAllowed = phone.isCspPlmnEnabled();
7537 }
7538 } finally {
7539 Binder.restoreCallingIdentity(identity);
7540 }
7541 return isAllowed;
7542 }
7543
7544 @Override
Jordan Liu75f43ea2019-01-17 16:56:37 -08007545 public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
Jordan Liucfdfe3a2020-03-23 11:55:07 -07007546 // Verify that tha callingPackage belongs to the calling UID
7547 mApp.getSystemService(AppOpsManager.class)
7548 .checkPackage(Binder.getCallingUid(), callingPackage);
7549
Jordan Liu1e142fc2019-04-22 15:10:43 -07007550 boolean hasReadPermission = false;
Jordan Liuc65bc952019-02-12 17:54:02 -08007551 try {
7552 enforceReadPrivilegedPermission("getUiccCardsInfo");
Jordan Liu1e142fc2019-04-22 15:10:43 -07007553 hasReadPermission = true;
Jordan Liuc65bc952019-02-12 17:54:02 -08007554 } catch (SecurityException e) {
7555 // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller
7556 // has carrier privileges on an active UICC
7557 if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage)
7558 != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
Jordan Liu1e142fc2019-04-22 15:10:43 -07007559 throw new SecurityException("Caller does not have permission.");
Jordan Liuc65bc952019-02-12 17:54:02 -08007560 }
Jordan Liu75f43ea2019-01-17 16:56:37 -08007561 }
Jordan Liu5aa07002018-12-18 15:44:48 -08007562
7563 final long identity = Binder.clearCallingIdentity();
7564 try {
Jordan Liu75f43ea2019-01-17 16:56:37 -08007565 UiccController uiccController = UiccController.getInstance();
7566 ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos();
Jordan Liu1e142fc2019-04-22 15:10:43 -07007567 if (hasReadPermission) {
7568 return cardInfos;
Jordan Liu75f43ea2019-01-17 16:56:37 -08007569 }
Jordan Liu1e142fc2019-04-22 15:10:43 -07007570
7571 // Remove private info if the caller doesn't have access
7572 ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>();
7573 for (UiccCardInfo cardInfo : cardInfos) {
7574 // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo
7575 // is available
7576 UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex());
7577 if (card == null || card.getUiccProfile() == null) {
7578 // assume no access if the card or profile is unavailable
7579 filteredInfos.add(cardInfo.getUnprivileged());
7580 continue;
7581 }
7582 UiccProfile profile = card.getUiccProfile();
7583 if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage)
7584 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
7585 filteredInfos.add(cardInfo);
7586 } else {
7587 filteredInfos.add(cardInfo.getUnprivileged());
7588 }
7589 }
7590 return filteredInfos;
Jordan Liu5aa07002018-12-18 15:44:48 -08007591 } finally {
7592 Binder.restoreCallingIdentity(identity);
7593 }
7594 }
7595
7596 @Override
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007597 public UiccSlotInfo[] getUiccSlotsInfo() {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007598 enforceReadPrivilegedPermission("getUiccSlotsInfo");
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007599
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007600 final long identity = Binder.clearCallingIdentity();
7601 try {
7602 UiccSlot[] slots = UiccController.getInstance().getUiccSlots();
7603 if (slots == null) {
7604 Rlog.i(LOG_TAG, "slots is null.");
7605 return null;
7606 }
7607
7608 UiccSlotInfo[] infos = new UiccSlotInfo[slots.length];
7609 for (int i = 0; i < slots.length; i++) {
7610 UiccSlot slot = slots[i];
7611 if (slot == null) {
7612 continue;
7613 }
7614
Jordan Liu7be7e652019-05-06 18:55:02 +00007615 String cardId;
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007616 UiccCard card = slot.getUiccCard();
7617 if (card != null) {
7618 cardId = card.getCardId();
Jordan Liu7be7e652019-05-06 18:55:02 +00007619 } else {
Jordan Liud96b5292019-09-12 16:19:43 -07007620 cardId = slot.getEid();
7621 if (TextUtils.isEmpty(cardId)) {
7622 cardId = slot.getIccId();
7623 }
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007624 }
7625
Jordan Liu857451f2019-05-09 16:35:35 -07007626 if (cardId != null) {
7627 // if cardId is an ICCID, strip off trailing Fs before exposing to user
7628 // if cardId is an EID, it's all digits so this is fine
7629 cardId = IccUtils.stripTrailingFs(cardId);
7630 }
7631
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007632 int cardState = 0;
7633 switch (slot.getCardState()) {
7634 case CARDSTATE_ABSENT:
7635 cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT;
7636 break;
7637 case CARDSTATE_PRESENT:
7638 cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT;
7639 break;
7640 case CARDSTATE_ERROR:
7641 cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR;
7642 break;
7643 case CARDSTATE_RESTRICTED:
7644 cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED;
7645 break;
7646 default:
7647 break;
7648
7649 }
7650
7651 infos[i] = new UiccSlotInfo(
7652 slot.isActive(),
7653 slot.isEuicc(),
7654 cardId,
7655 cardState,
7656 slot.getPhoneId(),
Jordan Liua2619582019-02-14 12:56:40 -08007657 slot.isExtendedApduSupported(),
7658 slot.isRemovable());
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007659 }
7660 return infos;
7661 } finally {
7662 Binder.restoreCallingIdentity(identity);
Holly Jiuyu Sun1d957c52018-04-04 13:52:42 -07007663 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007664 }
7665
7666 @Override
7667 public boolean switchSlots(int[] physicalSlots) {
7668 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007669
7670 final long identity = Binder.clearCallingIdentity();
7671 try {
7672 return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots);
7673 } finally {
7674 Binder.restoreCallingIdentity(identity);
7675 }
Holly Jiuyu Sun01c47ad2018-01-24 17:56:33 +00007676 }
Jack Yu4c988042018-02-27 15:30:01 -08007677
7678 @Override
Jordan Liu7de49fa2018-12-06 14:48:49 -08007679 public int getCardIdForDefaultEuicc(int subId, String callingPackage) {
Jordan Liu7de49fa2018-12-06 14:48:49 -08007680 final long identity = Binder.clearCallingIdentity();
7681 try {
7682 return UiccController.getInstance().getCardIdForDefaultEuicc();
7683 } finally {
7684 Binder.restoreCallingIdentity(identity);
7685 }
7686 }
7687
Pengquan Meng85728fb2018-03-12 16:31:21 -07007688 /**
goneil47ffb6e2018-04-06 15:40:58 -07007689 * A test API to reload the UICC profile.
7690 *
7691 * <p>Requires that the calling app has permission
7692 * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}.
7693 * @hide
7694 */
7695 @Override
7696 public void refreshUiccProfile(int subId) {
7697 enforceModifyPermission();
7698
7699 final long identity = Binder.clearCallingIdentity();
7700 try {
7701 Phone phone = getPhone(subId);
7702 if (phone == null) {
7703 return;
7704 }
7705 UiccCard uiccCard = phone.getUiccCard();
7706 if (uiccCard == null) {
7707 return;
7708 }
7709 UiccProfile uiccProfile = uiccCard.getUiccProfile();
7710 if (uiccProfile == null) {
7711 return;
7712 }
7713 uiccProfile.refresh();
7714 } finally {
7715 Binder.restoreCallingIdentity(identity);
7716 }
7717 }
7718
7719 /**
Pengquan Meng85728fb2018-03-12 16:31:21 -07007720 * Returns false if the mobile data is disabled by default, otherwise return true.
7721 */
7722 private boolean getDefaultDataEnabled() {
Inseob Kim8d298d42018-12-13 17:11:34 +09007723 return TelephonyProperties.mobile_data().orElse(true);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007724 }
7725
7726 /**
7727 * Returns true if the data roaming is enabled by default, i.e the system property
7728 * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of
7729 * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true.
7730 */
7731 private boolean getDefaultDataRoamingEnabled(int subId) {
7732 final CarrierConfigManager configMgr = (CarrierConfigManager)
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007733 mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE);
Shuo Qianfaaa63d2020-07-15 12:36:44 -07007734 boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false);
Pengquan Meng85728fb2018-03-12 16:31:21 -07007735 isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean(
7736 CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL);
7737 return isDataRoamingEnabled;
7738 }
7739
7740 /**
7741 * Returns the default network type for the given {@code subId}, if the default network type is
7742 * not set, return {@link Phone#PREFERRED_NT_MODE}.
7743 */
7744 private int getDefaultNetworkType(int subId) {
Inseob Kim8d298d42018-12-13 17:11:34 +09007745 List<Integer> list = TelephonyProperties.default_network();
7746 int phoneId = mSubscriptionController.getPhoneId(subId);
7747 if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) {
7748 return list.get(phoneId);
7749 }
7750 return Phone.PREFERRED_NT_MODE;
Pengquan Meng85728fb2018-03-12 16:31:21 -07007751 }
fionaxua13278b2018-03-21 00:08:13 -07007752
7753 @Override
7754 public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String
chen xueaba88a2019-03-15 13:15:10 -07007755 gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) {
fionaxua13278b2018-03-21 00:08:13 -07007756 enforceModifyPermission();
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007757
7758 final long identity = Binder.clearCallingIdentity();
7759 try {
7760 final Phone phone = getPhone(subId);
7761 if (phone == null) {
7762 loge("setCarrierTestOverride fails with invalid subId: " + subId);
7763 return;
7764 }
chen xueaba88a2019-03-15 13:15:10 -07007765 phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn,
7766 carrierPrivilegeRules, apn);
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007767 } finally {
7768 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007769 }
fionaxua13278b2018-03-21 00:08:13 -07007770 }
7771
7772 @Override
7773 public int getCarrierIdListVersion(int subId) {
Brad Ebinger35c841c2018-10-01 10:40:55 -07007774 enforceReadPrivilegedPermission("getCarrierIdListVersion");
Malcolm Chenaa4a8532018-02-28 15:00:40 -08007775
7776 final long identity = Binder.clearCallingIdentity();
7777 try {
7778 final Phone phone = getPhone(subId);
7779 if (phone == null) {
7780 loge("getCarrierIdListVersion fails with invalid subId: " + subId);
7781 return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION;
7782 }
7783 return phone.getCarrierIdListVersion();
7784 } finally {
7785 Binder.restoreCallingIdentity(identity);
fionaxua13278b2018-03-21 00:08:13 -07007786 }
fionaxua13278b2018-03-21 00:08:13 -07007787 }
Malcolm Chen2c63d402018-08-14 16:00:53 -07007788
7789 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007790 public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage,
7791 String callingFeatureId) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007792 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007793 mApp, subId, callingPackage, callingFeatureId,
7794 "getNumberOfModemsWithSimultaneousDataConnections")) {
Malcolm Chen2c63d402018-08-14 16:00:53 -07007795 return -1;
7796 }
7797
7798 final long identity = Binder.clearCallingIdentity();
7799 try {
7800 return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections();
7801 } finally {
7802 Binder.restoreCallingIdentity(identity);
7803 }
7804 }
Pengquan Menga1bb6272018-09-06 09:59:22 -07007805
7806 @Override
7807 public int getCdmaRoamingMode(int subId) {
zoey chen07238702019-12-17 18:18:59 +08007808 TelephonyPermissions
7809 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
Pengquan Menga1bb6272018-09-06 09:59:22 -07007810 mApp, subId, "getCdmaRoamingMode");
7811
7812 final long identity = Binder.clearCallingIdentity();
7813 try {
7814 return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId);
7815 } finally {
7816 Binder.restoreCallingIdentity(identity);
7817 }
7818 }
7819
7820 @Override
7821 public boolean setCdmaRoamingMode(int subId, int mode) {
7822 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7823 mApp, subId, "setCdmaRoamingMode");
7824
7825 final long identity = Binder.clearCallingIdentity();
7826 try {
7827 return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId);
7828 } finally {
7829 Binder.restoreCallingIdentity(identity);
7830 }
7831 }
7832
7833 @Override
7834 public boolean setCdmaSubscriptionMode(int subId, int mode) {
7835 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
7836 mApp, subId, "setCdmaSubscriptionMode");
7837
7838 final long identity = Binder.clearCallingIdentity();
7839 try {
7840 return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId);
7841 } finally {
7842 Binder.restoreCallingIdentity(identity);
7843 }
7844 }
Makoto Onukida3bf792018-09-18 16:06:29 -07007845
sqianc5eccab2018-10-19 18:46:41 -07007846 @Override
sqian8c685422019-02-22 15:55:18 -08007847 public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007848 String callingPackage, String callingFeatureId) {
sqian11b7a0e2018-12-05 18:48:28 -08007849 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08007850 mApp, getDefaultSubscription(), callingPackage, callingFeatureId,
7851 "getEmergencyNumberList")) {
sqian11b7a0e2018-12-05 18:48:28 -08007852 throw new SecurityException("Requires READ_PHONE_STATE permission.");
7853 }
7854 final long identity = Binder.clearCallingIdentity();
7855 try {
sqian854d44b2018-12-12 16:48:18 -08007856 Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>();
7857 for (Phone phone: PhoneFactory.getPhones()) {
7858 if (phone.getEmergencyNumberTracker() != null
7859 && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) {
7860 emergencyNumberListInternal.put(
7861 phone.getSubId(),
7862 phone.getEmergencyNumberTracker().getEmergencyNumberList());
7863 }
sqian11b7a0e2018-12-05 18:48:28 -08007864 }
sqian854d44b2018-12-12 16:48:18 -08007865 return emergencyNumberListInternal;
sqian11b7a0e2018-12-05 18:48:28 -08007866 } finally {
7867 Binder.restoreCallingIdentity(identity);
7868 }
sqianc5eccab2018-10-19 18:46:41 -07007869 }
7870
7871 @Override
sqian8c685422019-02-22 15:55:18 -08007872 public boolean isEmergencyNumber(String number, boolean exactMatch) {
Nazanin Bakhshif782e562018-12-11 15:15:39 -08007873 final Phone defaultPhone = getDefaultPhone();
sqian11b7a0e2018-12-05 18:48:28 -08007874 if (!exactMatch) {
7875 TelephonyPermissions
7876 .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
sqian8c685422019-02-22 15:55:18 -08007877 mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)");
sqian11b7a0e2018-12-05 18:48:28 -08007878 }
7879 final long identity = Binder.clearCallingIdentity();
7880 try {
sqian854d44b2018-12-12 16:48:18 -08007881 for (Phone phone: PhoneFactory.getPhones()) {
7882 if (phone.getEmergencyNumberTracker() != null
7883 && phone.getEmergencyNumberTracker() != null) {
7884 if (phone.getEmergencyNumberTracker().isEmergencyNumber(
7885 number, exactMatch)) {
7886 return true;
sqian11b7a0e2018-12-05 18:48:28 -08007887 }
7888 }
sqian11b7a0e2018-12-05 18:48:28 -08007889 }
7890 return false;
7891 } finally {
7892 Binder.restoreCallingIdentity(identity);
7893 }
7894 }
7895
sqianf4ca7ed2019-01-15 18:32:07 -08007896 /**
7897 * Update emergency number list for test mode.
7898 */
7899 @Override
7900 public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) {
7901 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7902 "updateEmergencyNumberListTestMode");
7903
7904 final long identity = Binder.clearCallingIdentity();
7905 try {
7906 for (Phone phone: PhoneFactory.getPhones()) {
7907 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7908 if (tracker != null) {
7909 tracker.executeEmergencyNumberTestModeCommand(action, num);
7910 }
7911 }
7912 } finally {
7913 Binder.restoreCallingIdentity(identity);
7914 }
7915 }
7916
7917 /**
7918 * Get the full emergency number list for test mode.
7919 */
7920 @Override
7921 public List<String> getEmergencyNumberListTestMode() {
7922 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
7923 "getEmergencyNumberListTestMode");
7924
7925 final long identity = Binder.clearCallingIdentity();
7926 try {
7927 Set<String> emergencyNumbers = new HashSet<>();
7928 for (Phone phone: PhoneFactory.getPhones()) {
7929 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7930 if (tracker != null) {
7931 for (EmergencyNumber num : tracker.getEmergencyNumberList()) {
7932 emergencyNumbers.add(num.getNumber());
7933 }
7934 }
7935 }
7936 return new ArrayList<>(emergencyNumbers);
7937 } finally {
7938 Binder.restoreCallingIdentity(identity);
7939 }
7940 }
7941
chen xud6b45bd2018-10-30 22:27:10 -07007942 @Override
Shuo Qianf2b2df42019-11-13 17:43:31 -08007943 public int getEmergencyNumberDbVersion(int subId) {
7944 enforceReadPrivilegedPermission("getEmergencyNumberDbVersion");
7945
7946 final long identity = Binder.clearCallingIdentity();
7947 try {
7948 final Phone phone = getPhone(subId);
7949 if (phone == null) {
7950 loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId);
7951 return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION;
7952 }
7953 return phone.getEmergencyNumberDbVersion();
7954 } finally {
7955 Binder.restoreCallingIdentity(identity);
7956 }
7957 }
7958
7959 @Override
7960 public void notifyOtaEmergencyNumberDbInstalled() {
7961 enforceModifyPermission();
7962
7963 final long identity = Binder.clearCallingIdentity();
7964 try {
7965 for (Phone phone: PhoneFactory.getPhones()) {
7966 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7967 if (tracker != null) {
7968 tracker.updateOtaEmergencyNumberDatabase();
7969 }
7970 }
7971 } finally {
7972 Binder.restoreCallingIdentity(identity);
7973 }
7974 }
7975
7976 @Override
Shuo Qianb15c6be2020-03-05 17:55:34 -08007977 public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) {
Shuo Qianf2b2df42019-11-13 17:43:31 -08007978 enforceActiveEmergencySessionPermission();
7979
7980 final long identity = Binder.clearCallingIdentity();
7981 try {
7982 for (Phone phone: PhoneFactory.getPhones()) {
7983 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
7984 if (tracker != null) {
Shuo Qianb15c6be2020-03-05 17:55:34 -08007985 tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor);
7986 }
7987 }
7988 } finally {
7989 Binder.restoreCallingIdentity(identity);
7990 }
7991 }
7992
7993 @Override
7994 public void resetOtaEmergencyNumberDbFilePath() {
7995 enforceActiveEmergencySessionPermission();
7996
7997 final long identity = Binder.clearCallingIdentity();
7998 try {
7999 for (Phone phone: PhoneFactory.getPhones()) {
8000 EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker();
8001 if (tracker != null) {
8002 tracker.resetOtaEmergencyNumberDbFilePath();
Shuo Qianf2b2df42019-11-13 17:43:31 -08008003 }
8004 }
8005 } finally {
8006 Binder.restoreCallingIdentity(identity);
8007 }
8008 }
8009
8010 @Override
chen xud6b45bd2018-10-30 22:27:10 -07008011 public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) {
8012 enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules");
8013 Phone phone = getPhone(subId);
8014 if (phone == null) {
8015 return null;
8016 }
8017 final long identity = Binder.clearCallingIdentity();
8018 try {
8019 UiccProfile profile = UiccController.getInstance()
8020 .getUiccProfileForPhone(phone.getPhoneId());
8021 if (profile != null) {
8022 return profile.getCertsFromCarrierPrivilegeAccessRules();
8023 }
8024 } finally {
8025 Binder.restoreCallingIdentity(identity);
8026 }
8027 return null;
8028 }
Malcolm Chen8e4ed912019-01-15 20:22:16 -08008029
8030 /**
8031 * Enable or disable a modem stack.
8032 */
8033 @Override
8034 public boolean enableModemForSlot(int slotIndex, boolean enable) {
8035 enforceModifyPermission();
8036
8037 final long identity = Binder.clearCallingIdentity();
8038 try {
8039 Phone phone = PhoneFactory.getPhone(slotIndex);
8040 if (phone == null) {
8041 return false;
8042 } else {
8043 return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null);
8044 }
8045 } finally {
8046 Binder.restoreCallingIdentity(identity);
8047 }
8048 }
Michelecea4cf22018-12-21 15:00:11 -08008049
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008050 /**
8051 * Whether a modem stack is enabled or not.
8052 */
8053 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008054 public boolean isModemEnabledForSlot(int slotIndex, String callingPackage,
8055 String callingFeatureId) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008056 Phone phone = PhoneFactory.getPhone(slotIndex);
8057 if (phone == null) return false;
8058
8059 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008060 mApp, phone.getSubId(), callingPackage, callingFeatureId,
8061 "isModemEnabledForSlot")) {
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008062 throw new SecurityException("Requires READ_PHONE_STATE permission.");
8063 }
8064
8065 final long identity = Binder.clearCallingIdentity();
8066 try {
Nazanin Bakhshif71371d2019-04-29 17:29:44 -07008067 try {
8068 return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId());
8069 } catch (NoSuchElementException ex) {
8070 return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null);
8071 }
Malcolm Chen4bcd9822019-03-27 18:34:05 -07008072 } finally {
8073 Binder.restoreCallingIdentity(identity);
8074 }
8075 }
8076
Michelecea4cf22018-12-21 15:00:11 -08008077 @Override
Michele0ea7d782019-03-19 14:58:42 -07008078 public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) {
Michelecea4cf22018-12-21 15:00:11 -08008079 enforceModifyPermission();
8080
8081 final long identity = Binder.clearCallingIdentity();
8082 try {
8083 mTelephonySharedPreferences.edit()
Michele0ea7d782019-03-19 14:58:42 -07008084 .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted)
Michelecea4cf22018-12-21 15:00:11 -08008085 .commit();
8086 } finally {
8087 Binder.restoreCallingIdentity(identity);
8088 }
8089 }
8090
8091 @Override
Michele0ea7d782019-03-19 14:58:42 -07008092 @TelephonyManager.IsMultiSimSupportedResult
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008093 public int isMultiSimSupported(String callingPackage, String callingFeatureId) {
Michele4245e952019-02-04 11:36:23 -08008094 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp,
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008095 getDefaultPhone().getSubId(), callingPackage, callingFeatureId,
8096 "isMultiSimSupported")) {
Michele0ea7d782019-03-19 14:58:42 -07008097 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele4245e952019-02-04 11:36:23 -08008098 }
Michelecea4cf22018-12-21 15:00:11 -08008099
8100 final long identity = Binder.clearCallingIdentity();
8101 try {
Michele0ea7d782019-03-19 14:58:42 -07008102 return isMultiSimSupportedInternal();
Michelecea4cf22018-12-21 15:00:11 -08008103 } finally {
8104 Binder.restoreCallingIdentity(identity);
8105 }
8106 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008107
Michele0ea7d782019-03-19 14:58:42 -07008108 @TelephonyManager.IsMultiSimSupportedResult
8109 private int isMultiSimSupportedInternal() {
Michele30b57b22019-03-01 12:01:14 -08008110 // If the device has less than 2 SIM cards, indicate that multisim is restricted.
8111 int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length;
8112 if (numPhysicalSlots < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008113 loge("isMultiSimSupportedInternal: requires at least 2 cards");
8114 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008115 }
8116 // Check if the hardware supports multisim functionality. If usage of multisim is not
8117 // supported by the modem, indicate that it is restricted.
8118 PhoneCapability staticCapability =
8119 mPhoneConfigurationManager.getStaticPhoneCapability();
8120 if (staticCapability == null) {
Michele0ea7d782019-03-19 14:58:42 -07008121 loge("isMultiSimSupportedInternal: no static configuration available");
8122 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008123 }
Sarah Chin09f38ee2020-02-25 00:13:10 +00008124 if (staticCapability.logicalModemList.size() < 2) {
Michele0ea7d782019-03-19 14:58:42 -07008125 loge("isMultiSimSupportedInternal: maximum number of modem is < 2");
8126 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE;
Michele30b57b22019-03-01 12:01:14 -08008127 }
8128 // Check if support of multiple SIMs is restricted by carrier
8129 if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) {
Michele0ea7d782019-03-19 14:58:42 -07008130 return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER;
Michele30b57b22019-03-01 12:01:14 -08008131 }
8132
Michele0ea7d782019-03-19 14:58:42 -07008133 return TelephonyManager.MULTISIM_ALLOWED;
Michele30b57b22019-03-01 12:01:14 -08008134 }
8135
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008136 /**
8137 * Switch configs to enable multi-sim or switch back to single-sim
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008138 * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE
8139 * permission, but the other way around is possible with either MODIFY_PHONE_STATE
8140 * or carrier privileges
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008141 * @param numOfSims number of active sims we want to switch to
8142 */
8143 @Override
8144 public void switchMultiSimConfig(int numOfSims) {
Nazanin Bakhshi17318782019-03-01 11:56:08 -08008145 if (numOfSims == 1) {
8146 enforceModifyPermission();
8147 } else {
8148 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8149 mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig");
8150 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008151 final long identity = Binder.clearCallingIdentity();
Michele30b57b22019-03-01 12:01:14 -08008152
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008153 try {
Michele30b57b22019-03-01 12:01:14 -08008154 //only proceed if multi-sim is not restricted
Michele0ea7d782019-03-19 14:58:42 -07008155 if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) {
Michele30b57b22019-03-01 12:01:14 -08008156 loge("switchMultiSimConfig not possible. It is restricted or not supported.");
8157 return;
8158 }
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008159 mPhoneConfigurationManager.switchMultiSimConfig(numOfSims);
8160 } finally {
8161 Binder.restoreCallingIdentity(identity);
8162 }
8163 }
8164
Hyungjun Parkbb07fde2019-01-10 15:28:51 +09008165 @Override
8166 public boolean isApplicationOnUicc(int subId, int appType) {
8167 enforceReadPrivilegedPermission("isApplicationOnUicc");
8168 Phone phone = getPhone(subId);
8169 if (phone == null) {
8170 return false;
8171 }
8172 final long identity = Binder.clearCallingIdentity();
8173 try {
8174 UiccCard uiccCard = phone.getUiccCard();
8175 if (uiccCard == null) {
8176 return false;
8177 }
8178 UiccProfile uiccProfile = uiccCard.getUiccProfile();
8179 if (uiccProfile == null) {
8180 return false;
8181 }
8182 if (TelephonyManager.APPTYPE_SIM <= appType
8183 && appType <= TelephonyManager.APPTYPE_ISIM) {
8184 return uiccProfile.isApplicationOnIcc(AppType.values()[appType]);
8185 }
8186 return false;
8187 } finally {
8188 Binder.restoreCallingIdentity(identity);
8189 }
8190 }
8191
Nazanin Bakhshi628473f2019-01-29 17:37:52 -08008192 /**
chen xub4baa772019-04-03 10:23:41 -07008193 * Get whether making changes to modem configurations will trigger reboot.
8194 * Return value defaults to true.
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008195 */
8196 @Override
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008197 public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage,
8198 String callingFeatureId) {
chen xub4baa772019-04-03 10:23:41 -07008199 if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(
Philip P. Moltmann9797cbb2020-01-07 13:45:00 -08008200 mApp, subId, callingPackage, callingFeatureId,
8201 "doesSwitchMultiSimConfigTriggerReboot")) {
chen xub4baa772019-04-03 10:23:41 -07008202 return false;
8203 }
Nazanin Bakhshi5fe5ef22019-01-30 10:52:09 -08008204 final long identity = Binder.clearCallingIdentity();
8205 try {
8206 return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange();
8207 } finally {
8208 Binder.restoreCallingIdentity(identity);
8209 }
8210 }
8211
Nathan Harold29f5f052019-02-15 13:41:57 -08008212 private void updateModemStateMetrics() {
8213 TelephonyMetrics metrics = TelephonyMetrics.getInstance();
8214 // TODO: check the state for each modem if the api is ready.
8215 metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1);
8216 }
8217
Pengquan Meng3889a572019-01-23 11:16:29 -08008218 @Override
8219 public int[] getSlotsMapping() {
8220 enforceReadPrivilegedPermission("getSlotsMapping");
8221
8222 final long identity = Binder.clearCallingIdentity();
8223 try {
8224 int phoneCount = TelephonyManager.getDefault().getPhoneCount();
8225 // All logical slots should have a mapping to a physical slot.
8226 int[] logicalSlotsMapping = new int[phoneCount];
8227 UiccSlotInfo[] slotInfos = getUiccSlotsInfo();
8228 for (int i = 0; i < slotInfos.length; i++) {
8229 if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
8230 logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
8231 }
8232 }
8233 return logicalSlotsMapping;
8234 } finally {
8235 Binder.restoreCallingIdentity(identity);
8236 }
8237 }
Nathan Harold48d6fd52019-02-06 19:01:40 -08008238
8239 /**
8240 * Get the IRadio HAL Version
8241 */
8242 @Override
8243 public int getRadioHalVersion() {
8244 Phone phone = getDefaultPhone();
8245 if (phone == null) return -1;
8246 HalVersion hv = phone.getHalVersion();
8247 if (hv.equals(HalVersion.UNKNOWN)) return -1;
8248 return hv.major * 100 + hv.minor;
8249 }
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008250
8251 /**
Shuo Qianaf42a312020-01-14 15:18:28 -08008252 * Get the current calling package name.
8253 * @return the current calling package name
8254 */
8255 @Override
8256 public String getCurrentPackageName() {
8257 return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0];
8258 }
8259
8260 /**
Malcolm Chene5ad5792019-04-18 13:51:02 -07008261 * Return whether data is enabled for certain APN type. This will tell if framework will accept
8262 * corresponding network requests on a subId.
8263 *
8264 * Data is enabled if:
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008265 * 1) user data is turned on, or
Malcolm Chene5ad5792019-04-18 13:51:02 -07008266 * 2) APN is un-metered for this subscription, or
8267 * 3) APN type is whitelisted. E.g. MMS is whitelisted if
changbetty97defcf2019-12-24 15:40:37 +08008268 * {@link TelephonyManager#setAlwaysAllowMmsData} is turned on.
Malcolm Chene5ad5792019-04-18 13:51:02 -07008269 *
8270 * @return whether data is allowed for a apn type.
8271 *
8272 * @hide
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008273 */
8274 @Override
Malcolm Chene5ad5792019-04-18 13:51:02 -07008275 public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) {
Amit Mahajanf2509742019-10-07 16:20:43 -07008276 enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for "
8277 + "isDataEnabledForApn");
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008278
8279 // Now that all security checks passes, perform the operation as ourselves.
8280 final long identity = Binder.clearCallingIdentity();
8281 try {
8282 Phone phone = getPhone(subId);
8283 if (phone == null) return false;
8284
Jack Yu41407ee2019-05-13 16:54:09 -07008285 boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chene5ad5792019-04-18 13:51:02 -07008286 return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType);
8287 } finally {
8288 Binder.restoreCallingIdentity(identity);
8289 }
8290 }
8291
8292 @Override
Jack Yu41407ee2019-05-13 16:54:09 -07008293 public boolean isApnMetered(@ApnType int apnType, int subId) {
Malcolm Chene5ad5792019-04-18 13:51:02 -07008294 enforceReadPrivilegedPermission("isApnMetered");
8295
8296 // Now that all security checks passes, perform the operation as ourselves.
8297 final long identity = Binder.clearCallingIdentity();
8298 try {
8299 Phone phone = getPhone(subId);
8300 if (phone == null) return true; // By default return true.
8301
Jack Yu41407ee2019-05-13 16:54:09 -07008302 return ApnSettingUtils.isMeteredApnType(apnType, phone);
Malcolm Chendc8c10e2019-04-10 18:25:07 -07008303 } finally {
8304 Binder.restoreCallingIdentity(identity);
8305 }
8306 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008307
8308 @Override
Hall Liud0d1dc92020-01-20 13:42:00 -08008309 public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers,
8310 int subscriptionId, IBooleanConsumer resultCallback) {
8311 enforceModifyPermission();
8312 long token = Binder.clearCallingIdentity();
8313 try {
8314 Phone phone = getPhone(subscriptionId);
8315 if (phone == null) {
8316 try {
8317 if (resultCallback != null) {
8318 resultCallback.accept(false);
8319 }
8320 } catch (RemoteException e) {
8321 // ignore
8322 }
8323 return;
8324 }
8325 Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument =
8326 Pair.create(specifiers, (x) -> {
8327 try {
8328 if (resultCallback != null) {
8329 resultCallback.accept(x);
8330 }
8331 } catch (RemoteException e) {
8332 // ignore
8333 }
8334 });
8335 sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null);
8336 } finally {
8337 Binder.restoreCallingIdentity(token);
8338 }
8339 }
8340
8341 @Override
changbetty363e8ac2019-12-06 18:16:37 +08008342 public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) {
changbettyca3d40d2020-03-03 16:27:31 +08008343 enforceReadPrivilegedPermission("isMvnoMatched");
changbetty363e8ac2019-12-06 18:16:37 +08008344 IccRecords iccRecords = UiccController.getInstance().getIccRecords(
8345 SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP);
8346 if (iccRecords == null) {
8347 Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null");
8348 return false;
8349 }
8350 return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData);
8351 }
8352
8353 @Override
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008354 public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag,
8355 IIntegerConsumer pendingSubIdResult) {
Shuo Qianaf42a312020-01-14 15:18:28 -08008356 if (callingPackage == null) {
8357 callingPackage = getCurrentPackageName();
8358 }
Brad Ebingera63db5f2019-04-23 16:31:13 -07008359 SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp,
8360 (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE));
Philip P. Moltmann295beed2020-03-18 17:06:12 -07008361 if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag,
8362 "Sending message")) {
Brad Ebingera63db5f2019-04-23 16:31:13 -07008363 throw new SecurityException("Requires SEND_SMS permission to perform this operation");
8364 }
8365 PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult);
8366 Intent intent = new Intent();
8367 intent.setClass(mApp, PickSmsSubscriptionActivity.class);
8368 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
8369 // Bring up choose default SMS subscription dialog right now
8370 intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY,
8371 PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE);
8372 mApp.startActivity(intent);
8373 }
chen xud5ca2d52019-05-28 15:20:57 -07008374
8375 @Override
8376 public String getMmsUAProfUrl(int subId) {
8377 //TODO investigate if this API should require proper permission check in R b/133791609
8378 final long identity = Binder.clearCallingIdentity();
8379 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008380 String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString(
8381 CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING);
8382 if (!TextUtils.isEmpty(carrierUAProfUrl)) {
8383 return carrierUAProfUrl;
8384 }
chen xud5ca2d52019-05-28 15:20:57 -07008385 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8386 .getString(com.android.internal.R.string.config_mms_user_agent_profile_url);
8387 } finally {
8388 Binder.restoreCallingIdentity(identity);
8389 }
8390 }
8391
8392 @Override
8393 public String getMmsUserAgent(int subId) {
8394 //TODO investigate if this API should require proper permission check in R b/133791609
8395 final long identity = Binder.clearCallingIdentity();
8396 try {
Guoqiang.Qiu171383d2020-07-13 09:38:32 +08008397 String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString(
8398 CarrierConfigManager.KEY_MMS_USER_AGENT_STRING);
8399 if (!TextUtils.isEmpty(carrierUserAgent)) {
8400 return carrierUserAgent;
8401 }
chen xud5ca2d52019-05-28 15:20:57 -07008402 return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId)
8403 .getString(com.android.internal.R.string.config_mms_user_agent);
8404 } finally {
8405 Binder.restoreCallingIdentity(identity);
8406 }
8407 }
Jack Yub07d4972019-05-28 16:12:25 -07008408
8409 @Override
8410 public boolean setDataAllowedDuringVoiceCall(int subId, boolean allow) {
8411 enforceModifyPermission();
8412
8413 // Now that all security checks passes, perform the operation as ourselves.
8414 final long identity = Binder.clearCallingIdentity();
8415 try {
8416 Phone phone = getPhone(subId);
8417 if (phone == null) return false;
8418
8419 return phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(allow);
8420 } finally {
8421 Binder.restoreCallingIdentity(identity);
8422 }
8423 }
8424
8425 @Override
8426 public boolean isDataAllowedInVoiceCall(int subId) {
8427 enforceReadPrivilegedPermission("isDataAllowedInVoiceCall");
8428
8429 // Now that all security checks passes, perform the operation as ourselves.
8430 final long identity = Binder.clearCallingIdentity();
8431 try {
8432 Phone phone = getPhone(subId);
8433 if (phone == null) return false;
8434
8435 return phone.getDataEnabledSettings().isDataAllowedInVoiceCall();
8436 } finally {
8437 Binder.restoreCallingIdentity(identity);
8438 }
8439 }
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008440
changbetty97defcf2019-12-24 15:40:37 +08008441 @Override
8442 public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
8443 enforceModifyPermission();
8444
8445 // Now that all security checks passes, perform the operation as ourselves.
8446 final long identity = Binder.clearCallingIdentity();
8447 try {
8448 Phone phone = getPhone(subId);
8449 if (phone == null) return false;
8450
8451 return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
8452 } finally {
8453 Binder.restoreCallingIdentity(identity);
8454 }
8455 }
8456
Tyler Gunn7bcdc742019-10-04 15:56:59 -07008457 /**
8458 * Updates whether conference event pacakge handling is enabled.
8459 * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false}
8460 * otherwise.
8461 */
8462 @Override
8463 public void setCepEnabled(boolean isCepEnabled) {
8464 TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled");
8465
8466 final long identity = Binder.clearCallingIdentity();
8467 try {
8468 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled);
8469 for (Phone phone : PhoneFactory.getPhones()) {
8470 Phone defaultPhone = phone.getImsPhone();
8471 if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) {
8472 ImsPhone imsPhone = (ImsPhone) defaultPhone;
8473 ImsPhoneCallTracker imsPhoneCallTracker =
8474 (ImsPhoneCallTracker) imsPhone.getCallTracker();
8475 imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled);
8476 Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone "
8477 + imsPhone.getMsisdn());
8478 }
8479 }
8480 } finally {
8481 Binder.restoreCallingIdentity(identity);
8482 }
8483 }
allenwtsu46dcc572020-01-08 18:24:03 +08008484
8485 /**
8486 * Notify that an RCS autoconfiguration XML file has been received for provisioning.
8487 *
8488 * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
8489 * @param isCompressed The XML file is compressed in gzip format and must be decompressed
8490 * before being read.
8491 */
8492 @Override
8493 public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean
8494 isCompressed) {
8495 TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(
8496 mApp, subId, "notifyRcsAutoConfigurationReceived");
8497 try {
8498 IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS);
8499 if (configBinder == null) {
8500 Rlog.e(LOG_TAG, "null result for getImsConfig");
8501 } else {
8502 configBinder.notifyRcsAutoConfigurationReceived(config, isCompressed);
8503 }
8504 } catch (RemoteException e) {
8505 Rlog.e(LOG_TAG, "fail to getImsConfig " + e.getMessage());
8506 }
8507 }
zoey chenf95ca592019-12-30 16:11:23 +08008508
8509 @Override
8510 public boolean isIccLockEnabled(int subId) {
8511 enforceReadPrivilegedPermission("isIccLockEnabled");
8512
8513 // Now that all security checks passes, perform the operation as ourselves.
8514 final long identity = Binder.clearCallingIdentity();
8515 try {
8516 Phone phone = getPhone(subId);
8517 if (phone != null && phone.getIccCard() != null) {
8518 return phone.getIccCard().getIccLockEnabled();
8519 } else {
8520 return false;
8521 }
8522 } finally {
8523 Binder.restoreCallingIdentity(identity);
8524 }
8525 }
8526
8527 /**
zoey chene02881a2019-12-30 16:11:23 +08008528 * Set the ICC pin lock enabled or disabled.
zoey chenf95ca592019-12-30 16:11:23 +08008529 *
zoey chene02881a2019-12-30 16:11:23 +08008530 * @return an integer representing the status of IccLock enabled or disabled in the following
8531 * three cases:
8532 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock
8533 * successfully.
8534 * - Positive number and zero for remaining password attempts.
8535 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008536 *
8537 */
8538 @Override
8539 public int setIccLockEnabled(int subId, boolean enabled, String password) {
8540 enforceModifyPermission();
8541
8542 Phone phone = getPhone(subId);
8543 if (phone == null) {
8544 return 0;
8545 }
8546 // Now that all security checks passes, perform the operation as ourselves.
8547 final long identity = Binder.clearCallingIdentity();
8548 try {
8549 int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED,
8550 new Pair<Boolean, String>(enabled, password), phone, null);
8551 return attemptsRemaining;
8552
8553 } catch (Exception e) {
8554 Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e);
8555 } finally {
8556 Binder.restoreCallingIdentity(identity);
8557 }
8558 return 0;
8559 }
8560
8561 /**
8562 * Change the ICC password used in ICC pin lock.
8563 *
zoey chene02881a2019-12-30 16:11:23 +08008564 * @return an integer representing the status of IccLock changed in the following three cases:
8565 * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully.
8566 * - Positive number and zero for remaining password attempts.
8567 * - Negative number for other failure cases (such like enabling/disabling PIN failed).
zoey chenf95ca592019-12-30 16:11:23 +08008568 *
8569 */
8570 @Override
8571 public int changeIccLockPassword(int subId, String oldPassword, String newPassword) {
8572 enforceModifyPermission();
8573
8574 Phone phone = getPhone(subId);
8575 if (phone == null) {
8576 return 0;
8577 }
8578 // Now that all security checks passes, perform the operation as ourselves.
8579 final long identity = Binder.clearCallingIdentity();
8580 try {
8581 int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD,
8582 new Pair<String, String>(oldPassword, newPassword), phone, null);
8583 return attemptsRemaining;
8584
8585 } catch (Exception e) {
8586 Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e);
8587 } finally {
8588 Binder.restoreCallingIdentity(identity);
8589 }
8590 return 0;
8591 }
Malcolm Chen884180b2020-04-13 11:59:40 -07008592
Peter Wangdafb9ac2020-01-15 14:13:38 -08008593 /**
8594 * Request for receiving user activity notification
8595 */
8596 @Override
8597 public void requestUserActivityNotification() {
8598 if (!mNotifyUserActivity.get()
8599 && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) {
8600 mNotifyUserActivity.set(true);
8601 }
8602 }
8603
8604 /**
8605 * Called when userActivity is signalled in the power manager.
8606 * This is safe to call from any thread, with any window manager locks held or not.
8607 */
8608 @Override
8609 public void userActivity() {
8610 // ***************************************
8611 // * Inherited from PhoneWindowManager *
8612 // ***************************************
8613 // THIS IS CALLED FROM DEEP IN THE POWER MANAGER
8614 // WITH ITS LOCKS HELD.
8615 //
8616 // This code must be VERY careful about the locks
8617 // it acquires.
8618 // In fact, the current code acquires way too many,
8619 // and probably has lurking deadlocks.
8620
8621 if (Binder.getCallingUid() != Process.SYSTEM_UID) {
8622 throw new SecurityException("Only the OS may call notifyUserActivity()");
8623 }
8624
8625 if (mNotifyUserActivity.getAndSet(false)) {
8626 mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY,
8627 USER_ACTIVITY_NOTIFICATION_DELAY);
8628 }
8629 }
Malcolm Chen4639c562020-04-13 11:59:40 -07008630
Malcolm Chen884180b2020-04-13 11:59:40 -07008631 @Override
8632 public boolean canConnectTo5GInDsdsMode() {
8633 return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode);
8634 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -07008635}